class UVCoord {
  static public function getMiddle( uv0:UVCoord,
                                    uv1:UVCoord ):UVCoord {
    var ret:UVCoord = new UVCoord();
    ret.u = 0.5 * ( uv0.u + uv1.u );
    ret.v = 0.5 * ( uv0.v + uv1.u );
    return( ret );
  }

  public var u( __getu, __setu ):Float;
  public var v( __getv, __setv ):Float;

  public function new( ?x:Float = 0.0,
                       ?y:Float = 0.0 ) {
    u = x;
    v = y;
  }

  public function clear() {
    u = v = 0.0;
  }

  public function clone():UVCoord {
    return( new UVCoord( u, v ) );
  }

  public function __getu():Float { return( u ); }
  public function __getv():Float { return( v ); }
  public function __setu( f:Float ):Float {
    u = validValue( f );
    return( u );
  }
  public function __setv( f:Float ):Float {
    v = validValue( f );
    return( v );
  }

  // limit range of value to 0.0-1.0
  private function validValue( f:Float ):Float {
    var ret:Float = Math.min( 1.0, f );
    ret = Math.max( 0.0, ret );
    return( ret );
  }

  public function toString():String {
    return( "[ " + u + " " + v + " ]" );
  }
}
