65 if (a == 0 && b == 0) {
67 THROW_LOGICALERROR(
"the passed coefficients give the empty set");
122 std::vector<Coord>
c(3);
132 std::vector<Coord>
result;
134 if (std::isfinite(r)) {
142 assert(d ==
X || d ==
Y);
156 for (
unsigned i = 0; i < 2; ++i) {
159 if (v[d] != 0)
continue;
227 if (v[
X] == 0 && v[
Y] == 0) {
232 if (fabs(v[
X]) > fabs(v[
Y])) {
255 std::vector<ShapeIntersection>
result;
260 if (cp == 0)
return result;
265 result.emplace_back(*
this, other, t1, t2);
290 std::vector<ShapeIntersection>::reverse_iterator i = xs.rbegin(), last = xs.rend();
293 xs.erase((++i).base());
303 std::vector<ShapeIntersection>::reverse_iterator i = xs.rbegin(), last = xs.rend();
305 if ((a && i->first < 0) || (b && i->second < 0)) {
306 xs.erase((++i).base());
323 Point odiff = o2 - o1;
327 c.tb =
cross(odiff, v1) / cp;
341 if (crossing->ta < 0) {
345 swap(crossing->ta, crossing->tb);
351 THROW_INFINITESOLUTIONS();
371 if ( crossing->getTime(0) < 0
372 || crossing->getTime(0) > 1 )
377 swap((*crossing).ta, (*crossing).tb);
383 THROW_INFINITESOLUTIONS();
404 if ( (crossing->getTime(0) < 0)
405 || (crossing->getTime(0) > 1)
406 || (crossing->getTime(1) < 0) )
411 swap(crossing->ta, crossing->tb);
418 bool eqvs = (
dot(direction, r2.
vector()) > 0);
420 crossing->ta = crossing->tb = 0;
432 THROW_INFINITESOLUTIONS();
435 THROW_INFINITESOLUTIONS();
453 THROW_INFINITESOLUTIONS();
466 if ( crossing->ta < 0
467 || crossing->tb < 0 )
483 crossing->ta = crossing->tb = 0;
488 THROW_INFINITESOLUTIONS();
511 if ( crossing->getTime(0) < 0
512 || crossing->getTime(0) > 1
513 || crossing->getTime(1) < 0
514 || crossing->getTime(1) > 1 )
525 bool eqvs = (
dot(direction1, direction2) > 0);
530 crossing->ta = crossing->tb = 0;
541 THROW_INFINITESOLUTIONS();
548 crossing->ta = crossing->tb = 1;
559 THROW_INFINITESOLUTIONS();
582 THROW_RANGEERROR(
"passed lines are parallel");
588 : l2.
pointAt(crossing->tb - 1);
3x3 matrix representing an affine transformation.
Point finalPoint() const override
Retrieve the end of the curve.
Point initialPoint() const override
Retrieve the start of the curve.
constexpr bool contains(C val) const
Check whether the interval includes this number.
CPoint clamp(CPoint const &p) const
Clamp point to the rectangle.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
CPoint max() const
Get the corner of the rectangle with largest coordinate values.
Range of real numbers that is never empty.
Infinite line on a plane.
void setCoefficients(double a, double b, double c)
Set the coefficients of the line equation.
std::vector< double > coefficients() const
Get the coefficients of the line equation as a vector.
Coord timeAt(Point const &p) const
Get a time value corresponding to a point.
Coord root(Coord v, Dim2 d) const
Point origin() const
Get the line's origin point.
Point vector() const
Get the line's raw direction vector.
std::vector< Coord > roots(Coord v, Dim2 d) const
Find intersection with an axis-aligned line.
std::optional< LineSegment > clip(Rect const &r) const
Return the portion of the line that is inside the given rectangle.
Affine transformTo(Line const &other) const
Create a transformation that maps one line to another.
Point initialPoint() const
std::vector< ShapeIntersection > intersect(Line const &other) const
Point pointAt(Coord t) const
Range of real numbers that can be empty.
Two-dimensional point that doubles as a vector.
Coord length() const
Compute the distance from origin.
constexpr Point cw() const
Return a point like this point but rotated +90 degrees.
Straight ray from a specific point to infinity.
Axis aligned, non-empty rectangle.
Rotation around the origin.
BezierCurveN< 1 > LineSegment
Line segment.
Dim2
2D axis enumeration (X or Y).
constexpr Dim2 other_dimension(Dim2 d)
Get the other (perpendicular) dimension.
double Coord
Floating point type used to store coordinates.
Low level math functions and compatibility wrappers.
OptCrossing intersection_impl(Ray const &r1, Line const &l2, unsigned int i)
Various utility functions.
Coord length(LineSegment const &seg)
void filter_ray_intersections(std::vector< ShapeIntersection > &xs, bool a=false, bool b=true)
MultiDegree< n > max(MultiDegree< n > const &p, MultiDegree< n > const &q)
Returns the maximal degree appearing in the two arguments for each variables.
Angle distance(Angle const &a, Angle const &b)
std::optional< Crossing > OptCrossing
OptCrossing intersection(Ray const &r1, Line const &l2)
double angle_between(Line const &l1, Line const &l2)
bool contains(Path const &p, Point const &i, bool evenodd=true)
void filter_line_segment_intersections(std::vector< ShapeIntersection > &xs, bool a=false, bool b=true)
Removes intersections outside of the unit interval.
Piecewise< SBasis > cross(Piecewise< D2< SBasis > > const &a, Piecewise< D2< SBasis > > const &b)
Piecewise< SBasis > min(SBasis const &f, SBasis const &g)
Return the more negative of the two functions pointwise.
Line make_angle_bisector_line(Point const &A, Point const &O, Point const &B)
T dot(D2< T > const &a, D2< T > const &b)
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)