swf2ass/src/CubicCurveRecord.php

33 lines
1.2 KiB
PHP

<?php
namespace swf2ass;
class CubicCurveRecord implements Record {
public Vector2 $start;
public Vector2 $control1;
public Vector2 $control2;
public Vector2 $anchor;
public function __construct(Vector2 $control1, Vector2 $control2, Vector2 $anchor, Vector2 $start) {
$this->control1 = $control1;
$this->control2 = $control2;
$this->anchor = $anchor;
$this->start = $start;
}
public function getStart(): Vector2 {
return $this->start;
}
public function reverse(): CubicCurveRecord {
return new CubicCurveRecord($this->control2, $this->control1, $this->start, $this->anchor);
}
public function applyMatrixTransform(MatrixTransform $transform): CubicCurveRecord {
return new CubicCurveRecord($transform->applyToVector($this->control1), $transform->applyToVector($this->control2), $transform->applyToVector($this->anchor), $transform->applyToVector($this->start));
}
public static function fromQuadraticRecord(QuadraticCurveRecord $q): CubicCurveRecord {
return new CubicCurveRecord($q->start->add($q->control->multiply(2))->divide(3), $q->anchor->add($q->control->multiply(2))->divide(3), $q->anchor, $q->start);
}
}