diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-07-28 13:50:27 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-07-28 13:50:27 -0400 |
| commit | 80723a9898ad237818ac04ae47ff801919f34961 (patch) | |
| tree | 8aa7a9498b7bfedcd5a7ee17d8c83eb13c5aa2fd /public/assets/javascripts/rectangles/engine/shapes/shapelist.js | |
| parent | 0a6a314dc01df3d8d7f37c6b97293cedeb1aa6a0 (diff) | |
split out modules
Diffstat (limited to 'public/assets/javascripts/rectangles/engine/shapes/shapelist.js')
| -rw-r--r-- | public/assets/javascripts/rectangles/engine/shapes/shapelist.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js new file mode 100644 index 0000000..00e1a4e --- /dev/null +++ b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js @@ -0,0 +1,61 @@ +var ShapeList = Fiber.extend(function(base){ + var exports = {} + exports.init = function(){ + this.shapes = [] + } + exports.add = function(shape){ + this.shapes.push(shape) + } + exports.remove = function(shape){ + var index = this.shapes.indexOf(shape) + if (index !== -1) { + this.shapes.splice(index, 1) + } + } + exports.removeSegment = function (segment){ + var shape = segment.shape + var head = shape.getHeadAtIndex(segment.head) + var tail = shape.getTailAtIndex(segment.tail) + this.remove(shape) + shape.destroy() + if (head) { + this.add(head) + head.build() + } + if (tail) { + this.add(tail) + tail.build() + } + } + exports.findClosestPoint = function (p){ + var point + for (var i = 0; i < this.shapes.length; i++) { + point = this.shapes[i].hasPointNear(p) + if (point) return { point: point, shape: this.shapes[i] } + } + return null + } + exports.findClosestEndPoint = function (p){ + var point + for (var i = 0; i < this.shapes.length; i++) { + point = this.shapes[i].hasEndPointNear(p) + if (point) return { point: point, shape: this.shapes[i] } + } + return null + } + exports.findClosestSegment = function (p){ + var segment = null, closest_segment = null + for (var i = 0; i < this.shapes.length; i++) { + segment = this.shapes[i].hasSegmentNear(p, 10) + if (segment && (! closest_segment || segment.distance < closest_segment.distance)) { + closest_segment = segment + closest_segment.shape = this.shapes[i] + } + } + return closest_segment + } + exports.forEach = function(fn){ + this.shapes.forEach(fn) + } + return exports +})
\ No newline at end of file |
