7#include "color/sdf_r8.hpp"
8#include "pixel_map.hpp"
9#include "alignment.hpp"
12#include "required.hpp"
13#include "geometry/vector.hpp"
14#include "geometry/point.hpp"
15#include "geometry/transform.hpp"
24enum class LineJoinStyle { Bevel, Miter, Rounded };
30 enum class Type : uint8_t { None, Linear, Quadratic, Cubic };
31 enum class Color : uint8_t { Yellow, Magenta, Cyan, White };
75 Color
color = Color::White) noexcept :
80 [[nodiscard]]
bool has_red() const noexcept
82 return color != Color::Cyan;
85 [[nodiscard]]
bool has_green() const noexcept
87 return color != Color::Magenta;
90 [[nodiscard]]
bool has_blue() const noexcept
92 return color != Color::Yellow;
105 case Type::Linear:
return bezierPointAt(
P1,
P2, t);
106 case Type::Quadratic:
return bezierPointAt(
P1,
C1,
P2, t);
107 case Type::Cubic:
return bezierPointAt(
P1,
C1,
C2,
P2, t);
108 default: tt_no_default();
122 case Type::Linear:
return bezierTangentAt(
P1,
P2, t);
123 case Type::Quadratic:
return bezierTangentAt(
P1,
C1,
P2, t);
124 case Type::Cubic:
return bezierTangentAt(
P1,
C1,
C2,
P2, t);
125 default: tt_no_default();
136 case Type::Linear:
return bezierFindX(
P1,
P2, y);
137 case Type::Quadratic:
return bezierFindX(
P1,
C1,
P2, y);
138 case Type::Cubic:
return bezierFindX(
P1,
C1,
C2,
P2, y);
139 default: tt_no_default();
146 case Type::Linear:
return bezierFindTForNormalsIntersectingPoint(
P1,
P2, P);
147 case Type::Quadratic:
return bezierFindTForNormalsIntersectingPoint(
P1,
C1,
P2, P);
148 case Type::Cubic: tt_no_default();
149 default: tt_no_default();
159 auto min_normal =
vector2{0.0f, 1.0f};
161 ttlet ts = solveTForNormalsIntersectingPoint(P);
163 t = std::clamp(t, 0.0f, 1.0f);
166 ttlet square_distance = squared_hypot(normal);
167 if (square_distance < min_square_distance) {
168 min_square_distance = square_distance;
175 ttlet distance =
std::sqrt(min_square_distance);
176 ttlet sdistance = cross(tangent, min_normal) < 0.0 ? distance : -distance;
196 return {{
P1, outerA.pointAt(t), innerA.pointAt(t), newPoint}, {newPoint, innerB.pointAt(t), outerB.pointAt(t),
P2}};
211 return {{
P1, outerA.pointAt(t), newPoint}, {newPoint, outerB.pointAt(t),
P2}};
223 return {{
P1, newPoint}, {newPoint,
P2}};
237 default: tt_no_default();
247 if (
flatness() >= minimumFlatness) {
250 ttlet[a, b] =
split(0.5f);
251 a.subdivideUntilFlat_impl(r, minimumFlatness);
252 b.subdivideUntilFlat_impl(r, minimumFlatness);
273 case Type::Linear:
return bezierFlatness(
P1,
P2);
274 case Type::Quadratic:
return bezierFlatness(
P1,
C1,
P2);
275 case Type::Cubic:
return bezierFlatness(
P1,
C1,
C2,
P2);
276 default: tt_no_default();
286 auto [newP1, newP2] = parallelLine(
P1,
P2, offset);
287 return {newP1, newP2};
292 if (lhs.type != rhs.type) {
296 case bezier_curve::Type::Linear:
return (lhs.P1 == rhs.P1) && (lhs.P2 == rhs.P2);
297 case bezier_curve::Type::Quadratic:
return (lhs.P1 == rhs.P1) && (lhs.C1 == rhs.C1) && (lhs.P2 == rhs.P2);
298 case bezier_curve::Type::Cubic:
299 return (lhs.P1 == rhs.P1) && (lhs.C1 == rhs.C1) && (lhs.C2 == rhs.C2) && (lhs.P2 == rhs.P2);
300 default: tt_no_default();
304 [[nodiscard]]
friend bezier_curve operator*(geo::transformer
auto const &lhs, bezier_curve
const &rhs)
noexcept
306 return {rhs.type, lhs * rhs.P1, lhs * rhs.C1, lhs * rhs.C2, lhs * rhs.P2};
313 return {rhs.type, rhs.P2, rhs.C2, rhs.C1, rhs.P1};
324makeContourFromPoints(std::vector<bezier_point>::const_iterator first, std::vector<bezier_point>::const_iterator last)
noexcept;
347 LineJoinStyle lineJoinStyle,
348 float tolerance)
noexcept;
Definition bezier_curve.hpp:29
point2 C2
Control point.
Definition bezier_curve.hpp:37
vector2 tangentAt(float const t) const noexcept
Definition bezier_curve.hpp:119
float flatness() const noexcept
Definition bezier_curve.hpp:270
results< float, 3 > solveXByY(float const y) const noexcept
Definition bezier_curve.hpp:133
std::vector< bezier_curve > subdivideUntilFlat(float const tolerance) const noexcept
Definition bezier_curve.hpp:260
bezier_curve(point2 const P1, point2 const C1, point2 const C2, point2 const P2, Color color=Color::White) noexcept
Definition bezier_curve.hpp:62
std::pair< bezier_curve, bezier_curve > cubicSplit(float const t) const noexcept
Definition bezier_curve.hpp:185
std::pair< bezier_curve, bezier_curve > split(float const t) const noexcept
Definition bezier_curve.hpp:231
friend bezier_curve operator~(bezier_curve const &rhs) noexcept
Definition bezier_curve.hpp:311
bezier_curve(Type const type, point2 const P1, point2 const C1, point2 const C2, point2 const P2, Color color=Color::White) noexcept
Definition bezier_curve.hpp:69
point2 pointAt(float const t) const noexcept
Definition bezier_curve.hpp:102
bezier_curve(point2 const P1, point2 const C1, point2 const P2, Color color=Color::White) noexcept
Definition bezier_curve.hpp:55
std::pair< bezier_curve, bezier_curve > linearSplit(float const t) const noexcept
Definition bezier_curve.hpp:219
void subdivideUntilFlat_impl(std::vector< bezier_curve > &r, float const minimumFlatness) const noexcept
Definition bezier_curve.hpp:245
point2 P1
First point.
Definition bezier_curve.hpp:35
bezier_curve toParallelLine(float const offset) const noexcept
Definition bezier_curve.hpp:284
point2 P2
Last point.
Definition bezier_curve.hpp:38
float sdf_distance(point2 P) const noexcept
Find the distance from the point to the curve.
Definition bezier_curve.hpp:155
std::pair< bezier_curve, bezier_curve > quadraticSplit(float const t) const noexcept
Definition bezier_curve.hpp:204
point2 C1
Control point.
Definition bezier_curve.hpp:36
This is a RGBA floating point color.
Definition color.hpp:39
Definition polynomial.hpp:14