|
- package point
-
- import (
- "git.wtrh.nl/wouter/gopatterns/pkg/position"
- "git.wtrh.nl/wouter/gopatterns/pkg/vector"
- "github.com/tdewolff/canvas"
- )
-
- // AbsolutePoint implements Point and defines an absolute position.
- // All other points should eventually be relative to one or more absolute point(s).
- type AbsolutePoint struct {
- id ID
- position position.Position
- name string
- draw bool
- hide bool
- }
-
- // 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)
- }
-
- // ID returns the point ID.
- func (a *AbsolutePoint) ID() ID {
- return a.id
- }
-
- // Name returns the name of a point.
- func (a *AbsolutePoint) Name() string {
- return a.name
- }
-
- // Position calculates and returns the absolute [position.Position].
- func (a *AbsolutePoint) Position() position.Position {
- return a.position
- }
-
- // Vector calculates and returns the absolute [vector.Vector].
- func (a *AbsolutePoint) Vector() vector.Vector {
- return a.Position().Vector
- }
-
- // NewAbsolutePoint returns a new absolute point.
- func NewAbsolutePoint(x, y, r float64, id ID) *AbsolutePoint {
- return &AbsolutePoint{
- position: position.Position{
- Vector: vector.Vector{
- X: x,
- Y: y,
- },
- Rotation: r,
- },
- id: id,
- name: string(id),
- }
- }
-
- // Draw returns if the point should be drawn.
- func (a *AbsolutePoint) Draw() bool {
- return a.draw
- }
-
- // SetDraw indicates that the point should be drawn.
- func (a *AbsolutePoint) SetDraw() {
- a.draw = true
- }
-
- // UnsetDraw indicates that the point should not be drawn.
- func (a *AbsolutePoint) UnsetDraw() {
- a.draw = true
- }
-
- // Hide returns if the point must remain hidden.
- func (a *AbsolutePoint) Hide() bool {
- return a.hide
- }
-
- // SetHide indicates that the must be hidden.
- func (a *AbsolutePoint) SetHide() {
- a.hide = true
- }
|