Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PolyUtils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <vector>
#include <cstdlib>

/**
* All of necessary data structures are defined here
Expand Down
13 changes: 7 additions & 6 deletions test1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ int main()

std::cout << "\n#################### Union #####################\n";
possible_result.clear();
PolyClip::Polygon poly1 = polygon1;
PolyClip::Polygon poly2 = polygon2;

PolyClip::Polygon poly1(vertices1);
// = polygon1;
PolyClip::Polygon poly2(vertices2);
// = polygon2;
PolyClip::PloygonOpration::DetectIntersection(poly1, poly2);
if (PolyClip::PloygonOpration::Mark(poly1, poly2, possible_result, PolyClip::MarkUnion))
{
Expand Down Expand Up @@ -98,8 +99,8 @@ int main()

std::cout << "\n#################### Differentiate #####################\n";
possible_result.clear();
PolyClip::Polygon pol1 = polygon1;
PolyClip::Polygon pol2 = polygon2;
PolyClip::Polygon pol1(vertices1);
PolyClip::Polygon pol2(vertices2);

PolyClip::PloygonOpration::DetectIntersection(pol1, pol2);
if (PolyClip::PloygonOpration::Mark(pol1, pol2, possible_result, PolyClip::MarkDifferentiate))
Expand Down Expand Up @@ -129,4 +130,4 @@ int main()


return 0;
}
}
230 changes: 116 additions & 114 deletions test2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,117 +5,119 @@
//* -----------------------------------------------------
//* Here is an inside example
//*/
//
//#include "PolyUtils.h"
//#include "PolygonClipping.h"
//#include <iostream>
//
//
//int main()
//{
// std::vector<PolyClip::Point2d> vertices1;
// vertices1.push_back(PolyClip::Point2d(10.0, 10.0));
// vertices1.push_back(PolyClip::Point2d(10.0, 100.0));
// vertices1.push_back(PolyClip::Point2d(100.0, 100.0));
// vertices1.push_back(PolyClip::Point2d(100.0, 10.0));
// PolyClip::Polygon polygon1(vertices1);
//
// std::vector<PolyClip::Point2d> vertices2;
// vertices2.push_back(PolyClip::Point2d(20, 20.0));
// vertices2.push_back(PolyClip::Point2d(20, 80.0));
// vertices2.push_back(PolyClip::Point2d(80, 80.0));
// PolyClip::Polygon polygon2(vertices2);
//
//
// std::cout << "#################### Intersection #####################\n";
// PolyClip::PloygonOpration::DetectIntersection(polygon1, polygon2);
// std::vector<std::vector<PolyClip::Point2d>> possible_result;
// if (PolyClip::PloygonOpration::Mark(polygon1, polygon2, possible_result, PolyClip::MarkIntersection))
// {
// std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractIntersectionResults(polygon1);
// for (int i = 0; i<results.size(); ++i)
// {
// for (auto p : results[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// else
// {
// if (possible_result.size() == 0)
// std::cout << "No intersection\n";
// else
// {
// for (int i = 0; i<possible_result.size(); ++i)
// {
// for (auto p : possible_result[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// }
//
// std::cout << "\n#################### Union #####################\n";
// possible_result.clear();
// PolyClip::Polygon poly1 = polygon1;
// PolyClip::Polygon poly2 = polygon2;
//
// PolyClip::PloygonOpration::DetectIntersection(poly1, poly2);
// if (PolyClip::PloygonOpration::Mark(poly1, poly2, possible_result, PolyClip::MarkUnion))
// {
// std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractUnionResults(poly1);
// for (int i = 0; i<results.size(); ++i)
// {
// for (auto p : results[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// else
// {
// if (possible_result.size() == 0)
// std::cout << "No intersection\n";
// else
// {
// for (int i = 0; i<possible_result.size(); ++i)
// {
// for (auto p : possible_result[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// }
//
// std::cout << "\n#################### Differentiate #####################\n";
// possible_result.clear();
// PolyClip::Polygon pol1 = polygon1;
// PolyClip::Polygon pol2 = polygon2;
//
// PolyClip::PloygonOpration::DetectIntersection(pol1, pol2);
// if (PolyClip::PloygonOpration::Mark(pol1, pol2, possible_result, PolyClip::MarkDifferentiate))
// {
// std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractDifferentiateResults(pol1);
// for (int i = 0; i<results.size(); ++i)
// {
// for (auto p : results[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// else
// {
// if (possible_result.size() == 0)
// std::cout << "No intersection\n";
// else
// {
// for (int i = 0; i<possible_result.size(); ++i)
// {
// for (auto p : possible_result[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// }
//
// return 0;
//}

#include "PolyUtils.h"
#include "PolygonClipping.h"
#include <iostream>


int main()
{
std::vector<PolyClip::Point2d> vertices1;
vertices1.push_back(PolyClip::Point2d(10.0, 10.0));
vertices1.push_back(PolyClip::Point2d(10.0, 100.0));
vertices1.push_back(PolyClip::Point2d(100.0, 100.0));
vertices1.push_back(PolyClip::Point2d(100.0, 10.0));
PolyClip::Polygon polygon1(vertices1);

std::vector<PolyClip::Point2d> vertices2;
vertices2.push_back(PolyClip::Point2d(20, 20.0));
vertices2.push_back(PolyClip::Point2d(20, 80.0));
vertices2.push_back(PolyClip::Point2d(80, 80.0));
PolyClip::Polygon polygon2(vertices2);


std::cout << "#################### Intersection #####################\n";
PolyClip::PloygonOpration::DetectIntersection(polygon1, polygon2);
std::vector<std::vector<PolyClip::Point2d>> possible_result;
if (PolyClip::PloygonOpration::Mark(polygon1, polygon2, possible_result, PolyClip::MarkIntersection))
{
std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractIntersectionResults(polygon1);
for (int i = 0; i<results.size(); ++i)
{
for (auto p : results[i])
std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
std::cout << "\n";
}
}
else
{
if (possible_result.size() == 0)
std::cout << "No intersection\n";
else
{
for (int i = 0; i<possible_result.size(); ++i)
{
for (auto p : possible_result[i])
std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
std::cout << "\n";
}
}
}

std::cout << "\n#################### Union #####################\n";
possible_result.clear();
PolyClip::Polygon poly1(vertices1);
// = polygon1;
PolyClip::Polygon poly2(vertices2);
// = polygon2;
PolyClip::PloygonOpration::DetectIntersection(poly1, poly2);
if (PolyClip::PloygonOpration::Mark(poly1, poly2, possible_result, PolyClip::MarkUnion))
{
std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractUnionResults(poly1);
for (int i = 0; i<results.size(); ++i)
{
for (auto p : results[i])
std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
std::cout << "\n";
}
}
else
{
if (possible_result.size() == 0)
std::cout << "No intersection\n";
else
{
for (int i = 0; i<possible_result.size(); ++i)
{
for (auto p : possible_result[i])
std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
std::cout << "\n";
}
}
}

std::cout << "\n#################### Differentiate #####################\n";
possible_result.clear();
PolyClip::Polygon pol1(vertices1);
// = polygon1;
PolyClip::Polygon pol2(vertices2);
// = polygon2;
PolyClip::PloygonOpration::DetectIntersection(pol1, pol2);
if (PolyClip::PloygonOpration::Mark(pol1, pol2, possible_result, PolyClip::MarkDifferentiate))
{
std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractDifferentiateResults(pol1);
for (int i = 0; i<results.size(); ++i)
{
for (auto p : results[i])
std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
std::cout << "\n";
}
}
else
{
if (possible_result.size() == 0)
std::cout << "No intersection\n";
else
{
for (int i = 0; i<possible_result.size(); ++i)
{
for (auto p : possible_result[i])
std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
std::cout << "\n";
}
}
}

return 0;
}