diff options
Diffstat (limited to 'public/assets/javascripts/rectangles/models/surface.js')
| -rw-r--r-- | public/assets/javascripts/rectangles/models/surface.js | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/public/assets/javascripts/rectangles/models/surface.js b/public/assets/javascripts/rectangles/models/surface.js index 171376f..0fb90a8 100644 --- a/public/assets/javascripts/rectangles/models/surface.js +++ b/public/assets/javascripts/rectangles/models/surface.js @@ -65,6 +65,41 @@ } return null } + + Surface.prototype.move = function(dimensions, position, dx, dy) { + var face, faces = this.faces + var p = new Rect( new vec2( position.a, position.a + dimensions.a ), + new vec2( position.b, position.b + dimensions.b ) ) + dx = clamp(dx, -p.x.a, this.width - p.x.b) + dy = clamp(dy, -p.y.a, this.height - p.y.b) + + p.x.add(dx) + p.y.add(dy) + + var i = 0 + for (; i < faces.length; i++) { + face = faces[i] + // find the element that contains the top-left corner + if (face.x.a <= p.x.a && face.x.b <= p.x.a) { + break + } + } + if (! face) return null + + if (face.y.a <= p.x.a && p.y.b <= face.y.b) { + } + + if (face.x.b >= p.y.b) { + return p + } + else { + } + + + + } + + Surface.prototype.place = function(v, index){ var face, faces = this.faces } @@ -121,9 +156,15 @@ } else { nextIndex = bounds.first - 1 - nextFace = this.faces[nextIndex] - if (nextFace.y.a <= p.b && p.b + dimension.b <= nextFace.y.b) { - // it appears the div to the left will accomodate this element + for (var i = nextIndex; i >= 0; i--) { + nextFace = this.faces[i] + if (nextFace.y.a <= p.b && p.b + dimension.b <= nextFace.y.b) { + // it appears the div to the left will accomodate this element + nextIndex = i + } + else { + + } } else { p.a = bounds.x.a |
