--- /dev/null
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2010 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include <cmath>
+#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<Profile>(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<obj.points.size(); ++i)
+ {
+ obj.min_coords.x = min(obj.min_coords.x, obj.points[i].x);
+ obj.min_coords.y = min(obj.min_coords.y, obj.points[i].y);
+ obj.max_coords.x = max(obj.max_coords.x, obj.points[i].x);
+ obj.max_coords.y = max(obj.max_coords.y, obj.points[i].y);
+ }
+}
+
+void Profile::Loader::point(float x, float y)
+{
+ obj.points.push_back(Point(x/1000, y/1000));
+}
+
+} // namespace Marklin