44 #ifdef CHECK_MEMORY_LEAKS
46 #endif // CHECK_MEMORY_LEAKS
58 const SUMOReal eps = std::numeric_limits<SUMOReal>::epsilon();
59 const double denominator = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
60 const double numera = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
61 const double numerb = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
63 if (fabs(numera) < eps && fabs(numerb) < eps && fabs(denominator) < eps) {
70 a1 = x1 < x2 ? x1 : x2;
71 a2 = x1 < x2 ? x2 : x1;
72 a3 = x3 < x4 ? x3 : x4;
73 a4 = x3 < x4 ? x4 : x3;
75 a1 = y1 < y2 ? y1 : y2;
76 a2 = y1 < y2 ? y2 : y1;
77 a3 = y3 < y4 ? y3 : y4;
78 a4 = y3 < y4 ? y4 : y3;
80 if (a1 <= a3 && a3 <= a2) {
87 if (a3 <= a1 && a1 <= a4) {
97 *mu = (a - x1) / (x2 - x1);
99 *y = y1 + (*mu) * (y2 - y1);
103 *mu = (a - y1) / (y2 - y1);
111 if (fabs(denominator) < eps) {
115 const double mua = numera / denominator;
116 const double mub = numerb / denominator;
117 if (mua < 0 || mua > 1 || mub < 0 || mub > 1) {
121 *x = x1 + mua * (x2 - x1);
122 *y = y1 + mua * (y2 - y1);
135 p21.
x(), p21.
y(), p22.
x(), p22.
y(), 0, 0, 0);
146 p21.
x(), p21.
y(), p22.
x(), p22.
y(), &x, &y, &m)) {
148 return Position(x, y, p11.
z() + m * (p12.
z() - p11.
z()));
162 SUMOReal dtheta = atan2(y2, x2) - atan2(y1, x1);
177 return p1 + (p2 - p1) * factor;
185 return p1 - (p2 - p1) * factor;
193 return p2 - (p1 - p2) * factor;
200 const Position& Point,
bool perpendicular) {
202 if (lineLength2D == 0.0f) {
207 const SUMOReal u = (((Point.
x() - LineStart.
x()) * (LineEnd.
x() - LineStart.
x())) +
208 ((Point.
y() - LineStart.
y()) * (LineEnd.
y() - LineStart.
y()))
209 ) / (lineLength2D * lineLength2D);
210 if (u < 0.0f || u > 1.0f) {
219 return u * lineLength2D;
229 if (lineLengthSquared == 0.0f) {
234 SUMOReal u = (((point.
x() - lineStart.
x()) * (lineEnd.
x() - lineStart.
x())) +
235 ((point.
y() - lineStart.
y()) * (lineEnd.
y() - lineStart.
y()))
236 ) / lineLengthSquared;
237 if (u < 0.0f || u > 1.0f) {
241 lineStart.
x() + u * (lineEnd.
x() - lineStart.
x()),
242 lineStart.
y() + u * (lineEnd.
y() - lineStart.
y()));
254 outIntersection.
set(
Line(lineStart, lineEnd).getPositionAtDistance(length));
265 const SUMOReal dx = lineBeg.
x() - lineEnd.
x();
266 const SUMOReal dy = lineBeg.
y() - lineEnd.
y();
267 const SUMOReal length = sqrt(dx * dx + dy * dy);
269 p.
add(dy * amount / length, -dx * amount / length);
301 std::pair<SUMOReal, SUMOReal>
309 std::pair<SUMOReal, SUMOReal>
316 return std::pair<SUMOReal, SUMOReal>
317 ((beg.
y() - end.
y()) * wanted_offset / length, (end.
x() - beg.
x()) * wanted_offset / length);