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