Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

60 linhas
1.6KB

  1. // Package point contains different types of points for drawing patterns.
  2. // There are points that define an absolute position or a relative position.
  3. // Relative can be a specific distance one point or between two other points.
  4. package point
  5. import (
  6. "git.wtrh.nl/wouter/gopatterns/pkg/position"
  7. "git.wtrh.nl/wouter/gopatterns/pkg/vector"
  8. "github.com/tdewolff/canvas"
  9. )
  10. // ID defines a point id.
  11. type ID string
  12. // Point defines the interface for different types of points.
  13. type Point interface {
  14. // ID returns the point ID.
  15. ID() ID
  16. // Position calculates and returns the absolute [position.Position].
  17. Position() position.Position
  18. // Vector calculates and returns the absolute [vector.Vector].
  19. Vector() vector.Vector
  20. // Matrix calculates and returns the [canvas.Matrix] of a point.
  21. Matrix() canvas.Matrix
  22. // Name returns the name of a point.
  23. Name() string
  24. // SetDraw indicates that the point should be drawn.
  25. SetDraw()
  26. // Draw returns if the point should be drawn.
  27. Draw() bool
  28. // Hide returns if the point must remain hidden.
  29. Hide() bool
  30. // SetHide indicates that the must be hidden.
  31. SetHide()
  32. }
  33. // Draw draws a specific Point to the provided [canvas.Canvas].
  34. // The point is only drawn when the point states that it should be drawn and not must be hidden.
  35. func Draw(c *canvas.Canvas, point Point, face *canvas.FontFace) {
  36. if !point.Draw() || point.Hide() {
  37. return
  38. }
  39. path := canvas.Circle(1.0)
  40. m := point.Matrix()
  41. style := canvas.Style{Fill: canvas.Paint{Color: canvas.Black}}
  42. c.RenderPath(path, style, m)
  43. text := canvas.NewTextLine(face, point.Name(), canvas.Bottom)
  44. c.RenderText(text, m.Translate(2, -4))
  45. }