// An OrthoPolyline is a Polyline where all angles are 90 degrees. if (! ('window' in this) ) { var Polyline = require("./polyline.js") } var OrthoPolyline = Polyline.extend(function(base){ var exports = {} exports.type = function(){ return "ortho" } exports.instantiate = function(){ return new OrthoPolyline } exports.canCloseWith = function(p){ return (this.points.length > 2 && this.points[0].distanceTo( p ) < 10/map.zoom) } exports.draw = function(ctx, fillStyle, strokeStyle){ var points = this.points if (! points.length) return if (points.length == 1) { ctx.fillStyle = "#f80" map.draw.dot_at(this.points[0].a, points[0].b, 5) } if (points.length > 1) { ctx.fillStyle = fillStyle ctx.strokeStyle = strokeStyle ctx.lineWidth = 2 / map.zoom ctx.beginPath() ctx.moveTo(points[0].a, points[0].b) points.forEach(function(point, i){ i && ctx.lineTo(point.a, point.b) }) strokeStyle && ctx.stroke() if (! map.ui.placing || this.closed) { fillStyle && ctx.fill() } } } exports.translateSegment = function(src, dest, dx, dy) { if (src[0].a == src[1].a) { dest[0].a = src[0].a + dx dest[1].a = src[1].a + dx if (src.length == 3) { dest[2].a = src[2].a + dx } } else { dest[0].b = src[0].b + dy dest[1].b = src[1].b + dy if (src.length == 3) { dest[2].b = src[2].b + dy } } } exports.close = function(){ this.points[this.points.length] = this.points[0] this.closed = true } return exports }) if (! ('window' in this) ) { module.exports = OrthoPolyline }