Line.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Grafika\DrawingObject;
  3. use Grafika\Color;
  4. /**
  5. * Base class
  6. * @package Grafika
  7. */
  8. abstract class Line
  9. {
  10. /**
  11. * X,Y pos 1.
  12. * @var array
  13. */
  14. protected $point1;
  15. /**
  16. * X,Y pos 2.
  17. * @var array
  18. */
  19. protected $point2;
  20. /**
  21. * @var int Thickness of line.
  22. */
  23. protected $thickness;
  24. /**
  25. * @var Color
  26. */
  27. protected $color;
  28. /**
  29. * Creates a line.
  30. *
  31. * @param array $point1 Array containing int X and int Y position of the starting point.
  32. * @param array $point2 Array containing int X and int Y position of the starting point.
  33. * @param int $thickness Thickness in pixel. Note: This is currently ignored in GD editor and falls back to 1.
  34. * @param Color|string $color Color of the line. Defaults to black.
  35. */
  36. public function __construct(array $point1, array $point2, $thickness = 1, $color = '#000000')
  37. {
  38. if (is_string($color)) {
  39. $color = new Color($color);
  40. }
  41. $this->point1 = $point1;
  42. $this->point2 = $point2;
  43. $this->thickness = $thickness;
  44. $this->color = $color;
  45. }
  46. /**
  47. * @return array
  48. */
  49. public function getPoint1()
  50. {
  51. return $this->point1;
  52. }
  53. /**
  54. * @return array
  55. */
  56. public function getPoint2()
  57. {
  58. return $this->point2;
  59. }
  60. /**
  61. * @return int
  62. */
  63. public function getThickness()
  64. {
  65. return $this->thickness;
  66. }
  67. /**
  68. * @return Color
  69. */
  70. public function getColor()
  71. {
  72. return $this->color;
  73. }
  74. }