diff options
Diffstat (limited to 'public/assets/javascripts')
| -rw-r--r-- | public/assets/javascripts/rectangles/models/surface.js | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/public/assets/javascripts/rectangles/models/surface.js b/public/assets/javascripts/rectangles/models/surface.js index eebd566..a700fd4 100644 --- a/public/assets/javascripts/rectangles/models/surface.js +++ b/public/assets/javascripts/rectangles/models/surface.js @@ -25,7 +25,7 @@ this.bounds.y.b = rect.y.a } this.bounds.x.b += rect.width() - this.bounds.y.b = Math.max(this.bounds.y.b, rect.height()) + this.bounds.y.b = Math.max(this.bounds.y.b, rect.y.b) this.faces.push(rect) } Surface.prototype.fits_scale = function(v, scale){ @@ -91,12 +91,14 @@ delta.a -= right_edge } - var bottom_edge = position.b + delta.b + bounds.y.a + var bottom_edge = position.b + delta.b - bounds.y.a if (bottom_edge < 0) { delta.b -= bottom_edge } var top_edge = position.b + dimension.b + delta.b - bounds.y.b +// console.log(position.b, 0, delta.b, bounds.y.a, bottom_edge) +// console.log(position.b, dimension.b, delta.b, bounds.y.b, top_edge) if (top_edge > 0) { delta.b -= top_edge } @@ -113,38 +115,37 @@ return old_bounds } - var left_index = this.index_for_x( position.a + dimension.a/2 + delta.a, 0 ) - var center_index = this.index_for_x( position.a + dimension.a/2 + delta.a, left_index ) - var right_index = this.index_for_x( position.a + dimension.a/2 + delta.a, center_index ) - var new_bounds = this.bounds_at_index_with_dimensions(center_index, dimension) - - this.clamp_delta(new_bounds, dimension, position, delta) - - return new_bounds +// var left_index = this.index_for_x( position.a + delta.a, 0 ) +// var center_index = this.index_for_x( position.a + dimension.a/2 + delta.a, left_index ) +// var right_index = this.index_for_x( position.a + dimension.a + delta.a, center_index ) +// var new_bounds = this.bounds_at_index_with_dimensions(center_index, dimension) +// +// this.clamp_delta(new_bounds, dimension, position, delta) +// +// 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() + var bounds = this.faces[left_side].clone() + var intersection - for (var i = left_side+1; i <= right_side; i++) { - if (this.faces[i].y.a > bounds.y.a) { - bounds.y.a = this.faces[i].y.a - } - if (this.faces[i].y.b < bounds.y.b) { - bounds.y.b = this.faces[i].y.b + for (var i = Math.min(left_side+1, right_side); i <= right_side; i++) { + intersection = bounds.y.intersection(this.faces[i].y) + if (intersection.length() < dimension.b) { + bounds = null + break } + bounds.y.assign(intersection) bounds.x.b = this.faces[i].x.b } - - if (bounds.width() > dimension.a || bounds.height() > dimension.b) { + if (! bounds || bounds.width() < dimension.a || bounds.height() < dimension.b || + bounds.y.a > position.b + delta.b || bounds.y.b < position.b + dimension.b + delta.b) { bounds = old_bounds } this.clamp_delta(bounds, dimension, position, delta) return bounds -*/ } Surface.prototype.index_for_x = function(x, min_i){ |
