Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.39 KB | None | 0 0
  1. package cirno
  2.  
  3. // Circle represents a geometric euclidian circle.
  4. type Circle struct {
  5.     center Vector
  6.     radius float64
  7.     tag
  8.     data
  9. }
  10.  
  11. // Center returns the coordinates of the center
  12. // of the circle.
  13. func (c *Circle) Center() Vector {
  14.     return c.center
  15. }
  16.  
  17. // Angle doesn't return any valuable
  18. // data because there is no sense to
  19. // rotate the circle.
  20. //
  21. // This method is added just to match the
  22. // Shape interface.
  23. func (c *Circle) Angle() float64 {
  24.     return 0
  25. }
  26.  
  27. // AngleRadians doesn't return any valuable
  28. // data because there is no sense to
  29. // rotate the circle.
  30. //
  31. // This method is added just to match the
  32. // Shape interface.
  33. func (c *Circle) AngleRadians() float64 {
  34.     return 0
  35. }
  36.  
  37. // Radius returns the radius og the circle.
  38. func (c *Circle) Radius() float64 {
  39.     return c.radius
  40. }
  41.  
  42. // Move moves the circle in the specified direction.
  43. func (c *Circle) Move(direction Vector) Vector {
  44.     c.center = c.center.Add(direction)
  45.  
  46.     return c.center
  47. }
  48.  
  49. // Rotate does nothing to the circle because there
  50. // is no sense to rotate it.
  51. //
  52. // This method is added just to match the
  53. // Shape interface.
  54. func (c *Circle) Rotate(angle float64) float64 {
  55.     return 0
  56. }
  57.  
  58. // RotateRadians does nothing to the circle because there
  59. // is no sense to rotate it.
  60. //
  61. // This method is added just to match the
  62. // Shape interface.
  63. func (c *Circle) RotateRadians(angle float64) float64 {
  64.     return 0
  65. }
  66.  
  67. // SetPosition sets the circle position to the given
  68. // coordinates.
  69. func (c *Circle) SetPosition(pos Vector) Vector {
  70.     c.center = pos
  71.  
  72.     return c.center
  73. }
  74.  
  75. // SetAngle does nothing to the circle because there is
  76. // no sense to rotate it.
  77. //
  78. // This method is added just to match the
  79. // Shape interface.
  80. func (c *Circle) SetAngle(angle float64) float64 {
  81.     return 0
  82. }
  83.  
  84. // SetAngleRadians does nothing to the circle because there is
  85. // no sense to rotate it.
  86. //
  87. // This method is added just to match the
  88. // Shape interface.
  89. func (c *Circle) SetAngleRadians(angle float64) float64 {
  90.     return 0
  91. }
  92.  
  93. // ContainsPoint detects if the given point is inside the circle.
  94. func (c *Circle) ContainsPoint(point Vector) bool {
  95.     d := c.center.Subtract(point)
  96.  
  97.     return d.SquaredMagnitude() <= c.radius*c.radius
  98. }
  99.  
  100. // NewCircle create a new circle with the given parameters.
  101. func NewCircle(position Vector, radius float64) *Circle {
  102.     return &Circle{
  103.         center: position,
  104.         radius: radius,
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement