www.spaceplanner.app

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

commit 1459ee837ac79711a99cc41e2f0b7be4cf44f518
parent bcde6ddff1f0218f21ce3da242988e7c7b8c96d5
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Mon, 23 Sep 2024 10:26:24 -0700

Add point_offset method to svg.js lines

This can be used to tell you whether a point is to the left or right
(or top or bottom, etc.) of a given line.

Diffstat:
Mfiles/floorplans/floorplan/geometry.js | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/files/floorplans/floorplan/geometry.js b/files/floorplans/floorplan/geometry.js @@ -29,6 +29,20 @@ SVG.extend(SVG.Line, { return vecs }, + // See https://math.stackexchange.com/questions/274712/calculate-on-which-side-of-a-straight-line-is-a-given-po + vecs_top_first: function() { + let v = this.vecs() + return v[1].y > v[0].y ? v : [v[1], v[0]]; + }, + + point_offset: function(point) { + const cross = function(a, b, o) { + return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x) + } + const t = this.vecs_top_first() + return cross(point, t[1], t[0]) + }, + /* * Most of this copied from the svg.js math library, * but I didn't particularly like the look of the