Skip to content

Commit

Permalink
Add doc blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 18, 2023
1 parent 04faec2 commit 2d0369b
Show file tree
Hide file tree
Showing 10 changed files with 383 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/Geometry/Circle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

class Circle extends Ellipse
{
/**
* Create new Circle instance
*
* @param int $diameter
* @param PointInterface $pivot
* @return void
*/
public function __construct(
protected int $diameter,
protected PointInterface $pivot = new Point()
Expand All @@ -14,6 +21,12 @@ public function __construct(
$this->setHeight($diameter);
}

/**
* Set diameter of circle
*
* @param int $diameter
* @return Circle
*/
public function setDiameter(int $diameter): self
{
$this->setWidth($diameter);
Expand All @@ -22,16 +35,32 @@ public function setDiameter(int $diameter): self
return $this;
}

/**
* Get diameter of circle
*
* @return int
*/
public function diameter(): int
{
return $this->diameter;
}

/**
* Set radius of circle
*
* @param int $radius
* @return Circle
*/
public function setRadius(int $radius): self
{
return $this->setDiameter(intval($radius * 2));
}

/**
* Get radius of circle
*
* @return int
*/
public function radius(): int
{
return intval($this->diameter / 2);
Expand Down
48 changes: 48 additions & 0 deletions src/Geometry/Ellipse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,95 @@ class Ellipse implements DrawableInterface
use HasBorder;
use HasBackgroundColor;

/**
* Create new Ellipse
*
* @param int $width
* @param int $height
* @param PointInterface $pivot
* @return void
*/
public function __construct(
protected int $width,
protected int $height,
protected PointInterface $pivot = new Point()
) {
}


/**
* {@inheritdoc}
*
* @see DrawableInterface::position()
*/
public function position(): PointInterface
{
return $this->pivot;
}

/**
* Return pivot point of Ellipse
*
* @return PointInterface
*/
public function pivot(): PointInterface
{
return $this->pivot;
}

/**
* Set size of Ellipse
*
* @param int $width
* @param int $height
* @return Ellipse
*/
public function setSize(int $width, int $height): self
{
return $this->setWidth($width)->setHeight($height);
}

/**
* Set width of Ellipse
*
* @param int $width
* @return Ellipse
*/
public function setWidth(int $width): self
{
$this->width = $width;

return $this;
}

/**
* Set height of Ellipse
*
* @param int $height
* @return Ellipse
*/
public function setHeight(int $height): self
{
$this->height = $height;

return $this;
}

/**
* Get width of Ellipse
*
* @return int
*/
public function width(): int
{
return $this->width;
}

/**
* Get height of Ellipse
*
* @return int
*/
public function height(): int
{
return $this->height;
Expand Down
60 changes: 60 additions & 0 deletions src/Geometry/Line.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,94 @@ class Line implements DrawableInterface
use HasBorder;
use HasBackgroundColor;

/**
* Create new line instance
*
* @param Point $start
* @param Point $end
* @param int $width
* @return void
*/
public function __construct(
protected Point $start,
protected Point $end,
protected int $width = 1
) {
}

/**
* {@inheritdoc}
*
* @see DrawableInterface::position()
*/
public function position(): PointInterface
{
return $this->start;
}

/**
* Return line width
*
* @return int
*/
public function width(): int
{
return $this->width;
}

/**
* Set line width
*
* @param int $width
* @return Line
*/
public function setWidth(int $width): self
{
$this->width = $width;

return $this;
}

/**
* Get starting point of line
*
* @return Point
*/
public function start(): Point
{
return $this->start;
}

/**
* get end point of line
*
* @return Point
*/
public function end(): Point
{
return $this->end;
}

/**
* Set starting point of line
*
* @param Point $start
* @return Line
*/
public function setStart(Point $start): self
{
$this->start = $start;

return $this;
}

/**
* Set starting point of line by coordinates
*
* @param int $x
* @param int $y
* @return Line
*/
public function from(int $x, int $y): self
{
$this->start()->setX($x);
Expand All @@ -61,6 +108,13 @@ public function from(int $x, int $y): self
return $this;
}

/**
* Set end point of line by coordinates
*
* @param int $x
* @param int $y
* @return Line
*/
public function to(int $x, int $y): self
{
$this->end()->setX($x);
Expand All @@ -69,6 +123,12 @@ public function to(int $x, int $y): self
return $this;
}

/**
* Set end point of line
*
* @param Point $end
* @return Line
*/
public function setEnd(Point $end): self
{
$this->end = $end;
Expand Down
18 changes: 18 additions & 0 deletions src/Geometry/Pixel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,38 @@

class Pixel extends Point
{
/**
* Create new pixel instance
*
* @param ColorInterface $background
* @param int $x
* @param int $y
* @return void
*/
public function __construct(
protected ColorInterface $background,
protected int $x,
protected int $y
) {
}

/**
* {@inheritdoc}
*
* @see DrawableInterface::setBackgroundColor()
*/
public function setBackgroundColor(ColorInterface $background): self
{
$this->background = $background;

return $this;
}

/**
* {@inheritdoc}
*
* @see DrawableInterface::backgroundColor()
*/
public function backgroundColor(): ColorInterface
{
return $this->background;
Expand Down
7 changes: 7 additions & 0 deletions src/Geometry/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

class Point implements PointInterface
{
/**
* Create new point instance
*
* @param int $x
* @param int $y
* @return void
*/
public function __construct(
protected int $x = 0,
protected int $y = 0
Expand Down
17 changes: 17 additions & 0 deletions src/Geometry/Polygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,34 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
use HasBorder;
use HasBackgroundColor;

/**
* Create new polygon instance
*
* @param array $points
* @param PointInterface $pivot
* @return void
*/
public function __construct(
protected array $points = [],
protected PointInterface $pivot = new Point()
) {
}

/**
* {@inheritdoc}
*
* @see DrawableInterface::position()
*/
public function position(): PointInterface
{
return $this->pivot;
}

/**
* Implement iteration through all points of polygon
*
* @return Traversable
*/
public function getIterator(): Traversable
{
return new ArrayIterator($this->points);
Expand Down
Loading

0 comments on commit 2d0369b

Please sign in to comment.