summaryrefslogtreecommitdiff
path: root/public/assets/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts')
-rw-r--r--public/assets/javascripts/rectangles/models/rect.js3
-rw-r--r--public/assets/javascripts/rectangles/models/surface.js23
2 files changed, 24 insertions, 2 deletions
diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js
index 5952f6a..f23ab9e 100644
--- a/public/assets/javascripts/rectangles/models/rect.js
+++ b/public/assets/javascripts/rectangles/models/rect.js
@@ -95,6 +95,9 @@
Rect.prototype.contains = function(x,y){
return this.x.contains(x) && this.y.contains(y)
}
+ Rect.prototype.contains_point = function(p){
+ return this.x.contains(p.x) && this.y.contains(p.y)
+ }
Rect.prototype.containsDisc = function(x,y,r){
return this.x.containsDisc(x,r) && this.y.containsDisc(y,r)
}
diff --git a/public/assets/javascripts/rectangles/models/surface.js b/public/assets/javascripts/rectangles/models/surface.js
index 0e0926f..3f43ec2 100644
--- a/public/assets/javascripts/rectangles/models/surface.js
+++ b/public/assets/javascripts/rectangles/models/surface.js
@@ -100,12 +100,28 @@
if (top_edge > 0) {
delta.b -= top_edge
}
+
+ return delta
}
Surface.prototype.translate = function (old_bounds, dimension, position, delta) {
+
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)) {
+ return old_bounds
+ }
+
+ var center_index = this.index_for_x( position.a + dimension.a/2 + delta.a, 0 )
+ var new_bounds = this.bounds_at_index_with_dimensions(center_index, dimension)
+
+ this.clamp_delta(new_bounds, dimension, position, delta)
- var left_side = this.index_for_x( position.a + delta.a, 0 )
+ return new_bounds
+
+/*
+ var left_side = this.index_for_x( position.a + delta.a, 0 )
var right_side = this.index_for_x( position.a + dimension.a + delta.a, left_side )
var bounds = this.sides[left_side].clone()
@@ -126,11 +142,12 @@
this.clamp_delta(bounds, dimension, position, delta)
return bounds
+*/
}
Surface.prototype.index_for_x = function(x, min_i){
min_i = min_i || 0
- if (x < 0 || x > width) {
+ if (x < 0 || x > this.width) {
return -1
}
for (var i = min_i; i < this.faces.length; i++) {
@@ -162,6 +179,8 @@
else if (bounds.width() < width) {
intersection = bounds.y.intersection(face.y)
if (intersection.length() < height) {
+ // not totally sure if we can clobber the bounds here since this would prevent
+ // us from looking right later
break
}
else {