// Package point contains different types of points for drawing patterns. // There are points that define an absolute position or a relative position. // Relative can be a specific distance one point or between two other points. package point import ( "git.wtrh.nl/patterns/gopatterns/pkg/position" "git.wtrh.nl/patterns/gopatterns/pkg/util" "git.wtrh.nl/patterns/gopatterns/pkg/vector" "github.com/tdewolff/canvas" ) // Point defines the interface for different types of points. type Point interface { // ID returns the point ID. ID() util.ID // Position calculates and returns the absolute [position.Position]. Position() position.Position // Vector calculates and returns the absolute [vector.Vector]. Vector() vector.Vector // Matrix calculates and returns the [canvas.Matrix] of a point. Matrix() canvas.Matrix // Name returns the name of a point. Name() string // SetDraw indicates that the point should be drawn. SetDraw() // Draw returns if the point should be drawn. Draw() bool // Hide returns if the point must remain hidden. Hide() bool // SetHide indicates that the must be hidden. SetHide() } // Draw draws a specific Point to the provided [canvas.Canvas]. // The point is only drawn when the point states that it should be drawn and not must be hidden. func Draw(c *canvas.Canvas, point Point, face *canvas.FontFace, debug bool) { if !debug && (!point.Draw() || point.Hide()) { return } path := canvas.Circle(1.0) m := point.Matrix() style := canvas.Style{Fill: canvas.Paint{Color: canvas.Black}} c.RenderPath(path, style, m) text := canvas.NewTextLine(face, point.Name(), canvas.Bottom) c.RenderText(text, m.Translate(2, -4)) if debug { yStyle := canvas.Style{ Fill: canvas.Paint{}, Stroke: canvas.Paint{Color: canvas.Green}, StrokeWidth: 0.2, StrokeCapper: canvas.RoundCap, StrokeJoiner: canvas.BevelJoin, } yLine := canvas.Line(0, 10) xStyle := canvas.Style{ Fill: canvas.Paint{}, Stroke: canvas.Paint{Color: canvas.Red}, StrokeWidth: 0.2, StrokeCapper: canvas.RoundCap, StrokeJoiner: canvas.BevelJoin, } xLine := canvas.Line(10, 0) c.RenderPath(yLine, yStyle, m) c.RenderPath(xLine, xStyle, m) } }