本文整理汇总了C++中Polyline::addPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Polyline::addPoint方法的具体用法?C++ Polyline::addPoint怎么用?C++ Polyline::addPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polyline
的用法示例。
在下文中一共展示了Polyline::addPoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
srand((unsigned) time(NULL));
try {
XList<Shape*> list;
// filling list of figures with random figures of all types.
int numberOfElements = rand() % 100;
for(int i = 0; i < numberOfElements; i++) {
switch (i % 5) {
case 0:
list.pushElementToBack(new Point("TestPoint", rand() % 100, rand() % 100));
break;
case 1:
list.pushElementToBack(new Circle("TestCircle", rand() % 100, rand() % 100, rand() % 100));
break;
case 2:
list.pushElementToBack(new Rect("TestRect", rand() % 100, rand() % 100, rand() % 100, rand() % 100));
break;
case 3:
list.pushElementToBack(new Square("TestSquare", rand() % 100, rand() % 100, rand() % 100));
break;
case 4:
Polyline* pol = new Polyline("TestPol");
Point p1("pol_point_1", rand() % 100, rand() % 100);
Point p2("pol_point_2", rand() % 100, rand() % 100);
Point p3("pol_point_3", rand() % 100, rand() % 100);
pol->addPoint(p1);
pol->addPoint(p2);
pol->addPoint(p3);
list.pushElementToBack(pol);
break;
}
}
std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";
XList<Shape*>::Iterator it = list.begin();
for(it = list.begin(); it != list.end(); ++it) {
std::cout << "\n" << **it << "\n";
}
std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";
for(it = list.begin(); it != list.end(); ++it) {
delete *it;
}
// should be zero
std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";
return 0;
} catch (std::exception ex) {
std::cerr << ex.what();
return 1;
}
}
示例2: Polyline
Polyline * Factory::getRandPolyline() {
Polyline * pl = new Polyline();
int N = iRand(1, 10);
for (int i = 0; i < N; i++) {
Point * p = getRandPoint();
pl->addPoint(* p);
delete p;
}
return pl;
}
示例3: constructPolylineFromSegments
Polyline* Polyline::constructPolylineFromSegments(const std::vector<Polyline*>& ply_vec, double prox)
{
size_t nLines = ply_vec.size();
Polyline* new_ply = new Polyline(*ply_vec[0]);
std::vector<GEOLIB::Point*> pnt_vec(new_ply->getPointsVec());
std::vector<Polyline*> local_ply_vec;
for (size_t i = 1; i < nLines; i++)
local_ply_vec.push_back(ply_vec[i]);
while (!local_ply_vec.empty())
{
bool ply_found(false);
prox *= prox; // square distance once to save time later
for (std::vector<Polyline*>::iterator it = local_ply_vec.begin(); it != local_ply_vec.end(); ++it)
{
if (pnt_vec == (*it)->getPointsVec())
{
size_t nPoints((*it)->getNumberOfPoints());
// if (new_ply->getPointID(0) == (*it)->getPointID(0))
if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0), (*it)->getPointID(0), prox))
{
Polyline* tmp = new Polyline((*it)->getPointsVec());
for (size_t k = 0; k < nPoints; k++)
tmp->addPoint((*it)->getPointID(nPoints - k - 1));
size_t new_ply_size(new_ply->getNumberOfPoints());
for (size_t k = 1; k < new_ply_size; k++)
tmp->addPoint(new_ply->getPointID(k));
delete new_ply;
new_ply = tmp;
ply_found = true;
}
// else if (new_ply->getPointID(0) == (*it)->getPointID(nPoints-1))
else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0), (*it)->getPointID(nPoints - 1), prox))
{
Polyline* tmp = new Polyline(**it);
size_t new_ply_size(new_ply->getNumberOfPoints());
for (size_t k = 1; k < new_ply_size; k++)
tmp->addPoint(new_ply->getPointID(k));
delete new_ply;
new_ply = tmp;
ply_found = true;
}
// else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(0))
else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(new_ply->getNumberOfPoints() - 1),
(*it)->getPointID(0), prox))
{
for (size_t k = 1; k < nPoints; k++)
new_ply->addPoint((*it)->getPointID(k));
ply_found = true;
}
// else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(nPoints-1))
else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(new_ply->getNumberOfPoints() - 1),
(*it)->getPointID(nPoints - 1), prox))
{
for (size_t k = 1; k < nPoints; k++)
new_ply->addPoint((*it)->getPointID(nPoints - k - 1));
ply_found = true;
}
if (ply_found)
{
local_ply_vec.erase(it);
break;
}
}
else
std::cout << "Error in Polyline::contructPolylineFromSegments() - Line segments use different point "
"vectors..."
<< "\n";
}
if (!ply_found)
{
std::cout << "Error in Polyline::contructPolylineFromSegments() - Not all segments are connected..."
<< "\n";
new_ply = NULL;
break;
}
}
return new_ply;
}