#ifndef GEOMETRY_2D_H_ #define GEOMETRY_2D_H_ #include #include // squared euclidean distance double dist2(const sla::Vec2d &a, const sla::Vec2d &b); // Calculates the closest point to x on a line segmente a-->b // if the distance to closest point is smaller than d2, both // d2 and cp will be overwritten bool closer_on_line(const sla::Vec2d &x, const sla::Vec2d &a, const sla::Vec2d &b, double &d2, sla::Vec2d &cp); // is the circle centered at b with radius r // fully within the rectangle centered at bc, with radius br? bool circle_within_bounds(const sla::Vec2d &b, double r, const sla::Vec2d &bc, double br); // is the circle centered at b with radius r // fully within the rectangle centered from min to max? bool circle_within_bounds(const sla::Vec2d &b, double r, const sla::Vec2d &min, const sla::Vec2d &max); // does the circle centered at b, with radius r, // intersect the rectangle centered at bc, with radius br? bool bounds_overlap_circle(const sla::Vec2d &b, double r, const sla::Vec2d &bc, double br); // Which of the four edges is point P outside of? long bevel_1d(const sla::Vec2d &p); // Which of the four edge lines is point P outside of? long bevel_2d(const sla::Vec2d &p); // 2D linear interpolation sla::Vec2d lerp(double t, const sla::Vec2d &a, const sla::Vec2d &b); // Test the point "alpha" of the way from P1 to P2 // See if it is on a edge of the rectangle // Consider only faces in "mask" bool point_on_edge(const sla::Vec2d &p1, const sla::Vec2d &p2, double alpha, long mask); // Compute intersection of P1 --> P2 line segment with edge lines // Then test intersection point to see if it is on cube face // Consider only face planes in "outcode_diff" // Note: Zero bits in "outcode_diff" means edge is outside of bool segment_on_edge(const sla::Vec2d &p1, const sla::Vec2d &p2, long outcode_diff); // true if line t1,t2 is outside a rectangle // centered at c with length of a side s, // false if the line intersects rectangle bool line_outside_of_rect(const sla::Vec2d &c, double s, const sla::Vec2d &t1, const sla::Vec2d &t2); // true if line p is outside a rectangle // centered at c with length of a side s, // false if the line intersects rectangle bool point_outside_of_rect(const sla::Vec2d &c, double s, const sla::Vec2d &p); #endif /*GEOMETRY_2D_H_*/