commit bcde6ddff1f0218f21ce3da242988e7c7b8c96d5
parent 2e8a3d20263520914eac7e46edf27517b6d04558
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Mon, 23 Sep 2024 10:25:11 -0700
Draw door swings in editor
Currently it's a triangle rather than an arc; I'v put a lot of time
into trying to figure out how to use SVG arcs to little success.
Later I'll draw the door swings with an arc.
Diffstat:
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/files/floorplans/floorplan/editor.js b/files/floorplans/floorplan/editor.js
@@ -1,5 +1,6 @@
import { default as SVG } from "/lib/github.com/svgdotjs/svg.js/svg.js"
import * as backend from "./backend.js"
+import { Vector2 } from "/lib/github.com/ros2jsguy/threejs-math/math/Vector2.js"
const selectEvent = new Event("select")
const unselectEvent = new Event("unselect")
@@ -282,6 +283,7 @@ export class FloorplanEditor {
this.ui.bottom = this.draw.group().attr({ id: "bottom" })
let data = this.draw.group().attr({ id: "floorplan" })
+ this.doorSwings = data.group().attr({ id: "door_swings" })
data.group().attr({ id: "pointmaps" }) // lines
data.group().attr({ id: "points" }) // circles
this.layouts = data.group().attr({ id: "furniture_layouts" }) // g of furniture
@@ -607,13 +609,42 @@ export class FloorplanEditor {
.addClass(value.type)
.data("type", value.type)
} else {
- editor.draw.findExactlyOne("#pointmaps")
+ wall = editor.draw.findExactlyOne("#pointmaps")
.line(a.x, a.y, b.x, b.y)
.stroke({ color: "black", width: 400 })
.attr({ id })
.addClass(value.type)
.data("type", value.type)
}
+ if (value.type === "door" && value.door_swing) {
+ a = new Vector2(a.x, a.y)
+ b = new Vector2(b.x, b.y)
+ let len = a.distanceTo(b)
+ let f, t
+ if (value.door_swing.at(0) === "a") {
+ f = a
+ t = b
+ } else {
+ f = b
+ t = a
+ }
+
+ let n = 90
+ let deg = value.door_swing.at(1) === "+" ? n : -n
+ let e = t.clone().rotateAround(f, deg * Math.PI / 180)
+ let swingID = id + "-swing"
+ let swing = editor.draw.findOne(byId(swingID))
+ let d = `M ${f.x} ${f.y} L ${e.x} ${e.y} L ${t.x} ${t.y} Z`
+ if (swing != null) {
+ swing.plot(d)
+ } else {
+ editor.doorSwings.path(d)
+ .fill("rgba(0,0,0,.05)").stroke({ width: 100, color: "#AAA", dasharray: "400 100" })
+ .attr({ id: swingID })
+ }
+ } else {
+ wall.find("title").remove()
+ }
},
furniture: function(id, value) {
let maps = editor.backend.cache.furniture_maps