summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models/surface.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/models/surface.js')
-rw-r--r--public/assets/javascripts/rectangles/models/surface.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/public/assets/javascripts/rectangles/models/surface.js b/public/assets/javascripts/rectangles/models/surface.js
index 53977c8..f031665 100644
--- a/public/assets/javascripts/rectangles/models/surface.js
+++ b/public/assets/javascripts/rectangles/models/surface.js
@@ -12,6 +12,7 @@
var Surface = function (face){
this.bounds = new Rect (new vec2(0, 0), new vec2(0, 0))
+ this.vec = new Rect (new vec2(0, 0), new vec2(0, 0))
this.faces = []
if (face) {
this.add(face)
@@ -36,7 +37,7 @@
Surface.prototype.fits = function(v){
var faces = this.faces
var scratch
- if (this.bounds.x.b < v.a || this.bounds.y.b < v.b) {
+ if (this.bounds.width() < v.a || this.bounds.height() < v.b) {
return null
}
for (var i = 0; i < faces.length; i++) {
@@ -46,7 +47,7 @@
}
scratch = new Rect (0,0,0,0)
for (var i = 0; i < faces.length; i++) {
- if (faces[i].y.length() < v.b) {
+ if (faces[i].height() < v.b) {
continue
}
scratch.x.a = faces[i].x.a
@@ -108,7 +109,7 @@
this.clamp_delta( this.bounds, dimension, position, delta )
var new_delta = delta.clone()
- if (this.clamp_delta(old_bounds, dimension, position, new_delta).eq(delta)) {
+ if (old_bounds && this.clamp_delta(old_bounds, dimension, position, new_delta).eq(delta)) {
return old_bounds
}
@@ -154,6 +155,21 @@
}
return -1
}
+ Surface.prototype.face_for_x = function(x, min_i){
+ min_i = min_i || 0
+ for (var i = min_i; i < this.faces.length; i++) {
+ if (this.faces[i].x.contains(x)) {
+ return this.faces[i]
+ }
+ }
+ if (x < this.faces[0].x.a) {
+ return this.faces[0]
+ }
+ else {
+ return this.faces[this.faces.length-1]
+ }
+ return null
+ }
Surface.prototype.bounds_at_index_with_dimensions = function(index, dimensions){
var faces = this.faces