From 8682ca011100e612895350b666bf852fc22e196a Mon Sep 17 00:00:00 2001 From: Wouter Horlings Date: Sun, 27 Jul 2025 18:26:37 +0200 Subject: [PATCH] Add unit tests for points --- pkg/path/path.go | 2 +- pkg/point/absolute_point.go | 4 ++-- pkg/position/position.go | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/path/path.go b/pkg/path/path.go index e1be8c3..2a96310 100644 --- a/pkg/path/path.go +++ b/pkg/path/path.go @@ -20,7 +20,7 @@ func (p *Polygon) Through() []point.Point { // NewPolygon returns a new [Polygon]. func NewPolygon(points []point.Point, style Style, id util.ID) *Polygon { - return &Polygon{points: points, style: style} + return &Polygon{points: points, style: style, id: id} } // WithStyle updates the style of the Polygon. diff --git a/pkg/point/absolute_point.go b/pkg/point/absolute_point.go index 6b4e912..998621b 100644 --- a/pkg/point/absolute_point.go +++ b/pkg/point/absolute_point.go @@ -19,7 +19,7 @@ type AbsolutePoint struct { // Matrix calculates and returns the [canvas.Matrix] of a point. func (a *AbsolutePoint) Matrix() canvas.Matrix { - return canvas.Identity.Translate(a.position.Vector.Values()).Rotate(a.position.Rotation) + return canvas.Identity.Translate(a.position.Vector.Values()).Rotate(a.position.RotationD()) } // ID returns the point ID. @@ -69,7 +69,7 @@ func (a *AbsolutePoint) SetDraw() { // UnsetDraw indicates that the point should not be drawn. func (a *AbsolutePoint) UnsetDraw() { - a.draw = true + a.draw = false } // Hide returns if the point must remain hidden. diff --git a/pkg/position/position.go b/pkg/position/position.go index e15dcc4..80b203f 100644 --- a/pkg/position/position.go +++ b/pkg/position/position.go @@ -22,6 +22,10 @@ func (p Position) Add(q Position) Position { } } +func (p Position) RotationD() float64 { + return p.Rotation*180/math.Pi +} + // Distance returns the distance between two positions. func (p Position) Distance(q Position) float64 { return p.Vector.Distance(q.Vector)