void R2Vector:: Mirror(const R2Line& line) { // Mirror vector across line double d = Dot(line.Normal()); *this += line.Normal() * (-2.0 * d); }
void R2Point:: Mirror(const R2Line& line) { // Mirror point across line double d = R2SignedDistance(*this, line); *this += line.Normal() * (-2.0 * d); }
void R2Line:: Project(const R2Line& line) { // Project line onto another line *this = line; if (Vector().Dot(line.Vector()) < 0.0) Flip(); }
RNLength R2SignedDistance(const R2Line& line, const R2Box& box) { // Return signed distance from line to box RNQuadrant quadrant = line.Normal().Quadrant(); RNScalar d1 = R2SignedDistance(line, box.Corner(~quadrant & 0x3)); if (RNIsPositiveOrZero(d1)) return d1; RNScalar d2 = R2SignedDistance(line, box.Corner(quadrant)); if (RNIsNegative(d2)) return d2; else return 0.0; }
RNLength R2SignedDistance(const R2Line& line1, const R2Line& line2) { // Return signed distance from line to line RNScalar dot = line1.Vector().Dot(line2.Vector()); if (RNIsEqual(dot, 1.0)) return (line1.C() - line2.C()); else if (RNIsEqual(dot, -1.0)) return (line1.C() + line2.C()); else return 0.0; }
RNLength R2Distance(const R2Point& point, const R2Line& line) { // Return distance from point to line RNLength d = point.X() * line.A() + point.Y() * line.B() + line.C(); return (d < 0.0) ? -d : d; }
RNLength R2SignedDistance(const R2Line& line, const R2Point& point) { // Return signed distance from point to line return (point.X()*line.A() + point.Y()*line.B() + line.C()); }