-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#include <cmath>
#include "profile.h"
namespace R2C2 {
-void Profile::append_vertex(const Point &p, bool smooth)
+void Profile::append_vertex(const Vector &p, bool smooth)
{
if(vertices.size()>1 && !vertices.back().smooth)
vertices.push_back(vertices.back());
if(!vertices.empty())
{
- float dx = p.x-vertices.back().pos.x;
- float dy = p.y-vertices.back().pos.y;
- float len = sqrt(dx*dx+dy*dy);
- v.normal.x = dy/len;
- v.normal.y = -dx/len;
+ Vector span = p-vertices.back().pos;
+ span.normalize();
+ v.normal.x = span.y;
+ v.normal.y = -span.x;
if(vertices.back().smooth)
{
- Point &n = vertices.back().normal;
- n.x += v.normal.x;
- n.y += v.normal.y;
- len = sqrt(n.x*n.x+n.y*n.y);
- n.x /= len;
- n.y /= len;
+ Vector &n = vertices.back().normal;
+ n += v.normal;
+ n.normalize();
}
else
vertices.back().normal = v.normal;
const Profile::Vertex &Profile::get_vertex(unsigned i) const
{
if(i>=vertices.size())
- throw InvalidParameterValue("Index out of range");
+ throw out_of_range("Profile::get_vertex");
return vertices[i];
}
void Profile::Loader::point(float x, float y)
{
- obj.append_vertex(Point(x/1000, y/1000), false);
+ obj.append_vertex(Vector(x/1000, y/1000, 0), false);
}
void Profile::Loader::smooth_point(float x, float y)
{
- obj.append_vertex(Point(x/1000, y/1000), true);
+ obj.append_vertex(Vector(x/1000, y/1000, 0), true);
}
} // namespace R2C2