From 2889470d8cad29bdc971f98e7a417563dc2746eb Mon Sep 17 00:00:00 2001 From: Michalis Chaviaras Date: Wed, 6 May 2020 15:24:45 +0300 Subject: [PATCH 1/2] In test1.cpp union and differentiation never showed. Because of the changes in the polygons to show the intersections. --- PolyUtils.h | 1 + test1.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/PolyUtils.h b/PolyUtils.h index 3c791c0..7e894e9 100644 --- a/PolyUtils.h +++ b/PolyUtils.h @@ -1,5 +1,6 @@ #pragma once #include +#include /** * All of necessary data structures are defined here diff --git a/test1.cpp b/test1.cpp index b53cb18..835584c 100644 --- a/test1.cpp +++ b/test1.cpp @@ -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)) { @@ -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)) @@ -129,4 +130,4 @@ int main() return 0; -} +} \ No newline at end of file From c1391dd25373ed8b63557cce3a0a051fac03b56e Mon Sep 17 00:00:00 2001 From: Michalis Chaviaras Date: Wed, 6 May 2020 15:29:27 +0300 Subject: [PATCH 2/2] fix also the test2 in order to run as the test1.cpp --- test2.cpp | 230 +++++++++++++++++++++++++++--------------------------- 1 file changed, 116 insertions(+), 114 deletions(-) diff --git a/test2.cpp b/test2.cpp index 078e8fc..e4efa02 100644 --- a/test2.cpp +++ b/test2.cpp @@ -5,117 +5,119 @@ //* ----------------------------------------------------- //* Here is an inside example //*/ -// -//#include "PolyUtils.h" -//#include "PolygonClipping.h" -//#include -// -// -//int main() -//{ -// std::vector 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 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> possible_result; -// if (PolyClip::PloygonOpration::Mark(polygon1, polygon2, possible_result, PolyClip::MarkIntersection)) -// { -// std::vector> results = PolyClip::PloygonOpration::ExtractIntersectionResults(polygon1); -// for (int i = 0; i> results = PolyClip::PloygonOpration::ExtractUnionResults(poly1); -// for (int i = 0; i> results = PolyClip::PloygonOpration::ExtractDifferentiateResults(pol1); -// for (int i = 0; i + + +int main() +{ + std::vector 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 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> possible_result; + if (PolyClip::PloygonOpration::Mark(polygon1, polygon2, possible_result, PolyClip::MarkIntersection)) + { + std::vector> results = PolyClip::PloygonOpration::ExtractIntersectionResults(polygon1); + for (int i = 0; i> results = PolyClip::PloygonOpration::ExtractUnionResults(poly1); + for (int i = 0; i> results = PolyClip::PloygonOpration::ExtractDifferentiateResults(pol1); + for (int i = 0; i