53Path::Path(
const std::vector<Vector2f>& lines,
float cornerRadius) {
54 std::vector<std::pair<Vector2f, float>> l(lines.size());
55 std::transform(lines.begin(), lines.end(), l.begin(), [&](
const Vector2f& pos) -> std::pair<Vector2f, float> {
56 return std::make_pair(pos, cornerRadius);
80 for (
size_t i = 0; i < lines.size(); i++) {
83 float radius = lines[i].second;
87 Vector2f prev = i != 0 ? lines[i-1].first : lines.back().first;
88 Vector2f next = i+1 < lines.size() ? lines[i+1].first : lines.front().first;
91 float cp = (prev - corner).cross(next - corner);
103 prevOffset = (prev - corner).rotateClockwise().
normalized() * radius;
104 nextOffset = (next - corner).rotateCounterClockwise().
normalized() * radius;
109 prevOffset = (prev - corner).rotateCounterClockwise().
normalized() * radius;
110 nextOffset = (next - corner).rotateClockwise().
normalized() * radius;
114 Vector2f prevLp0 = prev + prevOffset;
115 Vector2f prevLp1 = corner + prevOffset;
116 Vector2f nextLp0 = next + nextOffset;
117 Vector2f nextLp1 = corner + nextOffset;
119 Vector2f prevDist = prevLp1 - prevLp0;
120 Vector2f nextDist = nextLp1 - nextLp0;
123 float prevT = (nextLp0 - prevLp0).cross(nextDist / prevDist.
cross(nextDist));
124 float nextT = (nextLp0 - prevLp0).cross(prevDist / prevDist.
cross(nextDist));
126 Vector2f center = prevLp0 + prevDist * prevT;
127 Vector2f truePrev = prev + prevDist * prevT;
128 Vector2f trueNext = next + nextDist * nextT;
131 arcTo(trueNext, center, clockwise);
232 float radius = (end - center).magnitude();
233 float angle = (
beziers.back().start - center).signedAngle(end - center);
235 if (angle > 0) numsegments =
static_cast<int>(ceil(angle / (0.5f *
PI)));
236 else numsegments =
static_cast<int>(ceil((angle + 2.0f *
PI) / (0.5f *
PI)));
238 if (clockwise) numsegments = std::max(4 - numsegments, 1);
241 float a = angle * (1.0f /
static_cast<float>(numsegments));
242 if (clockwise) a += 2.0f *
PI;
246 float bezierArcApprox = (4.0f / 3.0f) * tan(
PI / (2.0f * (
static_cast<float>(numsegments) * 2.0f *
PI / angle)));
249 for (
size_t i = 0; i < static_cast<size_t>(numsegments); i++) {
256 (c * (last.
start.
x - center.
x)) - (s * (last.
start.
y - center.
y)),