home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************
-
- Point Objects
-
- ********************************************************************************/
- function Point( /* x,y or p */ ){
- if( Point.isPoint(arguments[0]) ){
- this.x = arguments[0].x;
- this.y = arguments[0].y;
- }
- else{
- this.x = arguments[0];
- this.y = arguments[1];
- }
- }
- Point.isPoint = function(what){
- return ( what.constructor == Point );
- }
- Point.prototype.getArgs = function( /* [[x,y]] or [[p]] */ ){
- return new Point( arguments[0][0], arguments[0][1] );
- }
-
- Point.prototype.add = function( /* x,y or p */ ){
- var that = this.getArgs( arguments );
- return new Point( this.x + that.x, this.y + that.y );
- }
- Point.prototype.sub = function( /* x,y or p */ ){
- var that = this.getArgs( arguments );
- return new Point( this.x - that.x, this.y - that.y );
- }
- Point.prototype.mult = function( mult ){
- return new Point( mult * this.x, mult * this.y);
- }
- Point.prototype.perp = function(){
- return new Point( - this.y, this.x );
- }
- Point.prototype.distTo = function( /* x,y or p */ ){
- var that = this.getArgs( arguments );
- var dx = this.x - that.x;
- var dy = this.y - that.y;
- if( dx == 0 ) return Math.abs(dy);
- if( dy == 0 ) return Math.abs(dx);
- return Math.sqrt( dx*dx + dy*dy );
- }
- Point.prototype.size = function(){
- var p = new Point(0,0);
- return this.distTo( p );
- }
- Point.prototype.toString = function(){
- return '(' + this.x + ', ' + this.y + ')';
- }
- Point.prototype.isInRect = function( t, r, b, l ){
- return ( this.y > t && this.x < r && this.y < b && this.x > l );
- }
-
- /********************************************************************************
-
- Rect Class
-
- ********************************************************************************/
- function Rect( t, r, b, l ){
- this.t = t;
- this.r = r;
- this.b = b;
- this.l = l;
- }
-
- Rect.prototype.toString = function(){
- return "(" + this.t + ", " + this.r + ", " + this.b + ", " + this.l + ")";
- }
-