Skip to content

Commit

Permalink
update rect
Browse files Browse the repository at this point in the history
  • Loading branch information
mucbuc committed Mar 31, 2017
1 parent a2aac07 commit 355b4bc
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions lib/rect.js
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);

0 comments on commit 355b4bc

Please sign in to comment.