This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple elements and actions
- Loading branch information
Sergey Tatarintsev
committed
Feb 19, 2014
1 parent
e1a8b10
commit 8879181
Showing
9 changed files
with
197 additions
and
61 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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
var inherit = require('inherit'); | ||
|
||
var Rect = inherit({ | ||
|
||
//it's ok to have 4 parameters for rect class constructor - | ||
//purpose and ordering of such params are typical | ||
/*jshint maxparams: 4*/ | ||
__constructor: function(x, y, width, height) { | ||
this.x = x; | ||
this.y = y; | ||
this.width = width; | ||
this.height = height; | ||
|
||
Object.defineProperties(this, { | ||
right: { | ||
get: function() { | ||
return this.x + this.width; | ||
} | ||
}, | ||
|
||
bottom: { | ||
get: function() { | ||
return this.y + this.height; | ||
} | ||
} | ||
}); | ||
|
||
}, | ||
|
||
merge: function(other) { | ||
var x = Math.min(this.x, other.x), | ||
y = Math.min(this.y, other.y); | ||
|
||
return new Rect( | ||
x, | ||
y, | ||
Math.max(this.right, other.right) - x, | ||
Math.max(this.bottom, other.bottom) - y | ||
); | ||
} | ||
|
||
}); | ||
|
||
module.exports = Rect; |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"freeze": true, | ||
"immed": true, | ||
"indent": 4, | ||
"latedef": "nofunc", | ||
"newcap": true, | ||
"noarg": true, | ||
"nonew": true, | ||
"quotmark": "single", | ||
"undef": true, | ||
"unused": "vars", | ||
"strict": true, | ||
"trailing": true, | ||
"maxparams": 3, | ||
"node": true, | ||
"predef": { | ||
"describe": false, | ||
"it": false, | ||
"before": false, | ||
"beforeEach": false, | ||
"afterEach": false | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
--require must |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
var Rect = require('../lib/geometery/rect'); | ||
|
||
describe('rect', function() { | ||
var rect; | ||
|
||
beforeEach(function() { | ||
rect = new Rect(10, 20, 30, 40); | ||
}); | ||
|
||
it('should have correct x', function() { | ||
rect.x.must.equal(10); | ||
}); | ||
|
||
it('should have correct y', function() { | ||
rect.y.must.equal(20); | ||
}); | ||
|
||
it('should report correct width', function() { | ||
rect.width.must.equal(30); | ||
}); | ||
|
||
it('should report correct height', function() { | ||
rect.height.must.equal(40); | ||
}); | ||
|
||
it('should report correct right', function() { | ||
rect.right.must.equal(40); | ||
}); | ||
|
||
it('should report correct bottom', function() { | ||
rect.bottom.must.equal(60); | ||
}); | ||
|
||
describe('#merge', function() { | ||
it('should pick smaller x', function() { | ||
rect.merge(new Rect(1, 0, 0, 0)).x.must.equal(1); | ||
}); | ||
|
||
it('should not pick larger x', function() { | ||
rect.merge(new Rect(11, 0, 0, 0)).x.must.equal(10); | ||
}); | ||
|
||
it('should pick smaller y', function() { | ||
rect.merge(new Rect(0, 1, 0, 0)).y.must.equal(1); | ||
}); | ||
|
||
it('should not pick larger y', function() { | ||
rect.merge(new Rect(0, 25, 0, 0)).y.must.equal(20); | ||
}); | ||
|
||
it('should pick larger right', function() { | ||
rect.merge(new Rect(0, 0, 100, 40)).right.must.equal(100); | ||
}); | ||
|
||
it('should not pick smaller right', function() { | ||
rect.merge(new Rect(15, 0, 10, 40)).right.must.equal(40); | ||
}); | ||
|
||
it('should pick larger bottom', function() { | ||
rect.merge(new Rect(0, 10, 0, 55)).bottom.must.equal(65); | ||
}); | ||
|
||
it('should not pick smaller bottom', function() { | ||
rect.merge(new Rect(0, 25, 0, 30)).bottom.must.equal(60); | ||
}); | ||
}); | ||
}); |