X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibr2c2%2Ftracktype.cpp;h=29bf47be5409d42eb79fbd9644fbf1a62e08e1bc;hb=64340dad429ba4040538fc06b6882aabdb489925;hp=4ac096767bac5a1e5efa580f4c8da5c3c700a46b;hpb=1ff06c5bc46a677fa389ef86c6b26664368f1653;p=r2c2.git diff --git a/source/libr2c2/tracktype.cpp b/source/libr2c2/tracktype.cpp index 4ac0967..29bf47b 100644 --- a/source/libr2c2/tracktype.cpp +++ b/source/libr2c2/tracktype.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #include "tracktype.h" @@ -15,7 +8,7 @@ namespace R2C2 { TrackType::TrackType(const ArticleNumber &an): art_nr(an), - double_address(false), + state_bits(0), autofit_preference(1) { } @@ -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::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,11 +173,13 @@ TrackType::Endpoint::Endpoint(float x, float y, float d, unsigned p): TrackType::Loader::Loader(TrackType &t): - Msp::DataFile::BasicLoader(t) + Msp::DataFile::ObjectLoader(t), + state_bits_set(false) { add("autofit_preference", &TrackType::autofit_preference); add("description", &TrackType::description); - add("double_address", &TrackType::double_address); + add("object", &TrackType::object); + add("state_bits", &Loader::state_bits); add("part", &Loader::part); } @@ -189,6 +193,15 @@ void TrackType::Loader::part() TrackPart p; load_sub(p); obj.parts.push_back(p); + if(!state_bits_set && p.get_path()) + while(p.get_path()>=(1U<