summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-07-28 13:29:55 -0400
committerJules Laplace <jules@okfoc.us>2015-07-28 13:29:55 -0400
commit0a6a314dc01df3d8d7f37c6b97293cedeb1aa6a0 (patch)
tree28f226c360e62628c3a8c9b833fa7aa473e0bd74
parenteceee13ba34b5a8481ee0208db17fe06b216dee6 (diff)
remove segment
-rw-r--r--public/assets/test/ortho3.html58
1 files changed, 48 insertions, 10 deletions
diff --git a/public/assets/test/ortho3.html b/public/assets/test/ortho3.html
index 7e7e8ec..f56c73f 100644
--- a/public/assets/test/ortho3.html
+++ b/public/assets/test/ortho3.html
@@ -87,6 +87,12 @@ app.off = function(){ app.tube.off.apply(app.tube, arguments) }
var EraserTool = MapTool.extend(function(base){
var exports = {}
exports.down = function(e, cursor){
+ last_point.a = cursor.x.a
+ last_point.b = cursor.y.a
+ var segment = shapes.findClosestSegment(last_point)
+ if (segment) {
+ shapes.removeSegment(segment)
+ }
}
exports.move = function(e, cursor){
last_point.a = cursor.x.a
@@ -98,7 +104,6 @@ var EraserTool = MapTool.extend(function(base){
last_point.b = segment.y
cursor.x.a = cursor.x.b = last_point.a
cursor.y.a = cursor.y.b = last_point.b
- return
}
else {
document.body.style.cursor = "crosshair"
@@ -121,6 +126,21 @@ var ShapeList = Fiber.extend(function(base){
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++) {
@@ -156,29 +176,42 @@ var ShapeList = Fiber.extend(function(base){
var Polyline = Fiber.extend(function(base){
var exports = {}
-
exports.init = function(){
this.points = []
this.mx_points = []
this.closed = false
}
-
exports.add = function(p){
this.points.push( p )
this.mx_points.push( new MX.Point(p) )
}
-
exports.firstPoint = function(){
return this.points[0]
}
exports.lastPoint = function(){
return this.points[this.points.length-1]
}
-
exports.canCloseWith = function(p){
return (this.points.length > 2 && this.points[0].distanceTo( p ) < 10/map.zoom)
}
-
+ exports.getHeadAtIndex = function(index){
+ if (index == 0) { return null }
+ if (index == this.points.length-1) { return this.clone() }
+ var head = new Polyline()
+ head.points = this.points.slice(0, index+1)
+ return head
+ }
+ exports.getTailAtIndex = function(index){
+ if (index == this.points.length-1) { return null }
+ if (index == 0) { return this.clone() }
+ var tail = new Polyline()
+ tail.points = this.points.slice(index, this.points.length)
+ return tail
+ }
+ exports.clone = function(){
+ var clone = new Polyline()
+ clone.points = this.points.concat()
+ }
exports.hasPointNear = function(p){
var point
for (var i = 0; i < this.points.length; i++){
@@ -199,7 +232,6 @@ var Polyline = Fiber.extend(function(base){
}
return null
}
-
exports.hasSegmentNear = function(p, min_dist){
var p1, p2, d1, d2, sum, rat
var dx, dy, new_x, new_y, x, y, closest_distance = min_dist || Infinity
@@ -231,10 +263,10 @@ var Polyline = Fiber.extend(function(base){
x: x,
y: y,
distance: closest_distance,
- index: closest_i,
+ head: closest_i-1,
+ tail: closest_i,
}
}
-
exports.draw = function(ctx){
var points = this.points
if (! points.length) return
@@ -280,13 +312,18 @@ var Polyline = Fiber.extend(function(base){
}
exports.reset = function(){
this.mx_points.forEach(function(mx){ scene.remove(mx) })
- this.points.length = 0
this.mx_points.length = 0
+ this.points.length = 0
}
+ exports.destroy = function(){
+ this.reset()
+ this.mx && this.mx.destroy()
+ }
return exports
})
+
var scene, map, controls
map = new Map ({
@@ -377,6 +414,7 @@ OrthographicToolbar.add("eraser-mode", function(){
// OrthographicToolbar.pick("ortho-polyline-mode")
OrthographicToolbar.pick("eraser-mode")
+
document.addEventListener('DOMContentLoaded', build)
function build () {
scene = new MX.Scene().addTo("#perspective")