From fa81420e382366ffd0d2262f1af6143399f7a91d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 2 Oct 2014 14:32:03 -0400 Subject: transform screen coordinates into a 3d point --- public/assets/javascripts/rectangles/models/vec2.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index 0040435..a5a832e 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -37,6 +37,9 @@ vec2.prototype.midpoint = function(){ return lerp(0.5, this.a, this.b) } + vec2.prototype.lerp = function(n){ + return lerp(n, this.a, this.b) + } vec2.prototype.eq = function(v){ return this.a == v.a && this.b == v.b } @@ -63,6 +66,10 @@ vec2.prototype.zero = function(){ this.a = this.b = 0 } + vec2.prototype.round = function(){ + this.a = Math.round(this.a) + this.b = Math.round(this.b) + } vec2.prototype.setPosition = function(n){ var len = this.length() this.a = n -- cgit v1.2.3-70-g09d2 From f7c36f7a3394caa90937c5687f3ac7aeeed82e82 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 2 Oct 2014 16:18:12 -0400 Subject: add media closer to where you clicked --- .../javascripts/rectangles/engine/scenery/move.js | 1 - .../rectangles/engine/scenery/types/_object.js | 26 ++++++++++++++++++++-- .../rectangles/engine/scenery/types/image.js | 9 +++++++- .../rectangles/engine/scenery/types/video.js | 9 +++++++- .../assets/javascripts/rectangles/models/vec2.js | 10 +++++++++ .../assets/javascripts/rectangles/models/wall.js | 9 ++++++-- views/projects/list-projects.ejs | 7 +++--- 7 files changed, 61 insertions(+), 10 deletions(-) (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/rectangles/engine/scenery/move.js b/public/assets/javascripts/rectangles/engine/scenery/move.js index 981eb68..7d148cf 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/move.js +++ b/public/assets/javascripts/rectangles/engine/scenery/move.js @@ -88,7 +88,6 @@ Scenery.move = function(base){ } function up (e, cursor){ - console.log(dragging, oldState) if (! dragging || ! oldState) return dragging = false diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js index 5eed53e..4e5e2c5 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/_object.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/_object.js @@ -33,11 +33,33 @@ Scenery.types.base = Fiber.extend(function(base){ var center = this.bounds.center() center.a -= this.dimensions.a / 2 center.b -= this.dimensions.b / 2 - var mx_position = this.wall.positionToMx( center, this.dimensions ) - this.mx.move(mx_position) this.position.assign(center) }, + translateTo: function (position){ + var flipX = this.wall.side & (FRONT | RIGHT) + var delta = position.clone().subVec(this.position) + delta.a -= this.dimensions.a/2 + delta.b -= this.dimensions.b/2 + + if (flipX) { delta.a *= -1 } + + var new_bounds = this.wall.surface.translate( this.bounds, this.dimensions, this.position, delta ) + + this.position.b += delta.b + + switch (this.wall.side) { + case FRONT: + case BACK: + this.position.a += delta.a * cos(wall_rotation[this.wall.side]) + break + case LEFT: + case RIGHT: + this.position.a += delta.a * sin(wall_rotation[this.wall.side]) + break + } + }, + bind: function(){ this.move.bind() $(this.mx.el).bind({ diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js index d2fa3ab..aa43341 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js @@ -22,7 +22,14 @@ Scenery.types.image = Scenery.types.base.extend(function(base){ } else { this.set_wall(opt) - this.bounds && this.recenter() + if (this.bounds) { + this.recenter() + if (opt.position) { + this.translateTo(opt.position) + } + var mx_position = this.wall.positionToMx( this.position, this.dimensions ) + this.mx.move(mx_position) + } } }, diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/video.js b/public/assets/javascripts/rectangles/engine/scenery/types/video.js index 76f32ac..2ef6ec3 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/video.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/video.js @@ -21,7 +21,14 @@ Scenery.types.video = Scenery.types.base.extend(function(base){ } else { this.set_wall(opt) - this.bounds && this.recenter() + if (this.bounds) { + this.recenter() + if (opt.position) { + this.translateTo(opt.position) + } + var mx_position = this.wall.positionToMx( this.position, this.dimensions ) + this.mx.move(mx_position) + } } }, diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index a5a832e..49613c3 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -63,6 +63,16 @@ this.b /= n return this } + vec2.prototype.addVec = function(v){ + this.a += v.a + this.b += v.b + return this + } + vec2.prototype.subVec = function(v){ + this.a -= v.a + this.b -= v.b + return this + } vec2.prototype.zero = function(){ this.a = this.b = 0 } diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js index ce958db..fdc8d8c 100644 --- a/public/assets/javascripts/rectangles/models/wall.js +++ b/public/assets/javascripts/rectangles/models/wall.js @@ -53,7 +53,6 @@ /* mousemove: function(e){ var offset = offsetFromPoint(e, mx.el) - var shouldFlip = base.side & (RIGHT | FRONT) if (offset) { var pos = base.mxOffsetToPosition( offset, index ) @@ -72,9 +71,15 @@ if (Scenery.nextText) { } else if (Scenery.nextMedia) { + var offset = offsetFromPoint(e, mx.el) + if (! offset) { return } + + var pos = base.mxOffsetToPosition( offset, index ) + var scenery = Scenery.addNextToWall({ wall: base, - index: index + index: index, + position: pos, }) // scenery was not placed diff --git a/views/projects/list-projects.ejs b/views/projects/list-projects.ejs index 5694648..f3332b2 100644 --- a/views/projects/list-projects.ejs +++ b/views/projects/list-projects.ejs @@ -14,11 +14,12 @@ [[ }) ]] - [[ if (String(user._id) == String(project.user_id)) { ]] -
edit
- [[ } ]]
+ [[ if (String(user._id) == String(project.user_id)) { ]] + + [[ } else { ]] + [[ } ]] [[- project.name ]]
[[- project.date ]]
-- cgit v1.2.3-70-g09d2 From 2c2c70965efb50b500799ae7966a42e86bbac480 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Fri, 31 Oct 2014 10:18:39 -0400 Subject: fix floating point error :-P --- public/assets/javascripts/rectangles/models/rect.js | 6 ++++++ public/assets/javascripts/rectangles/models/vec2.js | 5 ++++- public/assets/test/intersect.html | 15 +++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js index 00f2c55..c667cf5 100644 --- a/public/assets/javascripts/rectangles/models/rect.js +++ b/public/assets/javascripts/rectangles/models/rect.js @@ -169,6 +169,12 @@ var s = "[" + this.x.toString() + " " + this.y.toString() + "] " + sides return s } + Rect.prototype.exactString = function(){ + var sides = sidesToString(this.sides) + var s = "[" + this.x.exactString() + " " + this.y.exactString() + "] " + sides + return s + } + Rect.prototype.serialize = function(){ return { x: this.x.serialize(), y: this.y.serialize() } } diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index 49613c3..f28df54 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -200,7 +200,10 @@ } vec2.prototype.toString = function(){ - return "[" + ~~this.a + " " + ~~this.b + "]" + return "[" + round(this.a) + " " + round(this.b) + "]" + } + vec2.prototype.exactString = function(){ + return "[" + this.a + " " + this.b + "]" } vec2.prototype.serialize = function(){ return [ ~~this.a, ~~this.b ] diff --git a/public/assets/test/intersect.html b/public/assets/test/intersect.html index 5e16f2e..4e5b0bb 100644 --- a/public/assets/test/intersect.html +++ b/public/assets/test/intersect.html @@ -1,4 +1,5 @@ +
@@ -73,16 +74,21 @@ function draw () { var collinear = is_collinear( intersect, vec_b ) var long_enough_to_intersect = 0 <= t && t <= 1 + var msg if (long_enough_to_intersect && collinear) { ctx.fillStyle = "#f00" + msg = "through" } else if (collinear) { ctx.fillStyle = "#0f0" + msg = "to" } else { ctx.fillStyle = "#000" + msg = "off" } + hud.innerHTML = [intersect.exactString(), vec_b.exactString(), msg].join("
") drawPoint(intersect) } @@ -105,19 +111,20 @@ function perp (va, vb) { } function is_collinear (p, vec) { var on_x, on_y + var pa = round(p.a), pb = round(p.b) if (vec.x.a < vec.y.a) { - on_x = vec.x.a <= p.a && p.a <= vec.y.a + on_x = vec.x.a <= pa && pa <= vec.y.a } else { - on_x = vec.x.a >= p.a && p.a >= vec.y.a + on_x = vec.x.a >= pa && pa >= vec.y.a } if (vec.x.b < vec.y.b) { - on_y = vec.x.b <= p.b && p.b <= vec.y.b + on_y = vec.x.b <= pb && pb <= vec.y.b } else { - on_y = vec.x.b >= p.b && p.b >= vec.y.b + on_y = vec.x.b >= pb && pb >= vec.y.b } return !! (on_x && on_y) -- cgit v1.2.3-70-g09d2 From 00778a168b7314039e95e856f6d41e05d0dbc4e4 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 4 Nov 2014 14:44:02 -0500 Subject: fix resize undo --- public/assets/javascripts/app.js | 5 ----- .../assets/javascripts/rectangles/engine/scenery/types/image.js | 1 + .../assets/javascripts/rectangles/engine/scenery/types/text.js | 2 ++ .../assets/javascripts/rectangles/engine/scenery/types/video.js | 1 + public/assets/javascripts/rectangles/engine/scenery/undo.js | 9 ++++++--- public/assets/javascripts/rectangles/models/vec2.js | 6 +++++- public/assets/javascripts/vendor/polyfill.js | 5 +++++ 7 files changed, 20 insertions(+), 9 deletions(-) (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/app.js b/public/assets/javascripts/app.js index 5e339ea..0488f11 100644 --- a/public/assets/javascripts/app.js +++ b/public/assets/javascripts/app.js @@ -1,9 +1,4 @@ -var is_iphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)); -var is_ipad = (navigator.userAgent.match(/iPad/i)); -var is_android = (navigator.userAgent.match(/Android/i)) -var is_mobile = is_iphone || is_ipad || is_android; - if (is_mobile) { // window.location.href = "mobile.html" $("html").addClass("mobile"); diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/image.js b/public/assets/javascripts/rectangles/engine/scenery/types/image.js index 10fc917..848f8d4 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/image.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/image.js @@ -55,6 +55,7 @@ Scenery.types.image = Scenery.types.base.extend(function(base){ this.mx.move(data.position) this.mx.ops.width = data.dimensions.a this.mx.ops.height = data.dimensions.b + this.dimensions.deserialize(data.dimensions) }, } diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/text.js b/public/assets/javascripts/rectangles/engine/scenery/types/text.js index a10a332..dd1385f 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/text.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/text.js @@ -68,7 +68,9 @@ Scenery.types.text = Scenery.types.base.extend(function(base){ this.mx.move(data.position) this.mx.ops.width = data.dimensions.a this.mx.ops.height = data.dimensions.b + this.dimensions.deserialize(data.dimensions) }, + } return exports diff --git a/public/assets/javascripts/rectangles/engine/scenery/types/video.js b/public/assets/javascripts/rectangles/engine/scenery/types/video.js index a669a90..d83cc63 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/types/video.js +++ b/public/assets/javascripts/rectangles/engine/scenery/types/video.js @@ -117,6 +117,7 @@ Scenery.types.video = Scenery.types.base.extend(function(base){ this.mx.move(data.position) this.mx.ops.width = data.dimensions.a this.mx.ops.height = data.dimensions.b + this.dimensions.deserialize(data.dimensions) }, } diff --git a/public/assets/javascripts/rectangles/engine/scenery/undo.js b/public/assets/javascripts/rectangles/engine/scenery/undo.js index 998f7c6..6ad9e0d 100644 --- a/public/assets/javascripts/rectangles/engine/scenery/undo.js +++ b/public/assets/javascripts/rectangles/engine/scenery/undo.js @@ -21,9 +21,10 @@ type: "update-scenery", undo: function(state){ var scenery = Scenery.find(state.id) + var wall = Walls.find( state.wall_id ) scenery.deserialize(state) - scenery.set_wall(Walls.find( state.wall_id )) + scenery.set_wall({ wall: wall }) if (editor.permissions.resize) { Scenery.resize.show(scenery) @@ -34,13 +35,15 @@ }, redo: function(state){ var scenery = Scenery.find(state.id) + var wall = Walls.find( state.wall_id ) + scenery.deserialize(state) - scenery.set_wall(Walls.find( state.wall_id )) + scenery.set_wall({ wall: wall }) if (editor.permissions.resize) { Scenery.resize.show(scenery) - Scenery.resize.rotate_dots() Scenery.resize.move_dots() + Scenery.resize.rotate_dots() } // TODO: watch individual scenery object here diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index f28df54..14d0e6b 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -206,7 +206,11 @@ return "[" + this.a + " " + this.b + "]" } vec2.prototype.serialize = function(){ - return [ ~~this.a, ~~this.b ] + return [ round(this.a), round(this.b) ] + } + vec2.prototype.deserialize = function(data){ + this.a = data[0] + this.b = data[1] } vec2.prototype.quantize = function(n){ n = n || 10 diff --git a/public/assets/javascripts/vendor/polyfill.js b/public/assets/javascripts/vendor/polyfill.js index f97e438..8e4b9dc 100644 --- a/public/assets/javascripts/vendor/polyfill.js +++ b/public/assets/javascripts/vendor/polyfill.js @@ -52,6 +52,11 @@ function has3d(){ return browser; })( navigator.userAgent ); +// Naive useragent detection pattern +var is_iphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)); +var is_ipad = (navigator.userAgent.match(/iPad/i)); +var is_android = (navigator.userAgent.match(/Android/i)) +var is_mobile = is_iphone || is_ipad || is_android; // rAF shim (function() { -- cgit v1.2.3-70-g09d2 From 220320494c60c154e84c579f86d2dfdd8f41be2f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 3 Feb 2015 17:41:36 -0500 Subject: orthographic polyline --- .../javascripts/rectangles/engine/map/_map.js | 8 + .../javascripts/rectangles/engine/map/draw.js | 19 +- .../assets/javascripts/rectangles/models/vec2.js | 5 + public/assets/test/ortho.html | 224 +++++++++++++++++++++ 4 files changed, 251 insertions(+), 5 deletions(-) create mode 100644 public/assets/test/ortho.html (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/rectangles/engine/map/_map.js b/public/assets/javascripts/rectangles/engine/map/_map.js index 202803a..d582982 100644 --- a/public/assets/javascripts/rectangles/engine/map/_map.js +++ b/public/assets/javascripts/rectangles/engine/map/_map.js @@ -48,6 +48,13 @@ var Map = function(opt){ base.el.appendChild(canvas) switch (opt.type) { + case "ortho": + base.draw = new Map.Draw (base, { ortho: true }) + base.ui = new Map.UI.Ortho (base) + base.sides = base.sides_for_camera + $(window).resize(base.resize) + break + case "editor": base.draw = new Map.Draw (base) base.ui = new Map.UI.Editor (base) @@ -65,6 +72,7 @@ var Map = function(opt){ base.resize = function(){ canvas.width = base.dimensions.a = window.innerWidth canvas.height = base.dimensions.b = window.innerHeight + // resize here - esp if 2d-hires } base.toggle = function(state){ diff --git a/public/assets/javascripts/rectangles/engine/map/draw.js b/public/assets/javascripts/rectangles/engine/map/draw.js index 5a9b592..b525696 100644 --- a/public/assets/javascripts/rectangles/engine/map/draw.js +++ b/public/assets/javascripts/rectangles/engine/map/draw.js @@ -5,14 +5,16 @@ Map.Draw = function(map, opt){ var draw = this - var ctx = map.canvas.getContext("2d") + var ctx = draw.ctx = map.canvas.getContext("2d") draw.animate = function(){ ctx.save() draw.clear() draw.fill("rgba(255,255,255,0.98)") - if (opt.minimap) { + if (opt.ortho) { + } + else if (opt.minimap) { ctx.translate( map.dimensions.a * 1/2, map.dimensions.b * 1/2) ctx.scale( map.zoom, map.zoom ) ctx.translate( opt.center.x, - opt.center.z ) @@ -22,7 +24,6 @@ Map.Draw = function(map, opt){ draw.regions(Rooms.regions, [ "#fff" ], "#000") draw.camera(scene.camera) } - else { ctx.translate( map.dimensions.a * 1/2, map.dimensions.b * 1/2) ctx.scale( map.zoom, map.zoom ) @@ -31,12 +32,19 @@ Map.Draw = function(map, opt){ draw.regions(Rooms.regions, [ "#f8f8f8" ], "#000") draw.mouse(map.ui.mouse.cursor) + draw.mouse_dimensions(map.ui.mouse.cursor) draw.coords() scene && draw.camera(scene.camera) } ctx.restore() } + draw.translate = function(){ + ctx.translate( map.dimensions.a * 1/2, map.dimensions.b * 1/2) + ctx.scale( map.zoom, map.zoom ) + ctx.translate( map.center.a, map.center.b ) + ctx.scale( -1, 1 ) + } // changes the ctx temporarily draw.render = function(){ @@ -87,7 +95,7 @@ Map.Draw = function(map, opt){ ctx.putImageData(pixelData, 0, 0) // reset the ctx - ctx = map.canvas.getContext("2d") + ctx = draw.ctx return canvas } @@ -123,7 +131,8 @@ Map.Draw = function(map, opt){ ctx.beginPath(); ctx.arc(mouse.x.b, mouse.y.b, radius, 0, 2*Math.PI, false); ctx.fill(); - + } + draw.mouse_dimensions = function(mouse){ if (mouse.width() != 0 && mouse.height() != 0) { if (map.ui.dragging) { stroke_rect(mouse) diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index 14d0e6b..290e45e 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -80,6 +80,11 @@ this.a = Math.round(this.a) this.b = Math.round(this.b) } + vec2.prototype.distanceTo = function(v){ + var va = (this.a - v.a) + var vb = (this.b - v.b) + return Math.sqrt( va*va + vb*vb ) + } vec2.prototype.setPosition = function(n){ var len = this.length() this.a = n diff --git a/public/assets/test/ortho.html b/public/assets/test/ortho.html new file mode 100644 index 0000000..8626453 --- /dev/null +++ b/public/assets/test/ortho.html @@ -0,0 +1,224 @@ + + +
+
+ +
+ + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 272474767b6ed1f419843c7a205c16f934eeb84f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 20 Aug 2015 23:33:36 -0400 Subject: turn segments into rects --- .../rectangles/engine/shapes/regionlist.js | 54 ++++++++-------------- .../assets/javascripts/rectangles/models/rect.js | 6 +++ .../assets/javascripts/rectangles/models/vec2.js | 3 ++ .../javascripts/ui/blueprint/BlueprintEditor.js | 2 +- .../javascripts/ui/blueprint/BlueprintSettings.js | 16 ++++--- public/assets/javascripts/ui/lib/ToggleableView.js | 19 ++++++++ views/controls/blueprint/info.ejs | 4 +- views/controls/builder/info.ejs | 4 +- views/controls/editor/media-editor.ejs | 4 +- views/partials/scripts.ejs | 1 + 10 files changed, 65 insertions(+), 48 deletions(-) create mode 100644 public/assets/javascripts/ui/lib/ToggleableView.js (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js index 94b902a..42519cf 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js +++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js @@ -12,7 +12,7 @@ var RegionList = (function(){ var rooms = [] var open_segments = [] - var segment, open_segment, vertical, other_side + var segment, open_segment, y_segments for (var i = 0; i < segments.length; i++) { segment = segments[i] @@ -21,12 +21,20 @@ var RegionList = (function(){ } for (var j = 0; j < open_segments.length; j++) { open_segment = open_segments[j] - if (overlaps(segment, open_segment)) { + if (segment.y.overlaps(open_segment.y)) { // if we have overlap, it means we have made a full room - other_side = clone_segment(open_segment) - other_side[0].a = segment[0].a - other_side[1].a = segment[1].a - rooms.push([open_segment, other_side]) + + y_segments = open_segment.y.split(segment.y) + + if (y_segments.length == 1) { + open_segment.x.b = segment.x.b + rooms.push(open_segment) + } + +// other_side = clone_segment(open_segment) +// other_side[0].a = segment[0].a +// other_side[1].a = segment[1].a +// rooms.push([open_segment, other_side]) open_segments.splice(j, 1) j-- } @@ -43,8 +51,8 @@ var RegionList = (function(){ // get a list of all segments from these polylines var segments = shapes.getAllSegments() - // re-orientate them so they're either facing up or right - segments.forEach(function(segment){ + // re-orient them so they're either facing up or right and make them into rects + segments = segments.map(function(segment){ // vertical if (segment[0].a == segment[1].a) { if (segment[0].b > segment[1].b) { @@ -57,36 +65,12 @@ var RegionList = (function(){ segment.push(segment.shift()) } } + return new Rect( segment[0].a, segment[0].b, segment[1].a, segment[1].b ) }) - // sort them from top to bottom, left to right - segments = segments.sort(function(a,b){ - if (a[0].a < b[0].a) { - return -1 - } - else if (a[0].a == b[0].a) { - if (a[0].b < b[0].b) { - return -1 - } - else if (a[0].b == b[0].b) { - return 0 - } - else { - return 1 - } - } - else { - return 1 - } - }) - - return segments + return sort.rects_by_position(segments) } - - function isVertical (segment) { return segment[0].a == segment[1].a } - function isHorizontal (segment) { return segment[0].b == segment[1].b } - function overlaps (a,b) { return (a[0].b > b[0].b || a[1].b < b[1].b) } - function clone_segment(a){ return [a[0].clone(), a[1].clone()] } + return RegionList })() \ No newline at end of file diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js index 92c8c9e..a4756ed 100644 --- a/public/assets/javascripts/rectangles/models/rect.js +++ b/public/assets/javascripts/rectangles/models/rect.js @@ -62,6 +62,12 @@ Rect.prototype.maxDimension = function(){ return abs(this.width) > abs(this.height) ? this.width : this.height } + Rect.prototype.isVertical = function(){ + return this.x.isPoint() + } + Rect.prototype.isHorizontal = function(){ + return this.y.isPoint() + } Rect.prototype.mul = function(n){ this.x.mul(n) diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index 290e45e..90a56c6 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -43,6 +43,9 @@ vec2.prototype.eq = function(v){ return this.a == v.a && this.b == v.b } + vec2.prototype.isPoint = function(){ + return this.a == this.b + } vec2.prototype.add = function(n){ this.a += n this.b += n diff --git a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js index 8fe66ca..18ecf5f 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js @@ -93,7 +93,7 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({ map.draw.ctx.save() map.draw.translate() - // this.floorplan.draw(map.draw.ctx, true) + this.floorplan.draw(map.draw.ctx, true) map.draw.coords() diff --git a/public/assets/javascripts/ui/blueprint/BlueprintSettings.js b/public/assets/javascripts/ui/blueprint/BlueprintSettings.js index acd8dcc..252e3f1 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintSettings.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintSettings.js @@ -1,5 +1,5 @@ -var BlueprintSettings = FormView.extend({ +var BlueprintSettings = FormView.extend(ToggleableView.prototype).extend({ el: "#blueprintSettings", action: "/api/blueprint/edit", @@ -25,7 +25,13 @@ var BlueprintSettings = FormView.extend({ load: function(data){ this.$id.val(data._id) - this.$name.val(data.name) + if (data.name) { + this.$name.val(data.name) + this.hide() + } + else { + this.$name.val("") + } if (data.shapes) { shapes.destroy() shapes.deserialize( data.shapes ) @@ -51,10 +57,6 @@ var BlueprintSettings = FormView.extend({ }.bind(this)) }, - toggle: function(state){ - this.$el.toggleClass("active", state) - }, - enterSubmit: function (e) { e.stopPropagation() var base = this @@ -105,6 +107,8 @@ var BlueprintSettings = FormView.extend({ this.$name.val(data.name) this.action = this.updateAction + this.hide() + Minotaur.unwatch(this) Minotaur.hide() diff --git a/public/assets/javascripts/ui/lib/ToggleableView.js b/public/assets/javascripts/ui/lib/ToggleableView.js new file mode 100644 index 0000000..371629f --- /dev/null +++ b/public/assets/javascripts/ui/lib/ToggleableView.js @@ -0,0 +1,19 @@ +var ToggleableView = View.extend({ + + toggle: function(state){ + this.$el.toggleClass("active", state) + }, + + show: function(){ + this.toggle(true) + }, + + hide: function(){ + this.toggle(false) + }, + + visible: function(){ + return this.$el.hasClass("active") + } + +}) \ No newline at end of file diff --git a/views/controls/blueprint/info.ejs b/views/controls/blueprint/info.ejs index 9f7d708..4e2316f 100644 --- a/views/controls/blueprint/info.ejs +++ b/views/controls/blueprint/info.ejs @@ -15,8 +15,8 @@
diff --git a/views/controls/builder/info.ejs b/views/controls/builder/info.ejs index 8a0e0d5..11e995a 100644 --- a/views/controls/builder/info.ejs +++ b/views/controls/builder/info.ejs @@ -34,8 +34,8 @@ diff --git a/views/controls/editor/media-editor.ejs b/views/controls/editor/media-editor.ejs index 2a3d4f3..225bdc8 100644 --- a/views/controls/editor/media-editor.ejs +++ b/views/controls/editor/media-editor.ejs @@ -49,8 +49,8 @@
--> diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs index bc8dacb..865c0f1 100644 --- a/views/partials/scripts.ejs +++ b/views/partials/scripts.ejs @@ -108,6 +108,7 @@ + -- cgit v1.2.3-70-g09d2 From 0c1864a114a2efe1a3bb8b2b4951e8655712757a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 21 Aug 2015 15:19:05 -0400 Subject: dedupe new rooms --- .../javascripts/rectangles/engine/map/draw.js | 4 +- .../rectangles/engine/shapes/regionlist.js | 62 +++++++++++++++++----- .../assets/javascripts/rectangles/models/vec2.js | 3 ++ .../javascripts/ui/blueprint/BlueprintEditor.js | 8 +-- 4 files changed, 58 insertions(+), 19 deletions(-) (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/rectangles/engine/map/draw.js b/public/assets/javascripts/rectangles/engine/map/draw.js index 5824cc8..f47f10c 100644 --- a/public/assets/javascripts/rectangles/engine/map/draw.js +++ b/public/assets/javascripts/rectangles/engine/map/draw.js @@ -189,7 +189,7 @@ Map.Draw = function(map, opt){ var sides = map.sides() var quant = sides.clone().quantize(MAP_GRID_SIZE) for (var x = quant.x.a - MAP_GRID_SIZE; x <= quant.x.b; x += MAP_GRID_SIZE) { - if (Math.round(x) % 10 == 0) { + if (Math.round(x) % 360 == 0) { ctx.strokeStyle = "rgba(0,0,0,0.3)" ctx.lineWidth = 1/map.zoom } @@ -200,7 +200,7 @@ Map.Draw = function(map, opt){ line(x, sides.y.a, x, sides.y.b) } for (var y = quant.y.a - MAP_GRID_SIZE; y <= quant.y.b; y += MAP_GRID_SIZE) { - if (Math.round(y) % 10 == 0) { + if (Math.round(y) % 360 == 0) { ctx.strokeStyle = "rgba(0,0,0,0.3)" ctx.lineWidth = 1/map.zoom } diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js index f86968f..93a0df7 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js +++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js @@ -6,52 +6,86 @@ var RegionList = (function(){ RegionList.build = function(){ var segments = RegionList.getSortedSegments() -// var xx = t % (segments[0].x.a - segments[segments.length-1].x.b) - - // loop over them from left to right -// console.log(segments.map(function(s){ return s.toString() }).join("\n")) - var rooms = [] + var seen_rooms = {} var open_segments = [] var closed_segments = [] - var segment, open_segment, x_segment, y_segments, overlapped + var segment, open_segment, x_segment, y_segments, overlapped, seen_segments for (var i = 0; i < segments.length; i++) { segment = segments[i] if (! segment.isVertical()) { continue } - console.log(segment+"") overlapped = false for (var j = 0; j < open_segments.length; j++) { open_segment = open_segments[j] if (segment.y.overlaps(open_segment.y)) { - // if we have overlap, it means we have made a full room - console.log(segment.y+"", "overlaps", open_segment.y+"") overlapped = true closed_segments.push(open_segments[j]) open_segments.splice(j--, 1) x_segment = new vec2( open_segment.x.a, segment.x.b ) y_segments = open_segment.y.split(segment.y, TOP, BOTTOM) - console.log(y_segments.map(function(s){ return s+"" }).join("\n")) + + seen_segments = {} + y_segments.forEach(function(seg){ - rooms.push(new Rect( x_segment, seg[0] )) + seen_segments[ seg[0]+"" ] = true + var room = new Rect( x_segment, seg[0] ) + + if (seen_rooms[ room+"" ]) return; + + seen_rooms[ room+"" ] = true + rooms.push(room) + var new_seg = new Rect( segment.x, seg[0] ) + open_segments.unshift(new_seg) + j++ + }) + y_segments = segment.y.split(open_segment.y, TOP, BOTTOM) + y_segments.forEach(function(seg){ + if (seen_segments[ seg[0]+"" ]) return; var new_seg = new Rect( segment.x, seg[0] ) open_segments.unshift(new_seg) j++ }) } } - if (! overlapped) { + if (overlapped) { + // sort open segments? + open_segments = open_segments.sort(function(a,b){ + if (a.y.a < b.y.a) { return -1 } + if (a.y.a == b.y.a) { return 0 } + if (a.y.a > b.y.a) { return 1 } + }) + + if (open_segments.length < 2) { continue } + + for (var k = 1; k < open_segments.length; k++) { + if (open_segments[k-1].y.containsVec(open_segments[k].y)) { + open_segments.splice(k--, 1) + } + else if (open_segments[k-1].y.overlaps(open_segments[k].y)) { + open_segments[k].y = open_segments[k].y.clone() + console.log(open_segments[k-1].y+"", open_segments[k].y+"") + open_segments[k].y.a = open_segments[k-1].y.b + } + } + } + else { open_segments.push(segment) } } -// console.log(rooms.map(function(s){ return s.toString() }).join("\n")) - console.log({ rooms: rooms, open_segments: open_segments, segments: segments, closed_segments: closed_segments }) + for (var i = 0; i < segments.length; i++) { + segment = segments[i] + if (! segment.isHorizontal()) { + continue + } + } + return { rooms: rooms, open_segments: open_segments, segments: segments, closed_segments: closed_segments } } diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index 90a56c6..d37bc12 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -111,6 +111,9 @@ vec2.prototype.containsDisc = function(n,r){ return this.a <= n-r && n+r <= this.b } + vec2.prototype.containsVec = function(v){ + return this.a <= v.a && v.b <= this.b + } vec2.prototype.clamp = function(n){ return clamp(n, this.a, this.b) } diff --git a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js index cf9dea6..0b27d0c 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js @@ -108,7 +108,7 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({ } shapes.forEach(function(shape){ - shape.draw(map.draw.ctx) +// shape.draw(map.draw.ctx) }) map.draw.ctx.strokeStyle = "#f00"; @@ -117,14 +117,16 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({ map.draw.camera(scene.camera) this.rooms.open_segments.forEach(function(seg,i){ - map.draw.ctx.fillStyle = "#00f" + map.draw.ctx.fillStyle = "rgba(0,0,255,0.2)" map.draw.ctx.fillRect( seg.x.a, seg.y.a, seg.width()+10, seg.height() ) }) this.rooms.closed_segments.forEach(function(seg,i){ - map.draw.ctx.fillStyle = "#0ff" + map.draw.ctx.fillStyle = "rgba(0,255,0,0.2)" map.draw.ctx.fillRect( seg.x.a, seg.y.a, seg.width()+10, seg.height() ) }) + + var colors = ["rgba(0,0,0,0.1)"] this.rooms.rooms.forEach(function(room,i){ map.draw.ctx.fillStyle = colors[i % colors.length] -- cgit v1.2.3-70-g09d2 From 73fdf8d46f10793d210f4369adb8c31afa536d20 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 21 Aug 2015 16:59:48 -0400 Subject: thinking --- .../rectangles/engine/shapes/regionlist.js | 33 +++++++++++++--------- .../assets/javascripts/rectangles/models/vec2.js | 3 ++ 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js index fb2c8e5..b2672ad 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js +++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js @@ -106,22 +106,27 @@ var RegionList = (function(){ } } /* - else if ((segment.y.a == room.y.a || segment.y.a == room.y.b) && room.x.containsVec(segment.x)) { - splits = room.x.split(segment.x, LEFT, RIGHT) - for (var k = 0; k < splits.length; k++) { - splitter = splits[k] - var new_room = new Rect( splitter[0], room.y ) - new_room.sides |= splitter[1] - if (segment.x.containsVec(splitter[0])) { - if (segment.y.a == room.y.a) { - room.sides |= FRONT - } - if (segment.y.a == room.y.b) { - room.sides |= BACK + else if (segment.y.a == room.y.a || segment.y.a == room.y.b) { + if (room.x.overlaps(segment.x)) { + splits = room.x.split(segment.x, LEFT, RIGHT) + rooms.splice(r--, 1) + console.log(splits) + for (var k = 0; k < splits.length; k++) { + splitter = splits[k] + var new_room = new Rect( splitter[0], room.y ) + new_room.sides = 0 + new_room.sides |= splitter[1] + if (segment.x.containsVec( splitter[0] )) { + if (segment.y.a == new_room.y.a) { + new_room.sides |= FRONT + } + if (segment.y.a == new_room.y.b) { + new_room.sides |= BACK + } } + rooms.unshift(new_room) + r++ } - rooms.unshift(new_room) - r++ } } */ diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index d37bc12..226e56f 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -114,6 +114,9 @@ vec2.prototype.containsVec = function(v){ return this.a <= v.a && v.b <= this.b } + vec2.prototype.containsCenterVec = function(v){ + return this.a < v.a && v.b < this.b + } vec2.prototype.clamp = function(n){ return clamp(n, this.a, this.b) } -- cgit v1.2.3-70-g09d2 From 48fc9b27a77126da649959c8f74ad8faffcd6e2c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 25 Aug 2015 11:15:50 -0400 Subject: comment the regionlist algorithm --- .../javascripts/rectangles/engine/map/_map.js | 6 +- .../javascripts/rectangles/engine/rooms/builder.js | 1 + .../rectangles/engine/shapes/polyline.js | 4 ++ .../rectangles/engine/shapes/regionlist.js | 83 ++++++++++++++++------ .../rectangles/engine/shapes/shapelist.js | 2 + .../assets/javascripts/rectangles/models/vec2.js | 4 +- .../assets/javascripts/rectangles/models/wall.js | 5 ++ .../javascripts/ui/blueprint/BlueprintEditor.js | 5 +- 8 files changed, 79 insertions(+), 31 deletions(-) (limited to 'public/assets/javascripts/rectangles/models/vec2.js') diff --git a/public/assets/javascripts/rectangles/engine/map/_map.js b/public/assets/javascripts/rectangles/engine/map/_map.js index 2aee962..e27346d 100644 --- a/public/assets/javascripts/rectangles/engine/map/_map.js +++ b/public/assets/javascripts/rectangles/engine/map/_map.js @@ -69,9 +69,9 @@ var Map = function(opt){ break } - base.resize = function(){ - canvas.width = base.dimensions.a = window.innerWidth - canvas.height = base.dimensions.b = window.innerHeight + base.resize = function(w, h){ + canvas.width = base.dimensions.a = w || window.innerWidth + canvas.height = base.dimensions.b = h || window.innerHeight // resize here - esp if 2d-hires } diff --git a/public/assets/javascripts/rectangles/engine/rooms/builder.js b/public/assets/javascripts/rectangles/engine/rooms/builder.js index 5e09fab..f78fb91 100644 --- a/public/assets/javascripts/rectangles/engine/rooms/builder.js +++ b/public/assets/javascripts/rectangles/engine/rooms/builder.js @@ -14,6 +14,7 @@ PI = Math.PI HALF_PI = PI/2 TOP = CEILING, BOTTOM = FLOOR + $ = { browser: { mozilla: false } } function sidesToString(sides){ var s = "" if (sides & FRONT) s += "front " diff --git a/public/assets/javascripts/rectangles/engine/shapes/polyline.js b/public/assets/javascripts/rectangles/engine/shapes/polyline.js index 6c64128..609a2c8 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/polyline.js +++ b/public/assets/javascripts/rectangles/engine/shapes/polyline.js @@ -1,3 +1,7 @@ +// A Polyline is a set of points inputted by the user using the V2 editor to trace a blueprint. +// Additionally, it manages a set of MX objects which correspond to the walls in 3D. +// In this way, it attempts to bridge the 2D (canvas, imperative) and 3D (css, declarative) views. + var Polyline = Fiber.extend(function(base){ var exports = {} exports.init = function(){ diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js index 71f19d8..663f3fd 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js +++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js @@ -1,36 +1,58 @@ +// This algorithm takes the polylines from ShapeList as input and produces +// a set of Rooms which can be used by the existing V1 mover and editor. + +// The algorithm assumes that +// 1) all angles are orthogonal +// 2) all polylines are closed + var RegionList = (function(){ var RegionList = {} var regions = RegionList.regions RegionList.build = function(){ + + // first, get the segments sorted right to left & top to bottom var segments = RegionList.getSortedSegments() var rooms = [] var seen_rooms = {} var open_segments = [] - var closed_segments = [] var segment, open_segment, x_segment, y_segments, overlapped, seen_segments + // first pass: generate rooms from the vertical segments only for (var i = 0; i < segments.length; i++) { segment = segments[i] if (! segment.isVertical()) { continue } + + // check all the "open segments" we know about, i.e. rooms where we've only found + // the right wall. overlapped = false for (var j = 0; j < open_segments.length; j++) { open_segment = open_segments[j] + + // if these two segments overlap each other, then there is a room between them. if (segment.y.overlaps(open_segment.y)) { overlapped = true - closed_segments.push(open_segments[j]) open_segments.splice(j--, 1) + // the X part of the room will be the span between these two vertical segments' + // X components. the Y part of the room is the "split" or subdivision between + // the two horizontal vectors. + + // the split function is non-commutative, + // so we need to call A split B and B split A, + // then dedupe the segments we got back.. x_segment = new vec2( open_segment.x.a, segment.x.b ) y_segments = open_segment.y.split(segment.y, 0, 0) seen_segments = {} + // check each of the splits.. if the two segments overlap, then we definitely + // have a room here. y_segments.forEach(function(seg){ seen_segments[ seg[0]+"" ] = true var room = new Rect( x_segment, seg[0] ) @@ -46,7 +68,8 @@ var RegionList = (function(){ j++ }) - y_segments = segment.y.split(open_segment.y, TOP, BOTTOM) + // splitting the other way.. + y_segments = segment.y.split(open_segment.y, 0, 0) y_segments.forEach(function(seg){ if (seen_segments[ seg[0]+"" ]) return; var new_seg = new Rect( segment.x, seg[0] ) @@ -55,6 +78,9 @@ var RegionList = (function(){ }) } } + + // if we have overlap, then re-sort the open segments Y-wise + // and (again) dedupe.. if (overlapped) { open_segments = open_segments.sort(function(a,b){ if (a.y.a < b.y.a) { return -1 } @@ -74,6 +100,7 @@ var RegionList = (function(){ } } } + // if we don't have any overlap, then this is a new open segment. else { open_segments.push(segment) } @@ -81,11 +108,15 @@ var RegionList = (function(){ var splits, splitter + // second pass: now that we have a bunch of rooms, assign sides to all of them. + // sides are used in the "mover" script to do bounds checking. for (var i = 0; i < segments.length; i++) { segment = segments[i] var horizontal = segment.isHorizontal(), vertical = segment.isVertical() for (var r = 0; r < rooms.length; r++){ room = rooms[r] + + // vertical segments determine the left and right edges of the room, fairly simply. if (vertical) { if (segment.y.containsVec(room.y)) { if (segment.x.a == room.x.a) { @@ -96,6 +127,8 @@ var RegionList = (function(){ } } } + + // horizontal segments determine the front and back edges of the room. if (horizontal) { if (segment.x.containsVec(room.x)) { if (segment.y.a == room.y.a) { @@ -105,28 +138,30 @@ var RegionList = (function(){ room.sides |= BACK } } - - else if (segment.y.a == room.y.a || segment.y.a == room.y.b) { - if (room.x.overlaps(segment.x)) { - splits = room.x.split(segment.x, room.sides & LEFT, room.sides & RIGHT) - rooms.splice(r--, 1) - console.log(splits) - for (var k = 0; k < splits.length; k++) { - splitter = splits[k] - var new_room = new Rect( splitter[0], room.y ) - new_room.sides = 0 - new_room.sides |= splitter[1] | ( room.sides & FRONT_BACK ) - if (segment.x.overlaps( splitter[0] )) { - if (segment.y.a == new_room.y.a) { - new_room.sides |= FRONT - } - if (segment.y.a == new_room.y.b) { - new_room.sides |= BACK - } + + // however, since we did not split on horizontal segments, our rooms may + // only have partial overlap with these segments, in which case we need to + // split the rooms apart. + else if ((segment.y.a == room.y.a || segment.y.a == room.y.b) && room.x.overlaps(segment.x)) { + + // split the room across the segment. preserve whether or not we know the + // room borders a segment on the left or right. + splits = room.x.split(segment.x, room.sides & LEFT, room.sides & RIGHT) + rooms.splice(r--, 1) + for (var k = 0; k < splits.length; k++) { + splitter = splits[k] + var new_room = new Rect( splitter[0], room.y ) + new_room.sides = splitter[1] | ( room.sides & FRONT_BACK ) + if (segment.x.overlaps( splitter[0] )) { + if (segment.y.a == new_room.y.a) { + new_room.sides |= FRONT + } + if (segment.y.a == new_room.y.b) { + new_room.sides |= BACK } - rooms.unshift(new_room) - r++ } + rooms.unshift(new_room) + r++ } } @@ -137,6 +172,8 @@ var RegionList = (function(){ return { rooms: rooms } } + + // Gets a list of polylines from the ShapeList and sorts the segments. RegionList.getSortedSegments = function(){ // get a list of all segments from these polylines var segments = shapes.getAllSegments() diff --git a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js index 4373caf..90714c2 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/shapelist.js +++ b/public/assets/javascripts/rectangles/engine/shapes/shapelist.js @@ -1,3 +1,5 @@ +// The ShapeList manages the list of polylines which form a V2 layout. + var ShapeList = Fiber.extend(function(base){ var exports = {} exports.init = function(){ diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js index 226e56f..8942d92 100644 --- a/public/assets/javascripts/rectangles/models/vec2.js +++ b/public/assets/javascripts/rectangles/models/vec2.js @@ -214,13 +214,13 @@ } vec2.prototype.toString = function(){ - return "[" + round(this.a) + " " + round(this.b) + "]" + return "[" + Math.round(this.a) + " " + Math.round(this.b) + "]" } vec2.prototype.exactString = function(){ return "[" + this.a + " " + this.b + "]" } vec2.prototype.serialize = function(){ - return [ round(this.a), round(this.b) ] + return [ Math.round(this.a), Math.round(this.b) ] } vec2.prototype.deserialize = function(data){ this.a = data[0] diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js index 13f5cd7..9d4650b 100644 --- a/public/assets/javascripts/rectangles/models/wall.js +++ b/public/assets/javascripts/rectangles/models/wall.js @@ -10,6 +10,11 @@ vec2 = require('./vec2') Rect = require('./rect') UidGenerator = require('../util/uid') + wall_rotation = {} + wall_rotation[FRONT] = PI + wall_rotation[BACK] = 0 + wall_rotation[LEFT] = HALF_PI + wall_rotation[RIGHT] = -HALF_PI } var Wall = function(opt){ diff --git a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js index 39cf62e..a341a24 100644 --- a/public/assets/javascripts/ui/blueprint/BlueprintEditor.js +++ b/public/assets/javascripts/ui/blueprint/BlueprintEditor.js @@ -62,8 +62,7 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({ if (this.parent.orbiting) { scene.width = window.innerWidth/2 scene.height = window.innerHeight - this.parent.map.canvas.width = this.parent.map.dimensions.a = window.innerWidth/2 - this.parent.map.canvas.height = this.parent.map.dimensions.b = window.innerHeight + this.parent.map.resize( window.innerWidth/2, window.innerHeight ) this.parent.map.canvas.style.display = "block" } else { @@ -119,7 +118,7 @@ var BlueprintEditor = View.extend(AnimatedView.prototype).extend({ // var colors = ["rgba(0,0,0,0.1)"] // var colors = ["rgba(255,255,255,1)"] // -// map.draw.regions(this.rooms.rooms, colors, "#000") + map.draw.regions(this.rooms.rooms, colors, "#000") // this.rooms.rooms.forEach(function(room,i){ // map.draw.ctx.fillStyle = colors[i % colors.length] -- cgit v1.2.3-70-g09d2