swf2ass/src/Coordinate.php
2021-12-26 15:59:57 +01:00

46 lines
1.3 KiB
PHP

<?php
namespace swf2ass;
class Coordinate {
public $x;
public $y;
public function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
public function equals(Coordinate $b): bool {
return $b->x === $this->x and $b->y === $this->y;
}
public function distance(Coordinate $b): float {
return sqrt(pow($this->x - $b->x, 2) + pow($this->y - $b->y, 2));
}
public function applyTransform(MatrixTransform $transform): Coordinate {
return new Coordinate($this->x * ($transform->scaleX ?? 1) + $this->y * ($transform->skewY ?? 0) + ($transform->transX ?? 0), $this->y * ($transform->scaleY ?? 1) + $this->x * ($transform->skewX ?? 0) + ($transform->transY ?? 0));
}
public function add(Coordinate $b): Coordinate {
return new Coordinate($this->x + $b->x, $this->y + $b->y);
}
public function sub(Coordinate $b): Coordinate {
return new Coordinate($this->x - $b->x, $this->y - $b->y);
}
public function multiply($size): Coordinate {
return new Coordinate($this->x * $size, $this->y * $size);
}
public function divide($size): Coordinate {
return new Coordinate($this->x / $size, $this->y / $size);
}
public function toPixel($twipSize = TWIP_SIZE): Coordinate {
return $this->divide($twipSize);
}
}