Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

84 řádky
1.9KB

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