|
- // 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/wouter/gopatterns/pkg/position"
- "git.wtrh.nl/wouter/gopatterns/pkg/vector"
- "github.com/tdewolff/canvas"
- )
-
- // ID defines a point id.
- type ID string
-
- // Point defines the interface for different types of points.
- type Point interface {
- // ID returns the point ID.
- ID() 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))
- }
|