From 45ec6f645ff2c303700711e96421c75acf33db1a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 25 Oct 2010 16:08:57 +0000 Subject: [PATCH] Move Endpoint inside TrackType --- source/3d/track.cpp | 2 +- source/libmarklin/block.cpp | 2 +- source/libmarklin/endpoint.h | 27 --------------------------- source/libmarklin/route.cpp | 10 +++++----- source/libmarklin/track.cpp | 18 +++++++++--------- source/libmarklin/trackiter.cpp | 2 +- source/libmarklin/trackpart.h | 1 - source/libmarklin/tracktype.cpp | 6 ++++++ source/libmarklin/tracktype.h | 11 ++++++++++- source/libmarklin/train.cpp | 2 +- 10 files changed, 34 insertions(+), 47 deletions(-) delete mode 100644 source/libmarklin/endpoint.h diff --git a/source/3d/track.cpp b/source/3d/track.cpp index baf3519..49ef02e 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -29,7 +29,7 @@ Track3D::Track3D(Layout3D &l, Track &t): layout.add_track(*this); layout.get_scene().add(*this); - const vector &type_eps = track.get_type().get_endpoints(); + const vector &type_eps = track.get_type().get_endpoints(); for(unsigned i=0; i &eps = track.get_type().get_endpoints(); + const vector &eps = track.get_type().get_endpoints(); for(unsigned i=0; i dijkstra(Track &from, unsigned ep, const Pred &goal) } const TrackType &type = lowest.track->get_type(); - const vector &eps = type.get_endpoints(); + const vector &eps = type.get_endpoints(); const vector &links = lowest.track->get_links(); for(unsigned i=0; i &endpoints = (*i)->get_type().get_endpoints(); + const vector &endpoints = (*i)->get_type().get_endpoints(); const vector &links = (*i)->get_links(); // Build a combined path mask from linked endpoints @@ -196,7 +196,7 @@ void Route::update_turnouts() if(unsigned tid2 = links[j]->get_turnout_id()) { - const Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)]; + const TrackType::Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)]; int p = get_turnout(tid2); if(p>=0 && !(ep.paths&(1< &endpoints = (*i)->get_type().get_endpoints(); + const vector &endpoints = (*i)->get_type().get_endpoints(); if(unsigned tid=(*i)->get_turnout_id()) { int r = get_turnout(tid); @@ -417,7 +417,7 @@ void Route::Loader::finish() continue; unsigned path_mask = 1<second; - const vector &eps = (*i)->get_type().get_endpoints(); + const vector &eps = (*i)->get_type().get_endpoints(); for(unsigned k=0; k &eps = type.get_endpoints(); + const vector &eps = type.get_endpoints(); if(epi>=eps.size()) - throw InvalidParameterValue("Endpoint index out of range"); + throw InvalidParameterValue("TrackType::Endpoint index out of range"); - const Endpoint &ep = eps[epi]; + const TrackType::Endpoint &ep = eps[epi]; float c = cos(rot); float s = sin(rot); @@ -185,11 +185,11 @@ Point Track::get_endpoint_position(unsigned epi) const float Track::get_endpoint_direction(unsigned epi) const { - const vector &eps = type.get_endpoints(); + const vector &eps = type.get_endpoints(); if(epi>=eps.size()) - throw InvalidParameterValue("Endpoint index out of range"); + throw InvalidParameterValue("TrackType::Endpoint index out of range"); - const Endpoint &ep = eps[epi]; + const TrackType::Endpoint &ep = eps[epi]; return rot+ep.dir; } @@ -197,8 +197,8 @@ float Track::get_endpoint_direction(unsigned epi) const bool Track::snap_to(Track &other, bool link) { float limit = (link && !flex && !other.get_flex()) ? 1e-6 : 1e-4; - const vector &eps = type.get_endpoints(); - const vector &other_eps = other.get_type().get_endpoints(); + const vector &eps = type.get_endpoints(); + const vector &other_eps = other.get_type().get_endpoints(); for(unsigned i=0; i &eps = type.get_endpoints(); + const vector &eps = type.get_endpoints(); for(unsigned i=0; i &eps = _track->get_type().get_endpoints(); + const vector &eps = _track->get_type().get_endpoints(); // Find an endpoint that's connected to the entry and has the requested path for(unsigned i=0; i -#include "endpoint.h" #include "geometry.h" namespace Marklin { diff --git a/source/libmarklin/tracktype.cpp b/source/libmarklin/tracktype.cpp index 1a39877..8c1505b 100644 --- a/source/libmarklin/tracktype.cpp +++ b/source/libmarklin/tracktype.cpp @@ -154,6 +154,12 @@ void TrackType::collect_endpoints() } } +TrackType::Endpoint::Endpoint(float x, float y, float d, unsigned p): + pos(x, y), + dir(d), + paths(p) +{ } + TrackType::Loader::Loader(TrackType &t): Msp::DataFile::BasicLoader(t) diff --git a/source/libmarklin/tracktype.h b/source/libmarklin/tracktype.h index 99989be..902a2f6 100644 --- a/source/libmarklin/tracktype.h +++ b/source/libmarklin/tracktype.h @@ -9,7 +9,7 @@ Distributed under the GPL #define LIBMARKLIN_TRACKTYPE_H_ #include -#include "endpoint.h" +#include "geometry.h" #include "trackpart.h" namespace Marklin { @@ -17,6 +17,15 @@ namespace Marklin { class TrackType { public: + struct Endpoint + { + Point pos; + float dir; // Direction outwards from the endpoint + unsigned paths; + + Endpoint(float, float, float, unsigned); + }; + class Loader: public Msp::DataFile::BasicLoader { public: diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index cdb8e67..11ec776 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -990,7 +990,7 @@ unsigned Train::reserve_more() if(block->get_turnout_id()) { - const Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()]; + const TrackType::Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()]; bool multiple_paths = (track_ep.paths&(track_ep.paths-1)); if(multiple_paths || !last->get_turnout_id()) -- 2.43.0