| 171 | } |
| 172 | |
| 173 | SignedDistance LinearSegment::signedDistance(Point2 origin, double ¶m) const { |
| 174 | Vector2 aq = origin-p[0]; |
| 175 | Vector2 ab = p[1]-p[0]; |
| 176 | param = dotProduct(aq, ab)/dotProduct(ab, ab); |
| 177 | Vector2 eq = p[param > .5]-origin; |
| 178 | double endpointDistance = eq.length(); |
| 179 | if (param > 0 && param < 1) { |
| 180 | double orthoDistance = dotProduct(ab.getOrthonormal(false), aq); |
| 181 | if (fabs(orthoDistance) < endpointDistance) |
| 182 | return SignedDistance(orthoDistance, 0); |
| 183 | } |
| 184 | return SignedDistance(nonZeroSign(crossProduct(aq, ab))*endpointDistance, fabs(dotProduct(ab.normalize(), eq.normalize()))); |
| 185 | } |
| 186 | |
| 187 | SignedDistance QuadraticSegment::signedDistance(Point2 origin, double ¶m) const { |
| 188 | Vector2 qa = p[0]-origin; |
no test coverage detected