const TrackType::Endpoint &TrackType::get_endpoint(unsigned i) const
{
if(i>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("TrackType::get_endpoint");
return endpoints[i];
}
TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
{
if(epi>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("TrackType::get_point");
const TrackPart *part = 0;
unsigned part_ep = 0;
}
if(!part)
- throw Exception("Internal error (endpoint does not match any part)");
+ throw logic_error("internal error (endpoint does not match any part)");
while(1)
{
d -= plen;
TrackPart *next = part->get_link(1-part_ep);
if(!next)
- throw InvalidParameterValue("Distance out of range");
+ throw invalid_argument("TrackType::get_point");
part_ep = (next->get_link(0)==part ? 0 : 1);
part = next;
}
}
}
+TrackPoint TrackType::get_nearest_point(const Vector &p) const
+{
+ TrackPoint result;
+ float dist = -1;
+
+ for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ {
+ TrackPoint n = i->get_nearest_point(p);
+ float d = distance(n.pos, p);
+ if(d<dist || dist<0)
+ {
+ result = n;
+ dist = d;
+ }
+ }
+
+ return result;
+}
+
bool TrackType::collide_ray(const Vector &start, const Vector &dir, float width) const
{
for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
TrackType::Loader::Loader(TrackType &t):
- Msp::DataFile::BasicLoader<TrackType>(t),
+ Msp::DataFile::ObjectLoader<TrackType>(t),
state_bits_set(false)
{
add("autofit_preference", &TrackType::autofit_preference);