fixup c++ style in offset_converter

This commit is contained in:
Dane Springmeyer 2014-03-18 17:31:15 -07:00
parent f59dc36a19
commit 080b8e174c

View file

@ -46,7 +46,6 @@ template <typename Geometry>
struct MAPNIK_DECL offset_converter struct MAPNIK_DECL offset_converter
{ {
typedef std::size_t size_type; typedef std::size_t size_type;
//typedef typename Geometry::value_type value_type;
offset_converter(Geometry & geom) offset_converter(Geometry & geom)
: geom_(geom) : geom_(geom)
@ -62,10 +61,7 @@ struct MAPNIK_DECL offset_converter
enum status enum status
{ {
initial, initial,
process, process
last_vertex,
angle_joint,
end
}; };
double get_offset() const double get_offset() const
@ -98,19 +94,27 @@ struct MAPNIK_DECL offset_converter
unsigned vertex(double * x, double * y) unsigned vertex(double * x, double * y)
{ {
if (offset_ == 0.0) if (offset_ == 0.0)
{
return geom_.vertex(x, y); return geom_.vertex(x, y);
}
if (status_ == initial) if (status_ == initial)
{
init_vertices(); init_vertices();
}
if (pos_ >= vertices_.size()) if (pos_ >= vertices_.size())
{
return SEG_END; return SEG_END;
}
pre_ = (pos_ ? cur_ : pre_first_); pre_ = (pos_ ? cur_ : pre_first_);
cur_ = vertices_[pos_++]; cur_ = vertices_.at(pos_++);
if (pos_ == vertices_.size()) if (pos_ == vertices_.size())
{
return output_vertex(x, y); return output_vertex(x, y);
}
double const check_dist = offset_ * threshold_; double const check_dist = offset_ * threshold_;
double const check_dist2 = check_dist * check_dist; double const check_dist2 = check_dist * check_dist;
@ -127,13 +131,19 @@ struct MAPNIK_DECL offset_converter
double const dy = u0.y - cur_.y; double const dy = u0.y - cur_.y;
if (dx*dx + dy*dy > check_dist2) if (dx*dx + dy*dy > check_dist2)
{
break; break;
}
if (!intersection(pre_, cur_, &vt, u0, u1, &ut)) if (!intersection(pre_, cur_, &vt, u0, u1, &ut))
{
continue; continue;
}
if (vt < 0.0 || vt > t || ut < 0.0 || ut > 1.0) if (vt < 0.0 || vt > t || ut < 0.0 || ut > 1.0)
{
continue; continue;
}
t = vt; t = vt;
pos_ = i+1; pos_ = i+1;
@ -162,12 +172,18 @@ private:
static double explement_reflex_angle(double angle) static double explement_reflex_angle(double angle)
{ {
if (angle > pi) if (angle > pi)
{
return angle - 2 * pi; return angle - 2 * pi;
}
else if (angle < -pi) else if (angle < -pi)
{
return angle + 2 * pi; return angle + 2 * pi;
}
else else
{
return angle; return angle;
} }
}
static bool intersection(vertex2d const& u1, vertex2d const& u2, double* ut, static bool intersection(vertex2d const& u1, vertex2d const& u2, double* ut,
vertex2d const& v1, vertex2d const& v2, double* vt) vertex2d const& v1, vertex2d const& v2, double* vt)
@ -186,7 +202,9 @@ private:
double const dn = vx * uy - ux * vy; double const dn = vx * uy - ux * vy;
if (dn > -1e-6 && dn < 1e-6) if (dn > -1e-6 && dn < 1e-6)
{
return false; // they are parallel return false; // they are parallel
}
*vt = up / dn; *vt = up / dn;
*ut = (*vt * vx + dx) / ux; *ut = (*vt * vx + dx) / ux;
@ -200,7 +218,9 @@ private:
double const dn = vy * ux - uy * vx; double const dn = vy * ux - uy * vx;
if (dn > -1e-6 && dn < 1e-6) if (dn > -1e-6 && dn < 1e-6)
{
return false; // they are parallel return false; // they are parallel
}
*vt = up / dn; *vt = up / dn;
*ut = (*vt * vy + dy) / uy; *ut = (*vt * vy + dy) / uy;
@ -251,7 +271,9 @@ private:
status init_vertices() status init_vertices()
{ {
if (status_ != initial) // already initialized if (status_ != initial) // already initialized
{
return status_; return status_;
}
vertex2d v1(vertex2d::no_init); vertex2d v1(vertex2d::no_init);
vertex2d v2(vertex2d::no_init); vertex2d v2(vertex2d::no_init);
@ -261,7 +283,9 @@ private:
v2.cmd = geom_.vertex(&v2.x, &v2.y); v2.cmd = geom_.vertex(&v2.x, &v2.y);
if (v2.cmd == SEG_END) // not enough vertices in source if (v2.cmd == SEG_END) // not enough vertices in source
{
return status_ = process; return status_ = process;
}
double angle_a = 0; double angle_a = 0;
double angle_b = std::atan2((v2.y - v1.y), (v2.x - v1.x)); double angle_b = std::atan2((v2.y - v1.y), (v2.x - v1.x));
@ -290,16 +314,24 @@ private:
if (offset_ < 0.0) if (offset_ < 0.0)
{ {
if (joint_angle > 0.0) if (joint_angle > 0.0)
{
joint_angle = joint_angle - 2 * pi; joint_angle = joint_angle - 2 * pi;
}
else else
bulge_steps = 1 + int(std::floor(half_turns / pi)); {
bulge_steps = 1 + static_cast<int>(std::floor(half_turns / pi));
}
} }
else else
{ {
if (joint_angle < 0.0) if (joint_angle < 0.0)
{
joint_angle = joint_angle + 2 * pi; joint_angle = joint_angle + 2 * pi;
}
else else
bulge_steps = 1 + int(floor(half_turns / pi)); {
bulge_steps = 1 + static_cast<int>(std::floor(half_turns / pi));
}
} }
#ifdef MAPNIK_LOG #ifdef MAPNIK_LOG