diff --git a/DataStructures/Coordinate.cpp b/DataStructures/Coordinate.cpp index 3ee0176a3..8383b6abc 100644 --- a/DataStructures/Coordinate.cpp +++ b/DataStructures/Coordinate.cpp @@ -329,3 +329,92 @@ void FixedPointCoordinate::Output(std::ostream &out) const { out << "(" << lat / COORDINATE_PRECISION << "," << lon / COORDINATE_PRECISION << ")"; } + + +// double PointSegmentDistanceSquared( double px, double py, +// double p1x, double p1y, +// double p2x, double p2y, +// double& t, +// double& qx, double& qy) +// { +// static const double kMinSegmentLenSquared = 0.00000001; // adjust to suit. If you use float, you'll probably want something like 0.000001f +// static const double kEpsilon = 1.0E-14; // adjust to suit. If you use floats, you'll probably want something like 1E-7f +// double dx = p2x - p1x; +// double dy = p2y - p1y; +// double dp1x = px - p1x; +// double dp1y = py - p1y; +// const double segLenSquared = (dx * dx) + (dy * dy); +// if (segLenSquared >= -kMinSegmentLenSquared && segLenSquared <= kMinSegmentLenSquared) +// { +// // segment is a point. +// qx = p1x; +// qy = p1y; +// t = 0.0; +// return ((dp1x * dp1x) + (dp1y * dp1y)); +// } +// else +// { +// // Project a line from p to the segment [p1,p2]. By considering the line +// // extending the segment, parameterized as p1 + (t * (p2 - p1)), +// // we find projection of point p onto the line. +// // It falls where t = [(p - p1) . (p2 - p1)] / |p2 - p1|^2 +// t = ((dp1x * dx) + (dp1y * dy)) / segLenSquared; +// if (t < kEpsilon) +// { +// // intersects at or to the "left" of first segment vertex (p1x, p1y). 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. +// qx = p1x; +// qy = p1y; +// // Note: If you wanted the ACTUAL intersection point of where the projected lines would intersect if +// // we were doing PointLineDistanceSquared, then qx would be (p1x + (t * dx)) and qy would be (p1y + (t * dy)). +// } +// else if (t > (1.0 - kEpsilon)) +// { +// // intersects at or to the "right" of second segment vertex (p2x, p2y). 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. +// qx = p2x; +// qy = p2y; +// // Note: If you wanted the ACTUAL intersection point of where the projected lines would intersect if +// // we were doing PointLineDistanceSquared, then qx would be (p1x + (t * dx)) and qy would be (p1y + (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. +// qx = p1x + (t * dx); +// qy = p1y + (t * dy); +// } +// // return the squared distance from p to the intersection point. Note that we return the squared distance +// // as an optimization because many times you just need to compare relative distances and the squared values +// // works fine for that. If you want the ACTUAL distance, just take the square root of this value. +// double dpqx = px - qx; +// double dpqy = py - qy; +// return ((dpqx * dpqx) + (dpqy * dpqy)); +// } +// } + +// public float DistanceOfPointToLine2(PointF p1, PointF p2, PointF p) +// { +// // (y1-y2)x + (x2-x1)y + (x1y2-x2y1) +// //d(P,L) = -------------------------------- +// // sqrt( (x2-x1)pow2 + (y2-y1)pow2 ) + +// double ch = (p1.Y - p2.Y) * p.X + (p2.X - p1.X) * p.Y + (p1.X * p2.Y - p2.X * p1.Y); +// double del = Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2)); +// double d = ch / del; +// return (float)d; +// } diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index 60d286355..5177ebed0 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -51,12 +51,11 @@ struct DescriptorConfig template class BaseDescriptor { public: - BaseDescriptor() {} //TODO: initialize facade here. + BaseDescriptor() {} // Maybe someone can explain the pure virtual destructor thing to me (dennis) virtual ~BaseDescriptor() {} virtual void Run(const RawRouteData &raw_route, const PhantomNodes &phantom_nodes, - DataFacadeT *facade, http::Reply &reply) = 0; virtual void SetConfig(const DescriptorConfig &config) = 0; }; diff --git a/Descriptors/GPXDescriptor.h b/Descriptors/GPXDescriptor.h index 027cb8313..020e0a3ca 100644 --- a/Descriptors/GPXDescriptor.h +++ b/Descriptors/GPXDescriptor.h @@ -35,6 +35,7 @@ template class GPXDescriptor : public BaseDescriptor & output) { @@ -56,12 +57,13 @@ template class GPXDescriptor : public BaseDescriptor" diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 6127e5a82..46b85aba2 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -72,7 +72,7 @@ template class JSONDescriptor : public BaseDescriptor class JSONDescriptor : public BaseDescriptor class JSONDescriptor : public BaseDescriptor class JSONDescriptor : public BaseDescriptor class JSONDescriptor : public BaseDescriptor &route_segments_list) { // Segment information has following format: diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index d8ac8b448..89bbb2e44 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -160,13 +160,13 @@ template class ViaRoutePlugin : public BasePlugin // descriptor = std::make_shared>(); // break; case 1: - descriptor = std::make_shared>(); + descriptor = std::make_shared>(facade); break; // case 2: // descriptor = std::make_shared>(); // break; default: - descriptor = std::make_shared>(); + descriptor = std::make_shared>(facade); break; } @@ -175,7 +175,7 @@ template class ViaRoutePlugin : public BasePlugin phantom_nodes.target_phantom = raw_route.segment_end_coordinates.back().target_phantom; descriptor->SetConfig(descriptor_config); TIMER_START(descriptor); - descriptor->Run(raw_route, phantom_nodes, facade, reply); + descriptor->Run(raw_route, phantom_nodes, reply); TIMER_STOP(descriptor); SimpleLogger().Write() << "descriptor took " << TIMER_MSEC(descriptor) << "ms"; }