| 99 | } |
| 100 | |
| 101 | inline double PointToLineDistance (const double px, const double py, |
| 102 | const double x0, const double y0, |
| 103 | const double x1, const double y1) { |
| 104 | double A = px - x0; |
| 105 | double B = py - y0; |
| 106 | double C = x1 - x0; |
| 107 | double D = y1 - y0; |
| 108 | |
| 109 | double dot = A * C + B * D; |
| 110 | double len_sq = C * C + D * D; |
| 111 | double param = dot / len_sq; |
| 112 | |
| 113 | double xx, yy; |
| 114 | |
| 115 | if (param < 0) |
| 116 | { |
| 117 | xx = x0; |
| 118 | yy = y0; |
| 119 | } |
| 120 | else if (param > 1) |
| 121 | { |
| 122 | xx = x1; |
| 123 | yy = y1; |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | xx = x0 + param * C; |
| 128 | yy = y0 + param * D; |
| 129 | } |
| 130 | |
| 131 | return PointDistance(px, py, xx, yy); |
| 132 | } |
| 133 | |
| 134 | inline double PointToLineDistance (const geometry::Point2D &point, |
| 135 | const geometry::LineSegment2D &line) { |
no test coverage detected