/* Brian O'Connor * * line.h: structures and functions for working with lines * * IMPORTANT: all Points are assumed to be homogenous in this module. */ #include "input.h" #ifndef LINE_H #define LINE_H class Obstacle; class Cell; class Line { public: Line(void) {}; Line(Point *p1, Point *p2); Point *A; /* endpoints */ Point *B; double length; /* used in computing intersections */ Obstacle *ob; double a; /* line coordinates: a + bx + cy = 0 */ double b; double c; }; /* functions to encapsulate floating pt error */ int FloatCompare(double m, double n); int FloatEqual(double m, double n); /* create a new line from 2 pts */ Line *PointsToLine(Point *p1, Point *p2); Point *NewPoint(void); int PointCompare(Point *p1, Point *p2); int PointEqual(Point *p1, Point *p2); /* return TRUE if segments intersect w. intersection point returned in result */ int SegmentIntersection(Line *l1, Line *l2, Point *result); /* return TRUE if segment s intersects line l & also return int. point */ int LineSegIntersection(Line *l, Line *s, Point *result); /* return Point where the given lines intersect in result */ void LineIntersection(Line *l1, Line *l2, Point *result); /* return Point where the given lines intersect in result, and return the distance from l1->A endpoint to result (positive direction is direction from A to B). */ void LineIntersectionDistance(Line *l1, Line *l2, Point *result, double *dist); /* returns the Distance from p1 to p2 */ double LineDistance(Point *p1, Point *p2); /* returns TRUE if the given point is on the line segment, and false * if not. */ int PointOnSegment(Line *l, Point *p); /* returns the angle made by the two lines. */ double LineAngle(Line *l1, Line *l2); /* returns TRUE if the line segments overlap, and returns the endpoints * of the combined segment in pmin, pmax */ int LinesOverlap(Line *l1, Line *l2, Point **pmin, Point **pmax); /* ASSERTs if the line is not valid (endpoints don't satisfy line eq) * and optionally can print out the Line structure. */ void VerifyLine(Line *l); void DotProductTest(void); #endif