3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
16 void Profile::append_vertex(const Point &p, bool smooth)
18 if(vertices.size()>1 && !vertices.back().smooth)
19 vertices.push_back(vertices.back());
23 v.smooth = (!vertices.empty() && smooth);
27 float dx = p.x-vertices.back().pos.x;
28 float dy = p.y-vertices.back().pos.y;
29 float len = sqrt(dx*dx+dy*dy);
33 if(vertices.back().smooth)
35 Point &n = vertices.back().normal;
38 len = sqrt(n.x*n.x+n.y*n.y);
43 vertices.back().normal = v.normal;
46 vertices.push_back(v);
48 if(vertices.size()==1)
55 min_coords.x = min(min_coords.x, p.x);
56 min_coords.y = min(min_coords.y, p.y);
57 max_coords.x = max(max_coords.x, p.x);
58 max_coords.y = max(max_coords.y, p.y);
62 const Profile::Vertex &Profile::get_vertex(unsigned i) const
64 if(i>=vertices.size())
65 throw InvalidParameterValue("Index out of range");
70 Profile::Loader::Loader(Profile &p):
71 DataFile::ObjectLoader<Profile>(p)
73 add("point", &Loader::point);
74 add("smooth_point", &Loader::smooth_point);
77 void Profile::Loader::point(float x, float y)
79 obj.append_vertex(Point(x/1000, y/1000), false);
82 void Profile::Loader::smooth_point(float x, float y)
84 obj.append_vertex(Point(x/1000, y/1000), true);