mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 01:38:41 +00:00
Improve performance
This commit is contained in:
parent
feb054b8fb
commit
fc2fd1343f
|
|
@ -132,12 +132,15 @@ final class Skew
|
|||
|
||||
$rotated = [[]];
|
||||
|
||||
$cXArr = [];
|
||||
for ($j = 0; $j < $dim[1]; ++$j) {
|
||||
$cXArr[] = $j - $dim[1] / 2.0; // center
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $dim[0]; ++$i) {
|
||||
$cY = $i - $dim[0] / 2.0; // center
|
||||
|
||||
for ($j = 0; $j < $dim[1]; ++$j) {
|
||||
$cX = $j - $dim[1] / 2.0; // center
|
||||
|
||||
foreach ($cXArr as $j => $cX) {
|
||||
$x = $cos * $cX + $sin * $cY + $dim[1] / 2.0;
|
||||
$y = -$sin * $cX + $cos * $cY + $dim[0] / 2.0;
|
||||
|
||||
|
|
@ -162,11 +165,11 @@ final class Skew
|
|||
*/
|
||||
private static function getNearestValue(array $pixel, array $dim, float $x, float $y) : int
|
||||
{
|
||||
$xLow = \min((int) $x, $dim[1] - 1);
|
||||
$xHigh = \min((int) \ceil($x), $dim[1] - 1);
|
||||
$xLow = ($x < 0) ? 0 : (($x > ($dim[1] - 1)) ? ($dim[1] - 1) : (int) $x);
|
||||
$xHigh = ($xLow == ($dim[1] - 1)) ? $xLow : ($xLow + 1);
|
||||
|
||||
$yLow = \min((int) $y, $dim[0] - 1);
|
||||
$yHigh = \min((int) \ceil($y), $dim[0] - 1);
|
||||
$yLow = ($y < 0) ? 0 : (($y > ($dim[0] - 1)) ? ($dim[0] - 1) : (int) $y);
|
||||
$yHigh = ($yLow == ($dim[0] - 1)) ? $yLow : ($yLow + 1);
|
||||
|
||||
$points = [
|
||||
[$xLow, $yLow],
|
||||
|
|
|
|||
|
|
@ -56,7 +56,11 @@ final class MonotoneChain
|
|||
|
||||
// Lower hull
|
||||
for ($i = 0; $i < $n; ++$i) {
|
||||
while ($k >= 2 && self::cross($result[$k - 2], $result[$k - 1], $points[$i]) <= 0) {
|
||||
while ($k >= 2
|
||||
&& ($result[$k - 1]['x'] - $result[$k - 2]['x']) * ($points[$i]['y'] - $result[$k - 2]['y'])
|
||||
- ($result[$k - 1]['y'] - $result[$k - 2]['y']) * ($points[$i]['x'] - $result[$k - 2]['x']
|
||||
) <= 0
|
||||
) {
|
||||
--$k;
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +69,11 @@ final class MonotoneChain
|
|||
|
||||
// Upper hull
|
||||
for ($i = $n - 2, $t = $k + 1; $i >= 0; --$i) {
|
||||
while ($k >= $t && self::cross($result[$k - 2], $result[$k - 1], $points[$i]) <= 0) {
|
||||
while ($k >= $t
|
||||
&& ($result[$k - 1]['x'] - $result[$k - 2]['x']) * ($points[$i]['y'] - $result[$k - 2]['y'])
|
||||
- ($result[$k - 1]['y'] - $result[$k - 2]['y']) * ($points[$i]['x'] - $result[$k - 2]['x']
|
||||
) <= 0
|
||||
) {
|
||||
--$k;
|
||||
}
|
||||
|
||||
|
|
@ -78,22 +86,6 @@ final class MonotoneChain
|
|||
return \array_slice($result, 0, $k - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counter clock wise turn?
|
||||
*
|
||||
* @param array{x:int|float, y:int|float} $a Point a
|
||||
* @param array{x:int|float, y:int|float} $b Point b
|
||||
* @param array{x:int|float, y:int|float} $c Point c
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function cross(array $a, array $b, array $c) : float
|
||||
{
|
||||
return ($b['x'] - $a['x']) * ($c['y'] - $a['y']) - ($b['y'] - $a['y']) * ($c['x'] - $a['x']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort by x coordinate then by z coordinate
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user