25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.8KB

  1. package point
  2. import (
  3. "git.wtrh.nl/wouter/gopatterns/pkg/position"
  4. "git.wtrh.nl/wouter/gopatterns/pkg/vector"
  5. "github.com/tdewolff/canvas"
  6. )
  7. // AbsolutePoint implements Point and defines an absolute position.
  8. // All other points should eventually be relative to one or more absolute point(s).
  9. type AbsolutePoint struct {
  10. id ID
  11. position position.Position
  12. name string
  13. draw bool
  14. hide bool
  15. }
  16. // Matrix calculates and returns the [canvas.Matrix] of a point.
  17. func (a *AbsolutePoint) Matrix() canvas.Matrix {
  18. return canvas.Identity.Translate(a.position.Vector.Values()).Rotate(a.position.Rotation)
  19. }
  20. // ID returns the point ID.
  21. func (a *AbsolutePoint) ID() ID {
  22. return a.id
  23. }
  24. // Name returns the name of a point.
  25. func (a *AbsolutePoint) Name() string {
  26. return a.name
  27. }
  28. // Position calculates and returns the absolute [position.Position].
  29. func (a *AbsolutePoint) Position() position.Position {
  30. return a.position
  31. }
  32. // Vector calculates and returns the absolute [vector.Vector].
  33. func (a *AbsolutePoint) Vector() vector.Vector {
  34. return a.Position().Vector
  35. }
  36. // NewAbsolutePoint returns a new absolute point.
  37. func NewAbsolutePoint(x, y, r float64, id ID) *AbsolutePoint {
  38. return &AbsolutePoint{
  39. position: position.Position{
  40. Vector: vector.Vector{
  41. X: x,
  42. Y: y,
  43. },
  44. Rotation: r,
  45. },
  46. id: id,
  47. name: string(id),
  48. }
  49. }
  50. // Draw returns if the point should be drawn.
  51. func (a *AbsolutePoint) Draw() bool {
  52. return a.draw
  53. }
  54. // SetDraw indicates that the point should be drawn.
  55. func (a *AbsolutePoint) SetDraw() {
  56. a.draw = true
  57. }
  58. // UnsetDraw indicates that the point should not be drawn.
  59. func (a *AbsolutePoint) UnsetDraw() {
  60. a.draw = true
  61. }
  62. // Hide returns if the point must remain hidden.
  63. func (a *AbsolutePoint) Hide() bool {
  64. return a.hide
  65. }
  66. // SetHide indicates that the must be hidden.
  67. func (a *AbsolutePoint) SetHide() {
  68. a.hide = true
  69. }