X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fprofile.cpp;fp=source%2Flibmarklin%2Fprofile.cpp;h=f4dcf188d03b1f58d7ff7c56f153f12217446d94;hb=7e382cc3cad8c4f6945b0c9d89e2ca917b42b740;hp=0000000000000000000000000000000000000000;hpb=446fa7ad737b431621be53a23360ea3bbe417fe5;p=r2c2.git diff --git a/source/libmarklin/profile.cpp b/source/libmarklin/profile.cpp new file mode 100644 index 0000000..f4dcf18 --- /dev/null +++ b/source/libmarklin/profile.cpp @@ -0,0 +1,58 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#include +#include "profile.h" + +using namespace std; +using namespace Msp; + +namespace Marklin { + +const Point &Profile::get_point(unsigned i) const +{ + if(i>=points.size()) + throw InvalidParameterValue("Index out of range"); + return points[i]; +} + +Point Profile::get_edge_normal(unsigned i) const +{ + if(i+1>=points.size()) + throw InvalidParameterValue("Index out of range"); + float dx = points[i+1].x-points[i].x; + float dy = points[i+1].y-points[i].y; + float len = sqrt(dx*dx+dy*dy); + return Point(-dx/len, dy/len); +} + + +Profile::Loader::Loader(Profile &p): + DataFile::ObjectLoader(p) +{ + add("point", &Loader::point); +} + +void Profile::Loader::finish() +{ + obj.min_coords = obj.points[0]; + obj.max_coords = obj.points[0]; + for(unsigned i=1; i