commit 64c178c17f9396af4c399d0ec128edcc205519ce
parent 9251fd6875b1e3bccc958ace1a5d7fe25ba03b16
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Tue, 3 Sep 2024 10:19:57 -0700
Extend SVG.Circle with a vec() method
This uses the center of the circle rather than the corner like the
more general purpose vec function would do.
Diffstat:
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/files/floorplans/floorplan/geometry.js b/files/floorplans/floorplan/geometry.js
@@ -7,6 +7,12 @@ SVG.extend(SVG.Point, {
}
})
+SVG.extend(SVG.Circle, {
+ vec: function() {
+ return new Vector2(this.cx(), this.cy())
+ }
+})
+
SVG.extend(SVG.Shape, {
vec: function() {
return new Vector2(this.x(), this.y())
@@ -51,6 +57,16 @@ SVG.extend(SVG.Line, {
)
},
+ intersection: function(line2) {
+ let d = this.a * line2.b - line2.a * this.b;
+
+ return {
+ parallel: (d === 0),
+ x: (line2.b * this.c - this.b * line2.c) / d,
+ y: (this.a * line2.c - line2.a * this.c) / d
+ }
+ },
+
whereIsPoint: function(x, y) {
let p = new Vector2(x, y)
let width = this.attr("stroke-width") ?? 1