37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace swf2ass;
|
|
|
|
|
|
class Ellipse implements ComplexShape {
|
|
|
|
protected const c = 0.55228474983; // (4/3) * (sqrt(2) - 1)
|
|
//protected const c = 0.551915024494; // https://spencermortensen.com/articles/bezier-circle/
|
|
|
|
public Vector2 $center;
|
|
public Vector2 $radius;
|
|
|
|
public function __construct(Vector2 $center, Vector2 $radius) {
|
|
$this->center = $center;
|
|
$this->radius = $radius;
|
|
}
|
|
|
|
protected function getQuarter(Vector2 $size) : CubicCurveRecord{
|
|
return new CubicCurveRecord(
|
|
new Vector2($this->center->x - $size->x, $this->center->y - self::c * $size->y),
|
|
new Vector2($this->center->x - self::c * $size->x, $this->center->y - $size->y),
|
|
new Vector2($this->center->x, $this->center->y - $size->y),
|
|
new Vector2($this->center->x - $size->x, $this->center->y)
|
|
);
|
|
}
|
|
|
|
public function draw(): array {
|
|
return [
|
|
$this->getQuarter(new Vector2(-$this->radius->x, $this->radius->y)),
|
|
$this->getQuarter($this->radius)->reverse(), //Reverse so paths connect
|
|
$this->getQuarter(new Vector2($this->radius->x, -$this->radius->y)),
|
|
$this->getQuarter(new Vector2(-$this->radius->x, -$this->radius->y))->reverse(),
|
|
];
|
|
}
|
|
}
|