/** * @param float $r1 * @param float $r2 * @param float $alpha * @param float $angle * * @return Path */ function getGroupPath($r1, $r2, $alpha, $angle) { $radians = ArcUtils::getArcRadians($alpha, $angle); $scale = ArcUtils::getScale($radians); list($sX, $sY) = ArcUtils::getPolarPoint($r2, $radians[0]); list($curX, $curY) = ArcUtils::getPolarPoint($r1, $radians[0]); $path = new Path($sX, $sY); if ($r1 !== $r2) { $path->lineTo($curX, $curY); } $pos = 1; while ($pos < count($radians)) { list($nextX, $nextY) = ArcUtils::getPolarPoint($r1, $radians[$pos++]); list($c1X, $c1Y) = ArcUtils::getBezierControl($curX, $curY, -$scale); list($c2X, $c2Y) = ArcUtils::getBezierControl($nextX, $nextY, $scale); $path->curveTo($c1X, $c1Y, $c2X, $c2Y, $nextX, $nextY); $curX = $nextX; $curY = $nextY; } list($eX, $eY) = ArcUtils::getPolarPoint($r2, end($radians)); if ($r1 !== $r2) { $path->lineTo($eX, $eY); } return $path; }
/** * @return Path */ private function getPartialRingPath() { $outer = $this->getOuterRadius(); $inner = $this->getInnerRadius(); $cx = $this->getX(); $cy = $this->getY(); if ($this->angle === 0.0) { $radian = ArcUtils::toRadian($this->getAlpha()); list($outerX, $outerY) = ArcUtils::getPolarPoint($outer, $radian); list($innerX, $innerY) = ArcUtils::getPolarPoint($inner, $radian); return (new Path($outerX + $cx, $outerY + $cy))->lineTo($innerX + $cx, $innerY + $cy)->close(); } $radians = ArcUtils::getArcRadians($this->getAlpha(), $this->getAngle()); $scale = ArcUtils::getScale($radians); $pos = 0; // outer arc list($curX, $curY) = ArcUtils::getPolarPoint($outer, $radians[$pos++]); $path = new Path($curX + $cx, $curY + $cy); while ($pos < count($radians)) { list($nextX, $nextY) = ArcUtils::getPolarPoint($outer, $radians[$pos++]); list($c1X, $c1Y) = ArcUtils::getBezierControl($curX, $curY, -$scale); list($c2X, $c2Y) = ArcUtils::getBezierControl($nextX, $nextY, $scale); $path->curveTo($c1X + $cx, $c1Y + $cy, $c2X + $cx, $c2Y + $cy, $nextX + $cx, $nextY + $cy); $curX = $nextX; $curY = $nextY; } // inner arc list($curX, $curY) = ArcUtils::getPolarPoint($inner, $radians[--$pos]); if ($this->angle === 360.0) { // full ring $path->close()->moveTo($curX + $cx, $curY + $cy); } else { $path->lineTo($curX + $cx, $curY + $cy); } while ($pos > 0) { list($nextX, $nextY) = ArcUtils::getPolarPoint($inner, $radians[--$pos]); list($c1X, $c1Y) = ArcUtils::getBezierControl($curX, $curY, $scale); list($c2X, $c2Y) = ArcUtils::getBezierControl($nextX, $nextY, -$scale); $path->curveTo($c1X + $cx, $c1Y + $cy, $c2X + $cx, $c2Y + $cy, $nextX + $cx, $nextY + $cy); $curX = $nextX; $curY = $nextY; } // close path $path->close(); return $path; }