本文整理汇总了C++中VP::size方法的典型用法代码示例。如果您正苦于以下问题:C++ VP::size方法的具体用法?C++ VP::size怎么用?C++ VP::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VP
的用法示例。
在下文中一共展示了VP::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConvexCut
VP ConvexCut(const VP &ps, L l) {
VP Q;
for (int i = 0; i < (int)ps.size(); i++) {
P A = ps[i], B = ps[(i+1)%ps.size()];
if (ccw(l.a, l.b, A) != -1) Q.push_back(A);
if (ccw(l.a, l.b, A) * ccw(l.a, l.b, B) < 0)
Q.push_back(is_ll((L){A, B}, l));
}
return Q;
}
示例2: split_route
void split_route(vector<Segment> &vs,VR &nodes,int idx, int n1, int n2){
ParamEdge e=vs[idx].edge;
debugline(e.from(),e.to(),255,0,0,true);
double minp=DBL_MAX;
int minidx=-1;
for (int j=0,n=nodes.size();j<n;j++){
if (j==n1 || j==n2) continue;
if (e.cross(nodes[j])){
if (nodes[j].contains(e.from())) continue;
if (nodes[j].contains(e.to())) continue;
double p=e.cross_param_smallest(nodes[j]);
if (p<minp){
minp=p;
minidx=j;
}
}
}
if (minidx<0) return ;
Point dc=e.dist_vec(nodes[minidx].center());
if (dc.is_null()){
dc=to_left(e.unit(),PI/2); // minidxust choose a side
}
VP pts;
Point r=e.dist_vec(nodes[minidx].TL());
if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TL());
r=e.dist_vec(nodes[minidx].TR());
if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TR());
r=e.dist_vec(nodes[minidx].BL());
if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BL());
r=e.dist_vec(nodes[minidx].BR());
if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BR());
if (pts.size()==0) {
printf("Ups, no points on smaller side of edge/node cut area");
return;
}
if (pts.size()>2 ) throw "expected 1 or 2 points";
vector<Segment> vsnew;
int idxlast=idx+1;
if (pts.size()==1){
vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false));
vsnew.push_back(Segment(ParamEdge(pts[0],e.to()),false,vs[idx].last));
} else if (pts.size()==2) {
if (norm(pts[0]-e.from())>norm(pts[1]-e.from())){ // do nearest point first
swap(pts[0],pts[1]);
}
vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false));
vsnew.push_back(Segment(ParamEdge(pts[0],pts[1]),false,false));
vsnew.push_back(Segment(ParamEdge(pts[1],e.to()),false,vs[idx].last));
idxlast++;
}
vs.erase(vs.begin()+idx);
vs.insert(vs.begin()+idx,vsnew.begin(),vsnew.end());
split_route(vs,nodes,idxlast,minidx,n2);
split_route(vs,nodes,idx,n1,minidx); // new overlaps could be introduced after makeing a kink into the line
}
示例3: max_distance
ld max_distance(const VP &ps) {
assert (ps.size() > 1);
VP g = ConvexHull(ps);
int n = g.size(), a = 0, b = 1;
ld res = abs(g[0] - g[1]);
while (a < n) {
P p1 = g[a%n], p2 = g[(a+1)%n];
P q1 = g[b%n], q2 = g[(b+1)%n];
if (arg((p2 - p1) / (q1 - q2)) > 0) ++b; else ++a;
res = max(res, abs(p1 - q1));
}
return res;
}
示例4: calculatePaths
void calculatePaths() {
for (int i = 0; i < paths.size(); i++) {
if (paths[i].first == 1) {
depth = 0;
for (int j = 0; j < paths.size(); j++) {
//cout << j << endl;
pair<int,int> speeds = followPath(i, j);
bessieSpeeds.pb(speeds.bessie);
elsieSpeeds.pb(speeds.elsie);
}
}
}
}
示例5: areaCP
double areaCP(VP ps, Point center, double r) {
int n = ps.size();
double ans = 0;
for (int i = 0; i < n; i++) {
ans += areaCT(ps[i], ps[(i + 1) % n], center, r);
}
return ans;
}
示例6: CreateFromPoints
void Polygon::CreateFromPoints(const VP& SomePoints)
{
m_pPosition = Sum(SomePoints)/SomePoints.size();
m_vPoints = ConvexHull(SomePoints);
for (auto& m_vPoint : m_vPoints)
{
m_vPoint -= m_pPosition;
}
}
示例7: convexCut
VP convexCut(VP ps, CP p1, CP p2) {
//返回凸多边形被有向直线p1p2切割后左半部分, 可改为在线半平面交
int n = ps.size();
VP ret(0);
for (int i = 0; i < n; i++) {
int d1 = sgn((p2 - p1).det(ps[i] - p1));
int d2 = sgn((p2 - p1).det(ps[(i + 1) % n] - p1));
if (d1 >= 0) ret.push_back(ps[i]);
if (d1 * d2 < 0) ret.push_back(isLL(p1, p2, ps[i], ps[(i + 1) % n])[0]);
}
return ret;
}
示例8: ConvexHull
VP ConvexHull(VP ps) {
int n = ps.size();
int k = 0;
sort(ps.begin(), ps.end());
VP ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++])
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
ch.resize(k - 1);
return ch;
}
示例9: cut_convex
void cut_convex(VP& a, Point p1, Point p2) {
VP b;
repn(i, sz(a)) {
Point a1 = a[i], a2 = a[(i + 1) % a.size()];
double m1 = mult(p1, p2, a1);
double m2 = mult(p1, p2, a2);
if(sgn(m1) * sgn(m2) < 0) {
Point tmp;
tmp.x = (a1.x * m2 - a2.x * m1) / (m2 - m1);
tmp.y = (a1.y * m2 - a2.y * m1) / (m2 - m1);
b.push_back(tmp);
}
if(sgn(m2) >= 0) b.push_back(a2);
}
示例10: draw
///********************************************************
void draw(){ //glut 回调函数
double maxX=-100000,minX=-maxX;
double maxY=-100000,minY=-maxY;
for(int i=0;i<city.size();i++){
maxX=max(maxX,city[i].first);
minX=min(minX,city[i].first);
maxY=max(maxY,city[i].second);
minY=min(minY,city[i].second);
}
double aveX=(minX+maxX)/2, _X=1.2*(aveX-minX);
double aveY=(minY+maxY)/2, _Y=1.2*(aveY-minY); //等比例缩放
glClearColor(1.0, 1.0 , 1.0, 0); //白板
glClear(GL_COLOR_BUFFER_BIT); //清位
glPointSize(10); //设置点的大小,这个必须在模式选择之前
glLineWidth(5); //设置线宽
glBegin(GL_POINTS); //画点
for(int i=0;i<city.size();i++){
glColor3f(1,0,0);
double x=(city[i].first-aveX)/_X;
double y=(city[i].second-aveY)/_Y;
glVertex2f(x,y);
}
glEnd();
glBegin(GL_LINE_LOOP); //画线
for(int i=0;i<city.size();i++){
glColor3f(0,1,0);
double x=(city[ permut[i] ].first- aveX)/_X; //permutation
double y=(city[ permut[i] ].second-aveY)/_Y;
glVertex2f(x,y);
}
glEnd();
glutSwapBuffers();
}
示例11: contains
int contains(VP ps, CP q) {
int n = ps.size();
int res = -1;
for (int i = 0; i < n; i++) {
Point a = ps[i] - q, b = ps[(i + 1) % n] - q;
if (a.y > b.y) {
Point t = a; a = b; b = t;
}
if (a.y < eps && b.y > eps && a.det(b) > eps) {
res = -res;
}
if (abs(a.det(b)) < eps && a.dot(b) < eps) {
return 0;
}
}
return res;
}
示例12: convexDiameter
double convexDiameter(VP ps) {
int n = ps.size();
int is = 0, js = 0;
for (int i = 1; i < n; i++) {
if (ps[i].x > ps[is].x) is = i;
if (ps[i].x < ps[js].x) js = i;
}
double maxd = (ps[is] - ps[js]).abs();
int i = is, j = js;
do {
if ((ps[(i + 1) % n] - ps[i]).det(ps[(j + 1) % n] - ps[j]) >= 0) {
j = (j + 1) % n;
} else {
i = (i + 1) % n;
}
maxd = max(maxd, (ps[i] - ps[j]).abs());
} while (i != is || j != js);
return maxd;
}
示例13: areaCT
double areaCT(Point p1, Point p2, double r) {
VP qs = isCL(0, r, p1, p2);
if (qs.size() == 0) return r * r * rad(p1, p2) / 2;
bool b1 = p1.abs() > r + eps, b2 = p2.abs() > r + eps;
if (b1 && b2) {
if ((p1 - qs[0]).dot(p2 - qs[0]) < eps &&
(p1 - qs[1]).dot(p2 - qs[1]) < eps) {
return (r * r * (rad(p1, p2) - rad(qs[0], qs[1])) +
qs[0].det(qs[1])) / 2;
} else {
return r * r * rad(p1, p2) / 2;
}
} else if (b1) {
return (r * r * rad(p1, qs[0]) + qs[0].det(p2)) / 2;
} else if (b2) {
return (r * r * rad(qs[1], p2) + p1.det(qs[1])) / 2;
} else {
return p1.det(p2) / 2;
}
}
示例14: solve
VP solve(VP ps) {
int n = ps.size(), k = 0;
if (n <= 1) {
return ps;
}
sort(ps.begin(), ps.end(), cmp());
VP qs(n * 2);
for (int i = 0; i < n; qs[k++] = ps[i++]) {
while(k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) < eps) {
k--;
}
}
for (int i = n - 2, t = k; i >= 0; qs[k++] = ps[i--]) {
while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) < eps) {
k--;
}
}
qs.resize(k - 1);
return qs;
}
示例15: mp
pair<int,int> followPath(int path, int startDepth) {
depth++;
if (depth > 17) return mp(1000000, 1000000);
int bessieTime = speeds[path].bessie, elsieTime = speeds[path].elsie;
int leastTimeBessie = 1000000, leastTimeElsie = 1000001;
cout << paths[path].second << endl;
if (paths[path].second == N - 1) {
cout << path << endl;
return mp(bessieTime, elsieTime);
}
for (int i = startDepth; i < paths.size(); i++) {
if (path != i && paths[path].second == paths[i].first) {
bessieTime = speeds[path].bessie;
elsieTime = speeds[path].elsie;
pair<int,int> speeds = followPath(i, 0);
bessieTime += speeds.bessie;
elsieTime += speeds.elsie;
if (bessieTime < leastTimeBessie) leastTimeBessie = bessieTime;
if (elsieTime < leastTimeElsie) leastTimeElsie = elsieTime;
}
}
return mp(leastTimeBessie, leastTimeElsie);
}