Polygon.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace Grafika\DrawingObject;
  3. use Grafika\Color;
  4. /**
  5. * Base class
  6. * @package Grafika
  7. */
  8. abstract class Polygon
  9. {
  10. /**
  11. * Image width in pixels
  12. * @var int
  13. */
  14. protected $width;
  15. /**
  16. * Image height in pixels
  17. * @var int
  18. */
  19. protected $height;
  20. /**
  21. * Array of all X and Y positions. Must have at least three positions (x,y).
  22. * @var array
  23. */
  24. protected $points;
  25. /**
  26. * @var int
  27. */
  28. protected $borderSize;
  29. /**
  30. * @var Color
  31. */
  32. protected $fillColor;
  33. /**
  34. * @var Color
  35. */
  36. protected $borderColor;
  37. /**
  38. * Creates a polygon.
  39. *
  40. * @param array $points Array of all X and Y positions. Must have at least three positions.
  41. * @param int $borderSize Size of the border in pixels. Defaults to 1 pixel. Set to 0 for no border.
  42. * @param Color|string|bool $borderColor Border color. Defaults to black. Set to null for no color.
  43. * @param Color|string|bool $fillColor Fill color. Defaults to white. Set to null for no color.
  44. */
  45. public function __construct($points = array(array(0,0), array(0,0), array(0,0)), $borderSize = 1, $borderColor = '#000000', $fillColor = '#FFFFFF') {
  46. if (is_string($borderColor)) {
  47. $borderColor = new Color($borderColor);
  48. }
  49. if (is_string($fillColor)) {
  50. $fillColor = new Color($fillColor);
  51. }
  52. $this->points = $points;
  53. $this->borderSize = $borderSize;
  54. $this->borderColor = $borderColor;
  55. $this->fillColor = $fillColor;
  56. }
  57. /**
  58. * @return int
  59. */
  60. public function getWidth()
  61. {
  62. return $this->width;
  63. }
  64. /**
  65. * @return int
  66. */
  67. public function getHeight()
  68. {
  69. return $this->height;
  70. }
  71. /**
  72. * @return array
  73. */
  74. public function getPoints()
  75. {
  76. return $this->points;
  77. }
  78. /**
  79. * @return int
  80. */
  81. public function getBorderSize()
  82. {
  83. return $this->borderSize;
  84. }
  85. /**
  86. * @return Color
  87. */
  88. public function getFillColor()
  89. {
  90. return $this->fillColor;
  91. }
  92. /**
  93. * @return Color
  94. */
  95. public function getBorderColor()
  96. {
  97. return $this->borderColor;
  98. }
  99. }