9 void Profile::append_vertex(const Vector &p, bool smooth)
11 if(vertices.size()>1 && !vertices.back().smooth)
12 vertices.push_back(vertices.back());
16 v.smooth = (!vertices.empty() && smooth);
20 float dx = p.x-vertices.back().pos.x;
21 float dy = p.y-vertices.back().pos.y;
22 float len = sqrt(dx*dx+dy*dy);
26 if(vertices.back().smooth)
28 Vector &n = vertices.back().normal;
31 len = sqrt(n.x*n.x+n.y*n.y);
36 vertices.back().normal = v.normal;
39 vertices.push_back(v);
41 if(vertices.size()==1)
48 min_coords.x = min(min_coords.x, p.x);
49 min_coords.y = min(min_coords.y, p.y);
50 max_coords.x = max(max_coords.x, p.x);
51 max_coords.y = max(max_coords.y, p.y);
55 const Profile::Vertex &Profile::get_vertex(unsigned i) const
57 if(i>=vertices.size())
58 throw out_of_range("Profile::get_vertex");
63 Profile::Loader::Loader(Profile &p):
64 DataFile::ObjectLoader<Profile>(p)
66 add("point", &Loader::point);
67 add("smooth_point", &Loader::smooth_point);
70 void Profile::Loader::point(float x, float y)
72 obj.append_vertex(Vector(x/1000, y/1000), false);
75 void Profile::Loader::smooth_point(float x, float y)
77 obj.append_vertex(Vector(x/1000, y/1000), true);