www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit b0beacff4c7c742fce986686fabfd232b5a3892c
parent 4f24e993bec795957abd07c19008595c52f035e6
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Tue, 15 Oct 2024 23:57:02 -0700

Add length of pointmap to each side of cursor

To make this intuitive the lengths are sorted by which point of the
pointmap is above the other, or if equal which is to the left of
the other.

Diffstat:
Mfiles/floorplans/floorplan/geometry.js | 14++++++++++++++
Mfiles/floorplans/floorplan/main.js | 34+++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/files/floorplans/floorplan/geometry.js b/files/floorplans/floorplan/geometry.js @@ -214,3 +214,17 @@ export function length(a, b, length) { export function lineAngle(p1, p2) { return Math.atan2(p2.y - p1.y, p2.x - p1.x) } + +export function compareVecs(a, b) { + if (a.y !== b.y) { + return a.y < b.y + } + if (a.x < b.x) { + return true + } + return false +} + +export function sortVecs(vecs) { + return vecs.sort(compareVecs) +} diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js @@ -38,7 +38,8 @@ const modes = { pointerup: [precisePointHandler, precisePointMapHandler, furnitureHandler], keydown: [keyHandler], dblclick: [precisePointMapHandler, furnitureHandler], - select: selectHandler + select: selectHandler, + reselect: selectHandler } } } @@ -361,6 +362,37 @@ function selectHandler(event, editor, state) { .appendChild(document.createTextNode("Length: " + userLength(editor, editor.pointmapLength(groups.pntmap[0])))) + const dolengths = function(m, point) { + let intr = m.closestLinearInterpolation(new Vector2(point.x, point.y)) + let points = m.vecs() + let len = geometry.length(points[0], points[1]) + let al = len * intr + let bl = len * (1.0 - intr) + if (!geometry.compareVecs(points[0], points[1])) { + let t = al + al = bl + bl = t + } + + let it = c.appendChild(document.createElement("li")) + it.id = "pointmap_lengths" + it.append(document.createTextNode("(")) + let a = it.appendChild(document.createElement("span")) + it.append(document.createTextNode(" × ")) + let b = it.appendChild(document.createElement("span")) + it.append(document.createTextNode(")")) + + a.textContent = userLength(editor, al) + b.textContent = userLength(editor, bl) + } + let m = editor.findObj(groups.pntmap[0]) + dolengths(m, State.lastClick) + /* + * In the future, I could change the function to update the values, + * but it wouldn't work well on touch devices anyway. + *m.on("pointermove", function(ev) { dolengths(m, editor.draw.point(ev.clientX, ev.clientY)) }) + */ + let pm = editor.backend.reqObj(groups.pntmap[0]) if (pm.type === "door") { const swingButton = function(backward) {