X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fprofile.cpp;h=907da8adf791fb12a068dc3a318e13dde108429b;hb=f74a48e60ff2e818ada3bbbfcb200e5cd2b633d6;hp=96b06a2c185a1f174d3afa99f1f6de3b67a76569;hpb=f8a7788cee0261babfc4c804a58515aad6dfbc3d;p=r2c2.git diff --git a/source/libr2c2/profile.cpp b/source/libr2c2/profile.cpp index 96b06a2..907da8a 100644 --- a/source/libr2c2/profile.cpp +++ b/source/libr2c2/profile.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include #include "profile.h" @@ -24,20 +17,16 @@ void Profile::append_vertex(const Vector &p, bool smooth) 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) { Vector &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; + n += v.normal; + n.normalize(); } else vertices.back().normal = v.normal; @@ -62,7 +51,7 @@ void Profile::append_vertex(const Vector &p, bool smooth) 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]; } @@ -76,12 +65,12 @@ Profile::Loader::Loader(Profile &p): void Profile::Loader::point(float x, float y) { - obj.append_vertex(Vector(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(Vector(x/1000, y/1000), true); + obj.append_vertex(Vector(x/1000, y/1000, 0), true); } } // namespace R2C2