本文整理汇总了C++中Polygon2::side方法的典型用法代码示例。如果您正苦于以下问题:C++ Polygon2::side方法的具体用法?C++ Polygon2::side怎么用?C++ Polygon2::side使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon2
的用法示例。
在下文中一共展示了Polygon2::side方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: this_side
int pick_major_axis(
vector<pair<Pmwx::Halfedge_handle, Pmwx::Halfedge_handle> >& sides, // Per side: inclusive range of half-edges "consolidated" into the sides.
Polygon2& bounds, // Inset boundary in metric, first side matched to the list.
Vector2& v_x,
Vector2& v_y)
{
// special case: if we find a block with exactly ONE right angle, the longer of the two
// sides going into the right angle is hte major axis, full stop, we're done.
int right_angle = -1;
for(int i = 0; i < sides.size(); ++i)
{
int j = (i + 1) % sides.size();
int k = (i + 2) % sides.size();
Vector2 vx(Vector2(bounds[i],bounds[j]));
Vector2 vy(Vector2(bounds[j],bounds[k]));
vx.normalize();
vy.normalize();
double dot = fabs(vx.dot(vy));
if(dot < 0.087155742747658)
{
if(right_angle == -1)
right_angle = j;
else
right_angle = -2; // "more than one right angle" flag - causes us to NOT try this algo.
}
}
if(right_angle >= 0)
{
int prev = (right_angle + sides.size() - 1) % sides.size();
int next = (right_angle + 1) % sides.size();
Vector2 vp(Vector2(bounds[prev],bounds[right_angle]));
Vector2 vn(Vector2(bounds[right_angle],bounds[next]));
double pl = vp.normalize();
double nl = vn.normalize();
if(pl > nl)
v_x = vp;
else
v_x = vn;
v_y = v_x.perpendicular_ccw();
return right_angle;
}
// THIS is the algo we shipped with - it tries to minimize the short side axis of the block. This works
// okay but tends to make the diagonal of diagonal cuts (like Broadway) the main axis since (by the pythag
// theorem) that slightly reduces the block depth.
#if 0
int shortest = -1;
double thinnest_so_far = 0.0;
for(int i = 0; i < sides.size(); ++i)
{
Vector2 vx = Vector2(bounds.side(i).p1,bounds.side(i).p2);
vx.normalize();
Vector2 vy = vx.perpendicular_ccw();
double bbox[4];
bbox[0] = bbox[2] = vx.dot(Vector2(bounds[0]));
bbox[1] = bbox[3] = vy.dot(Vector2(bounds[0]));
for(int j = 0; j < sides.size(); ++j)
{
double x = vx.dot(Vector2(bounds[j]));
double y = vy.dot(Vector2(bounds[j]));
bbox[0] = dobmin2(bbox[0], x);
bbox[1] = dobmin2(bbox[1], y);
bbox[2] = dobmax2(bbox[2], x);
bbox[3] = dobmax2(bbox[3], y);
}
double xdist = fabs(bbox[2]-bbox[0]);
double ydist = fabs(bbox[3]-bbox[1]);
double my_dist = dobmin2(xdist,ydist);
if(shortest == -1 || my_dist < thinnest_so_far)
{
shortest = i;
thinnest_so_far = my_dist;
if(xdist < ydist)
{
v_x = vx.perpendicular_ccw();
v_y = vy.perpendicular_ccw();
}
else
{
v_x = vx;
v_y = vy;
}
}
}
DebugAssert(shortest >= 0);
return shortest;
#endif
#if 1
// #error This algo works 95% of the time, but 5% of the time it picks a slashed short end as the
// #error long axis, which gives a long thin block a wrong axis alignment and a huge AABB. Bad!
// The basic idea: we want to pick the grid axis MOST aligned with the block such that
// the major axis supports roads.
//.........这里部分代码省略.........
示例2: circ
bool build_convex_polygon(
Pmwx::Ccb_halfedge_circulator ccb,
vector<pair<Pmwx::Halfedge_handle, Pmwx::Halfedge_handle> >& sides,
const CoordTranslator2& trans,
Polygon2& metric_bounds,
double max_err_mtrs,
double min_side_len)
{
double e_sq = max_err_mtrs*max_err_mtrs;
sides.clear();
metric_bounds.clear();
Pmwx::Ccb_halfedge_circulator circ(ccb);
// Bbox2 bounds;
//
// do {
// bounds += cgal2ben(circ->source()->point());
// } while (++circ != ccb);
Pmwx::Ccb_halfedge_circulator start,next;
start = ccb;
do {
--start;
if(!sides_can_merge(start,ccb))
break;
if(!within_err_metric(start,ccb,trans,e_sq))
break;
} while(start != ccb);
++start;
// now we can go around.
circ = start;
//int ne = count_circulator(start);
//printf("Poly has %d sides.\n", ne);
do {
Pmwx::Ccb_halfedge_circulator stop(circ);
do {
++stop;
} while(sides_can_merge(circ,stop) && within_err_metric(circ,stop,trans,e_sq) && stop != start);
--stop;
//printf("Pushing side of %d, %d\n", circulator_distance_to(start, circ),circulator_distance_to(start,stop));
sides.push_back(pair<Pmwx::Halfedge_handle,Pmwx::Halfedge_handle>(circ, stop));
++stop;
circ = stop;
} while(circ != start);
if(sides.size() < 3)
{
//debug_mesh_point(bounds.centroid(),1,1,1);
return false;
}
int i, j, k;
vector<Segment2> msides;
for(i = 0; i < sides.size(); ++i)
{
j = (i + 1) % sides.size();
DebugAssert(sides[i].second->target() == sides[j].first->source());
msides.push_back(Segment2(
trans.Forward(cgal2ben(sides[i].first->source()->point())),
trans.Forward(cgal2ben(sides[i].second->target()->point()))));
}
vector<Segment2> debug(msides);
for(i = 0; i < sides.size(); ++i)
{
j = (i + 1) % sides.size();
Vector2 v1(msides[i].p1,msides[i].p2);
Vector2 v2(msides[j].p1,msides[j].p2);
v1.normalize();
v2.normalize();
if(v1.dot(v2) > 0.9998 ||
!v1.left_turn(v2))
{
//debug_mesh_point(trans.Reverse(msides[i].p2),1,0,0);
return false;
}
double w = width_for_he(sides[i].first);
if(w)
{
v1 = v1.perpendicular_ccw();
v1 *= w;
msides[i].p1 += v1;
msides[i].p2 += v1;
}
}
for(j = 0; j < sides.size(); ++j)
{
i = (j + sides.size() - 1) % sides.size();
Line2 li(msides[i]), lj(msides[j]);
Point2 p;
if(!li.intersect(lj,p))
{
Assert(!"Failure to intersect.\n");
return false;
}
//.........这里部分代码省略.........