+ if (t < kEpsilon) {
+ // intersects at or to the "left" of first segment vertex (p1.x, p1.y). If t is approximately 0.0, then
+ // intersection is at p1. If t is less than that, then there is no intersection (i.e. p is not within
+ // the 'bounds' of the segment)
+ if (t > -kEpsilon) {
+ // intersects at 1st segment vertex
+ t = 0.0;
+ }
+ // set our 'intersection' point to p1.
+ at = p1;
+ // Note: If you wanted the ACTUAL intersection point of where the projected lines would intersect if
+ // we were doing PointLineDistanceSquared, then qx would be (p1.x + (t * dx)) and qy would be (p1.y + (t * dy)).
+
+ } else if (t > (1.0 - kEpsilon)) {
+ // intersects at or to the "right" of second segment vertex (p2.x, p2.y). If t is approximately 1.0, then
+ // intersection is at p2. If t is greater than that, then there is no intersection (i.e. p is not within
+ // the 'bounds' of the segment)
+ if (t < (1.0 + kEpsilon)) {
+ // intersects at 2nd segment vertex
+ t = 1.0;
+ }
+ // set our 'intersection' point to p2.
+ at = p2;
+ // Note: If you wanted the ACTUAL intersection point of where the projected lines would intersect if
+ // we were doing PointLineDistanceSquared, then qx would be (p1.x + (t * dx)) and qy would be (p1.y + (t * dy)).
+ } else {
+ // The projection of the point to the point on the segment that is perpendicular succeeded and the point
+ // is 'within' the bounds of the segment. Set the intersection point as that projected point.
+ at = Duple (p1.x + (t * dx), p1.y + (t * dy));
+ }