/********************************************************************* === Geometory Two-Dimension Class === * Dimension [ eugrace-js-geom-Dimension.js ] * updated 2001/11/24 Copyright (C)2000-2001 by UNOS, All rights reserved. mail : peace@skipup.com home : http://www.eugrace.org/ *********************************************************************/ function class__Dimension__(){ var classId = arguments.callee.toString().match(/function (\w+)/)[1].match(/__(\w+)__/)[1]; var F = window[ classId ] = function(){ this.x = null ; this.y = null ; var a = arguments ; switch( a.length ){ case 0 : default : this.x = this.y = 0 ; break ; case 1 : { // Dimension || Array || Argunment || Other var o = a[0]; if( typeof o == "object" ){ var classOf = o.constructor ; if( classOf === Dimension ){ this.x = o.x ; this.y = o.y ; }else if( classOf === Array ){ this.x = o[0]; this.y = o[1]; }else{ this.x = this.y = o ; } }else{ this.x = this.y = o ; } break ; } case 2 : { // number, number || Other this.x = a[0]; this.y = a[1]; break ; } } }; var FP = F.prototype ; if( document.layers !== void 0 ) FP.constructor = F ; F.divide = function( sp, ep, c, e ){ var d = e !== void 0 ? c+( e/Math.PI )*Math.sin( Math.PI*c ) : c ; return new F( sp.x+( ep.x-sp.x )*d, sp.y+( ep.y-sp.y )*d ); }; FP.set = function(){ var p = null ; var a = arguments ; switch( a.length ){ case 0 : default : p = new F(); break ; case 1 : p = new F( a[0] ); break ; case 2 : p = new F( a[0], a[1] ); break ; } this.x = p.x ; this.y = p.y ; }; FP.setPolar = function( t, r ){ this.x = r*Math.cos( t ); this.y = r*Math.sin( t ); }; FP.isNaN = function(){ return ( isNaN( this.x ) || isNaN( this.y ) || this.x === "" || this.y === "" ); }; FP.isZero = function(){ return this.x*this.x+this.y*this.y < EPS ; }; FP.max = function(){ return Math.max( this.x, this.y ); }; FP.min = function(){ return Math.min( this.x, this.y ); }; FP.equals = function( p ){ return this.x === p.x && this.y === p.y ; }; FP.intEquals = function( p ){ return Math.floor( this.x ) == Math.floor( p.x ) && Math.floor( this.y ) == Math.floor( p.y ); }; FP.angle = function( p ){ if( p !== void 0 ){ return Math.acos( ( this.x*p.x+this.y*p.y )/Math.sqrt( ( this.x*this.x+this.y*this.y )*( p.x*p.x+p.y*p.y ) ) ); }else{ return Math.acos( this.x/Math.sqrt( this.x*this.x+this.y*this.y ) ); } }; FP.length = FP.distance = function( p ){ if( p !== void 0 ){ return Math.sqrt( ( this.x-p.x )*( this.x-p.x )+( this.y-p.y )*( this.y-p.y ) ); }else{ return Math.sqrt( this.x*this.x+this.y*this.y ); } }; FP.length2 = FP.distance2 = function( p ){ if( p !== void 0 ){ return ( this.x-p.x )*( this.x-p.x )+( this.y-p.y )*( this.y-p.y ) ; }else{ return this.x*this.x+this.y*this.y ; } }; FP.dot = function( p ){ if( p !== void 0 ){ return this.x*p.x+this.y*p.y ; }else{ return this.x*this.x+this.y*this.y ; } }; FP.absolute = function( p ){ if( p === void 0 ) p = this ; this.x = Math.abs( p.x ); this.y = Math.abs( p.y ); }; FP.integer = function( p ){ if( p === void 0 ) p = this ; this.x = Math.floor( p.x ); this.y = Math.floor( p.y ); }; FP.reverse = function( p ){ if( p === void 0 ) p = this ; this.x = -p.x ; this.y = -p.y ; }; FP.add = function( p0, p1 ){ if( arguments.length == 1 ){ this.x += p0.x ; this.y += p0.y ; }else{ this.x = p0.x+p1.x ; this.y = p0.y+p1.y ; } }; FP.sub = function( p0, p1 ){ if( arguments.length == 1 ){ this.x -= p0.x ; this.y -= p0.y ; }else{ this.x = p0.x-p1.x ; this.y = p0.y-p1.y ; } }; FP.scale = function( p0, p1 ){ if( arguments.length == 1 ){ this.x *= p0 ; this.y *= p0 ; }else{ this.x = p1.x*p0 ; this.y = p1.y*p0 ; } }; FP.scaleAdd = function( p0, p1, p2 ){ if( arguments.length == 2 ){ this.x = this.x*p0+p1.x ; this.y = this.y*p0+p1.y ; }else{ this.x = p1.x*p0+p2.x ; this.y = p1.y*p0+p2.y ; } }; FP.scaleSub = function( p0, p1, p2 ){ if( arguments.length == 2 ){ this.x = this.x*p0-p1.x ; this.y = this.y*p0-p1.y ; }else{ this.x = p1.x*p0-p2.x ; this.y = p1.y*p0-p2.y ; } }; FP.addScale = function( p0, p1, p2 ){ if( arguments.length == 2 ){ this.x = ( this.x+p0.x )*p1 ; this.y = ( this.y+p0.y )*p1 ; }else{ this.x = ( p0.x+p1.x )*p2 ; this.y = ( p0.y+p1.y )*p2 ; } }; FP.subScale = function( p0, p1, p2 ){ if( arguments.length == 2 ){ this.x = ( this.x-p0.x )*p1 ; this.y = ( this.y-p0.y )*p1 ; }else{ this.x = ( p0.x-p1.x )*p2 ; this.y = ( p0.y-p1.y )*p2 ; } }; FP.rotate = function( p0, p1 ){ var t0 = Math.cos( p0 ); var t1 = Math.sin( p0 ); if( arguments.length == 1 ) p1 = this ; this.x = p1.x*t0-p1.y*t1 ; this.y = p1.y*t0+p1.x*t1 ; }; FP.normalize = function( p ){ if( p === void 0 ) p = this ; var d = Math.sqrt( p.x*p.x+p.y*p.y ); this.x = p.x/d ; this.y = p.y/d ; }; FP.toArray = function(){ return new Array( this.x, this.y ) ; }; FP.toString = function(){ return classId+" : ( "+this.x+", "+this.y+" )"; }; FP.write = function(){ document.write( this ); }; FP.writeln = function(){ document.writeln( this ); }; FP.alert = function(){ alert( this ); }; } class__Dimension__();