3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
16 const Point &Profile::get_point(unsigned i) const
19 throw InvalidParameterValue("Index out of range");
23 Point Profile::get_edge_normal(unsigned i) const
25 if(i+1>=points.size())
26 throw InvalidParameterValue("Index out of range");
27 float dx = points[i+1].x-points[i].x;
28 float dy = points[i+1].y-points[i].y;
29 float len = sqrt(dx*dx+dy*dy);
30 return Point(dy/len, -dx/len);
34 Profile::Loader::Loader(Profile &p):
35 DataFile::ObjectLoader<Profile>(p)
37 add("point", &Loader::point);
40 void Profile::Loader::finish()
42 obj.min_coords = obj.points[0];
43 obj.max_coords = obj.points[0];
44 for(unsigned i=1; i<obj.points.size(); ++i)
46 obj.min_coords.x = min(obj.min_coords.x, obj.points[i].x);
47 obj.min_coords.y = min(obj.min_coords.y, obj.points[i].y);
48 obj.max_coords.x = max(obj.max_coords.x, obj.points[i].x);
49 obj.max_coords.y = max(obj.max_coords.y, obj.points[i].y);
53 void Profile::Loader::point(float x, float y)
55 obj.points.push_back(Point(x/1000, y/1000));
58 } // namespace Marklin