-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,38 @@ | ||
/* | ||
Written by: Mark Busenitz, [email protected] | ||
*/ | ||
'use strict'; | ||
|
||
(function(){ | ||
(function(exports){ | ||
|
||
function Rect( p, d ) { | ||
|
||
if (typeof p !== 'undefined') { | ||
this.left = p.x; | ||
this.top = p.y; | ||
} | ||
else { | ||
this.left = 0; | ||
this.top = 0; | ||
} | ||
class Rect { | ||
|
||
if (typeof d !== 'undefined') { | ||
this.right = this.left + Math.abs( d.x ); | ||
this.bottom = this.top + Math.abs( d.y ); | ||
} | ||
else { | ||
this.right = 0; | ||
this.bottom = 0; | ||
} | ||
} | ||
constructor( topLeft = { x: 0, y: 0 }, size = { x: 0, y: 0 } ) { | ||
this.left = topLeft.x; | ||
this.top = topLeft.y; | ||
this.right = this.left + Math.abs( size.x ); | ||
this.bottom = this.top + Math.abs( size.y ); | ||
}; | ||
|
||
Rect.prototype = { | ||
|
||
width: function() { | ||
width() { | ||
return Math.abs( this.right - this.left ); | ||
}, | ||
height: function() { | ||
} | ||
|
||
height() { | ||
return Math.abs( this.bottom - this.top ); | ||
}, | ||
isIntersecting: function( vec ) { | ||
} | ||
|
||
isIntersecting( vec ) { | ||
return vec.x >= this.left | ||
&& vec.x <= this.right | ||
&& vec.y >= this.top | ||
&& vec.y <= this.bottom; | ||
}, | ||
clone: function() { | ||
var p = new Vec( this.left, this.top ) | ||
, d = new Vec( this.width(), this.height() ); | ||
} | ||
|
||
return new Rect( p, d ); | ||
clone() { | ||
const topLeft = new Vec( this.left, this.top ) | ||
, size = new Vec( this.width(), this.height() ); | ||
return new Rect( topLeft, size ); | ||
} | ||
}; | ||
|
||
exports.Rect = Rect; | ||
|
||
} )(); | ||
})(exports); |