本文整理汇总了C++中VP类的典型用法代码示例。如果您正苦于以下问题:C++ VP类的具体用法?C++ VP怎么用?C++ VP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: name
bool CParamManager::SetParam(VP& vp, char* pa)
{
if ( pa == NULL ) return false;
string name(pa);
string value;
string::size_type pos = name.find(':');
if ( pos == string::npos ) return false;
value = name.substr( pos+1, name.length()-pos );
name = name.substr( 0, pos );
VP_IT it = vp.find(name);
if ( it == vp.end() ) return false;
_CParam* p = (*it).second;
switch ( p->type )
{
case PT_INT:
*((int*)p->value) = CCStringMake(value.c_str())->intValue();
break;
case PT_FLOAT:
*((float*)p->value) = CCStringMake(value.c_str())->floatValue();
break;
default:
return false;
}
return true;
}
示例2: solve
VP solve(vector<Line> line) {
sort(line.begin(), line.end(), cmp());
int n = unique(line.begin(), line.end(), kequal) - line.begin();
assert(n > 2);
int head = 0, tail = 1;
que[0] = line[0]; que[1] = line[1];
VP ret;
for (int i = 2; i < n; i++) {
if (fabs((que[tail].e - que[tail].s).det(que[tail - 1].e - que[tail - 1].s)) < eps ||
fabs((que[head].e - que[head].s).det(que[head + 1].e - que[head + 1].s)) < eps) {
return ret;
}
while (head < tail && ((isLL(que[tail], que[tail - 1])[0] - line[i].s)
.det(line[i].e - line[i].s)) > eps) tail--;
while (head < tail && ((isLL(que[head], que[head + 1])[0] - line[i].s)
.det(line[i].e - line[i].s)) > eps) head++;
que[++tail] = line[i];
}
while (head < tail && ((isLL(que[tail], que[tail - 1])[0] - que[head].s)
.det(que[head].e - que[head].s)) > eps) tail--;
while (head < tail && ((isLL(que[head], que[head + 1])[0] - que[tail].s)
.det(que[tail].e - que[tail].s)) > eps) head++;
if (tail <= head + 1)
return ret;
for (int i = head; i < tail; i++) {
ret.push_back(isLL(que[i], que[i + 1])[0]);
}
if (head < tail + 1)
ret.push_back(isLL(que[head], que[tail])[0]);
return ret;
}
示例3: test_container_with
void test_container_with (VP &v1) const {
// Container type tests in addition to expression types
// Insert and erase
v1.insert_element (0,0, 55);
v1.erase_element (1,1);
v1.clear ();
}
示例4: isLL
VP isLL(CP p1, CP p2, CP q1, CP q2){
//二直线交点,无则返回空vector
//返回空时有共线与相离的区别,用(p2 - p1).det(q1 - p1) == 0判断
VP ret;
T d = (q2 - q1).det(p2 - p1);
if (fabs(d) < eps) return ret;
ret.push_back(p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / d));
return ret;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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
}
示例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: isCL
VP isCL(CP c, double r, CP p1, CP p2) {
//返回值按到p1的距离从小到大排列
double x = (p1 - c).dot(p2 - p1);
double y = (p2 - p1).abs2();
double d = x * x - y * ((p1 - c).abs2() - r * r);
if (d < -eps) return VP(0);
if (d < 0) d = 0;
Point q1 = p1 - (p2 - p1) * (x / y);
Point q2 = (p2 - p1) * (sqrt(d) / y);
VP ret;
ret.push_back(q1 - q2);
ret.push_back(q1 + q2);
return ret;
}
示例11: calcPos
int calcPos(VI &data,VVI &g,int node)
{
int ret=-1;
VI wc(n , 0);
VI pos(n , -1);
int curNode = data[n-1];
for(int i = sz(data)-2 ; i>=0 ; i--)
{
if(g[curNode][data[i]])
{
wc[curNode]++;
}
else
{
wc[data[i]]++;
curNode = data[i];
}
}
for(int i = 0 ; i<n ; i++)
cout<<i <<" wc "<<wc[i]<<endl;
pos[curNode] = 1;
VP slist;
int idx = 2;
for(int i = 0 ; i<n ; i++)
{
if(i==curNode) continue;
slist.push_back({ wc[i] , i });
}
sort(slist.begin() , slist.end());
for(int i = sz(slist)-1 ; i>=0 ; i--)
{
if(i==(sz(slist)-1) || (slist[i].x!=slist[i+1].x))
pos[slist[i].y] = idx++;
else pos[slist[i].y] = pos[slist[i+1].y];
}
for(int i = 0 ; i<n ; i++)
{
cout<<i<<" pos "<<pos[i]<<endl;
}
return pos[node];
}
示例12: 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;
}
示例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: 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;
}
}
示例15: 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;
}