]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/tracktype.cpp
BasicLoader is now called ObjectLoader
[r2c2.git] / source / libr2c2 / tracktype.cpp
index 35d220821500e1621dbb19bc732587398154507b..29bf47be5409d42eb79fbd9644fbf1a62e08e1bc 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #include <cmath>
 #include "tracktype.h"
 
@@ -62,7 +55,7 @@ bool TrackType::is_dead_end() const
 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];
 }
@@ -70,7 +63,7 @@ const TrackType::Endpoint &TrackType::get_endpoint(unsigned i) const
 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;
@@ -94,7 +87,7 @@ TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
        }
 
        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)
        {
@@ -113,13 +106,22 @@ TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
                        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;
                }
        }
 }
 
+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)
+               if(i->collide_ray(start, dir, width))
+                       return true;
+
+       return false;
+}
+
 void TrackType::collect_endpoints()
 {
        endpoints.clear();
@@ -171,7 +173,7 @@ TrackType::Endpoint::Endpoint(float x, float y, float d, unsigned p):
 
 
 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);