From 559799f707a8c7fbd0d6296dfbce81ac6f9b376a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 18 Aug 2014 18:42:41 -0400 Subject: translation tests --- .../javascripts/rectangles/models/surface.js | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'public/assets/javascripts/rectangles/models/surface.js') 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 { -- cgit v1.2.3-70-g09d2