7#include "color/sdf_r8.hpp"
8#include "pixel_map.hpp"
9#include "alignment.hpp"
12#include "required.hpp"
13#include "numeric_array.hpp"
14#include "geometry/transform.hpp"
23enum class LineJoinStyle { Bevel, Miter, Rounded };
29 enum class Type : uint8_t { None, Linear, Quadratic, Cubic };
30 enum class Color : uint8_t { Yellow, Magenta, Cyan, White };
74 Color
color = Color::White) noexcept :
79 [[nodiscard]]
bool has_red() const noexcept
81 return color != Color::Cyan;
84 [[nodiscard]]
bool has_green() const noexcept
86 return color != Color::Magenta;
89 [[nodiscard]]
bool has_blue() const noexcept
91 return color != Color::Yellow;
104 case Type::Linear:
return bezierPointAt(
P1,
P2, t);
105 case Type::Quadratic:
return bezierPointAt(
P1,
C1,
P2, t);
106 case Type::Cubic:
return bezierPointAt(
P1,
C1,
C2,
P2, t);
107 default: tt_no_default();
121 case Type::Linear:
return bezierTangentAt(
P1,
P2, t);
122 case Type::Quadratic:
return bezierTangentAt(
P1,
C1,
P2, t);
123 case Type::Cubic:
return bezierTangentAt(
P1,
C1,
C2,
P2, t);
124 default: tt_no_default();
135 case Type::Linear:
return bezierFindX(
P1,
P2, y);
136 case Type::Quadratic:
return bezierFindX(
P1,
C1,
P2, y);
137 case Type::Cubic:
return bezierFindX(
P1,
C1,
C2,
P2, y);
138 default: tt_no_default();
145 case Type::Linear:
return bezierFindTForNormalsIntersectingPoint(
P1,
P2, P);
146 case Type::Quadratic:
return bezierFindTForNormalsIntersectingPoint(
P1,
C1,
P2, P);
147 case Type::Cubic: tt_no_default();
148 default: tt_no_default();
158 auto min_normal =
vector2{0.0f, 1.0f};
160 ttlet ts = solveTForNormalsIntersectingPoint(P);
162 t = std::clamp(t, 0.0f, 1.0f);
165 ttlet square_distance = squared_hypot(normal);
166 if (square_distance < min_square_distance) {
167 min_square_distance = square_distance;
174 ttlet distance =
std::sqrt(min_square_distance);
175 ttlet sdistance = cross(tangent, min_normal) < 0.0 ? distance : -distance;
195 return {{
P1, outerA.pointAt(t), innerA.pointAt(t), newPoint}, {newPoint, innerB.pointAt(t), outerB.pointAt(t),
P2}};
210 return {{
P1, outerA.pointAt(t), newPoint}, {newPoint, outerB.pointAt(t),
P2}};
222 return {{
P1, newPoint}, {newPoint,
P2}};
236 default: tt_no_default();
246 if (
flatness() >= minimumFlatness) {
249 ttlet[a, b] =
split(0.5f);
250 a.subdivideUntilFlat_impl(r, minimumFlatness);
251 b.subdivideUntilFlat_impl(r, minimumFlatness);
272 case Type::Linear:
return bezierFlatness(
P1,
P2);
273 case Type::Quadratic:
return bezierFlatness(
P1,
C1,
P2);
274 case Type::Cubic:
return bezierFlatness(
P1,
C1,
C2,
P2);
275 default: tt_no_default();
285 auto [newP1, newP2] = parrallelLine(
P1,
P2, offset);
286 return {newP1, newP2};
291 if (lhs.type != rhs.type) {
295 case bezier_curve::Type::Linear:
return (lhs.P1 == rhs.P1) && (lhs.P2 == rhs.P2);
296 case bezier_curve::Type::Quadratic:
return (lhs.P1 == rhs.P1) && (lhs.C1 == rhs.C1) && (lhs.P2 == rhs.P2);
297 case bezier_curve::Type::Cubic:
298 return (lhs.P1 == rhs.P1) && (lhs.C1 == rhs.C1) && (lhs.C2 == rhs.C2) && (lhs.P2 == rhs.P2);
299 default: tt_no_default();
303 [[nodiscard]]
friend bezier_curve operator*(geo::transformer<2>
auto const &lhs, bezier_curve
const &rhs)
noexcept
305 return {rhs.type, lhs * rhs.P1, lhs * rhs.C1, lhs * rhs.C2, lhs * rhs.P2};
312 return {rhs.type, rhs.P2, rhs.C2, rhs.C1, rhs.P1};
323makeContourFromPoints(std::vector<bezier_point>::const_iterator first, std::vector<bezier_point>::const_iterator last)
noexcept;
346 LineJoinStyle lineJoinStyle,
347 float tolerance)
noexcept;
Definition bezier_curve.hpp:28
point2 C2
Control point.
Definition bezier_curve.hpp:36
vector2 tangentAt(float const t) const noexcept
Definition bezier_curve.hpp:118
float flatness() const noexcept
Definition bezier_curve.hpp:269
results< float, 3 > solveXByY(float const y) const noexcept
Definition bezier_curve.hpp:132
std::vector< bezier_curve > subdivideUntilFlat(float const tolerance) const noexcept
Definition bezier_curve.hpp:259
bezier_curve(point2 const P1, point2 const C1, point2 const C2, point2 const P2, Color color=Color::White) noexcept
Definition bezier_curve.hpp:61
std::pair< bezier_curve, bezier_curve > cubicSplit(float const t) const noexcept
Definition bezier_curve.hpp:184
std::pair< bezier_curve, bezier_curve > split(float const t) const noexcept
Definition bezier_curve.hpp:230
friend bezier_curve operator~(bezier_curve const &rhs) noexcept
Definition bezier_curve.hpp:310
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:68
point2 pointAt(float const t) const noexcept
Definition bezier_curve.hpp:101
bezier_curve(point2 const P1, point2 const C1, point2 const P2, Color color=Color::White) noexcept
Definition bezier_curve.hpp:54
bezier_curve toParrallelLine(float const offset) const noexcept
Definition bezier_curve.hpp:283
std::pair< bezier_curve, bezier_curve > linearSplit(float const t) const noexcept
Definition bezier_curve.hpp:218
void subdivideUntilFlat_impl(std::vector< bezier_curve > &r, float const minimumFlatness) const noexcept
Definition bezier_curve.hpp:244
point2 P1
First point.
Definition bezier_curve.hpp:34
point2 P2
Last point.
Definition bezier_curve.hpp:37
float sdf_distance(point2 P) const noexcept
Find the distance from the point to the curve.
Definition bezier_curve.hpp:154
std::pair< bezier_curve, bezier_curve > quadraticSplit(float const t) const noexcept
Definition bezier_curve.hpp:203
point2 C1
Control point.
Definition bezier_curve.hpp:35
This is a RGBA floating point color.
Definition color.hpp:39
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector.hpp:20
Definition polynomial.hpp:14