/********************************************************************* === Geometory Two-Dimension === * Dimension [ Dimension.js ] * updated 2001/05/28 mail : peace@skipup.com home : http://www.skipup.com/~peace/ *********************************************************************/ // public class Dimension extends Object function Dimension(){ // protected object this.x ; this.y ; /****************************** CONSTRUCTOR - BEGIN ******************************/ var a = arguments ; switch( a.length ){ case 0 : default : this.x = this.y = 0 ; break ; case 1 : { // Dimension || Array || other var o = a[0]; if( typeof o == "object" ){ if( o.constructor == Dimension ){ // Dimension this.x = o.x ; this.y = o.y ; }else if( o.constructor == Array ){ // Array this.x = o[0]; this.y = o[1]; } }else{ // other this.x = this.y = o ; } break ; } case 2 : { // number , number || other this.x = a[0]; this.y = a[1]; break ; } } /****************************** CONSTRUCTOR - E N D ******************************/ } function setBasicMember__Dimension__(){ var D = Dimension ; var DP = D.prototype ; /****************************** SET_MEMBER - BEGIN ******************************/ // public void DP.set = function(){ var a = arguments ; var p ; switch( a.length ){ case 0 : default : p = new D(); break ; case 1 : p = new D( a[0] ); break ; case 2 : p = new D( a[0] , a[1] ); break ; } this.x = p.x ; this.y = p.y ; }; DP.setX = function( x ){ this.x = x ; }; DP.setY = function( y ){ this.y = y ; }; // public object DP.getX = function(){ return this.x ; }; DP.getY = function(){ return this.y ; }; // public Array DP.toArray = function(){ return new Array( this.x , this.y ); }; // public Dimension DP.toInteger = function(){ return new D( Math.floor( this.x ) , Math.floor( this.y ) ); }; // public boolean DP.equals = function( p ){ return ( this.x == p.x && this.y == p.y ); }; DP.intEquals = function( p ){ return ( this.toInteger().equals( p.toInteger() ) ); }; // public boolean DP.isNaN = function(){ return ( isNaN( this.x ) || isNaN( this.y ) || this.x == "" || this.y == "" ); }; // public double DP.distance = function( p ){ if( p ){ var q = new D( this ); q.sub( p ); return q.distance(); }else{ return Math.sqrt( Math.pow( this.x , 2 ) + Math.pow( this.y , 2 ) ); } }; // public double DP.mulin = function( p ){ return this.x*p.x+this.y*p.y ; }; // public double DP.max = function(){ return Math.max( this.x , this.y ); }; DP.min = function(){ return Math.min( this.x , this.y ); }; // public double DP.angle = function( p ){ return p ? Math.abs( this.angle()-p.angle() ) : Math.acos( this.x/this.distance() ) ; }; // public void DP.absolute = function(){ this.x = Math.abs( this.x ); this.y = Math.abs( this.y ); }; // public void DP.scale = function( v ){ this.x *= v ; this.y *= v ; }; // public void DP.add = function( p ){ var d = new D( p ); this.x += d.x ; this.y += d.y ; }; DP.sub = function( p ){ var d = new D( p ); this.x -= d.x ; this.y -= d.y ; }; // public string DP.toString = function(){ return "Dimension : ( "+this.x+" , "+this.y+" )"; }; /****************************** SET_MEMBER - E N D ******************************/ } setBasicMember__Dimension__();