diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-08-27 11:57:51 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-08-27 12:09:21 -0400 |
| commit | 685d5fd7b32ac868a0b2d8ac8a2a1b4120f274cf (patch) | |
| tree | 890537207a09374d4e2f2753f68407360d570c1a /public/assets/javascripts/rectangles/engine/shapes/ortho.js | |
| parent | c29a5363e3e4e0833e78958fe95b52811d0b0660 (diff) | |
fork orthopolyline
Diffstat (limited to 'public/assets/javascripts/rectangles/engine/shapes/ortho.js')
| -rw-r--r-- | public/assets/javascripts/rectangles/engine/shapes/ortho.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/public/assets/javascripts/rectangles/engine/shapes/ortho.js b/public/assets/javascripts/rectangles/engine/shapes/ortho.js new file mode 100644 index 0000000..8a8f928 --- /dev/null +++ b/public/assets/javascripts/rectangles/engine/shapes/ortho.js @@ -0,0 +1,41 @@ +// An OrthoPolyline is a Polyline where all angles are 90 degrees. + +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.close = function(){ + this.points[this.points.length] = this.points[0] + this.closed = true + } + return exports +}) |
