forked from codysauermann/GeometricDataStructures2D
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine2D.cpp
More file actions
61 lines (49 loc) · 1.65 KB
/
Line2D.cpp
File metadata and controls
61 lines (49 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Line2D.h"
#include "vector"
#include "HalfSegment2D.h"
#include "utility"
#include <algorithm>
using namespace std;
struct Line2D::Impl
{
Impl(){};
Impl(vector<Segment2D> inputLineSegments){};
vector<HalfSegment2D> lineSegments;
void CheckForIntersection();
};
//empty constructor
Line2D::Line2D() {}
//base constructor
Line2D::Line2D(std::vector<Segment2D> &inputLineSegments): pimpl(new Impl())
{
//std::sort(inputLineSegments.begin(), inputLineSegments.end()); //sort input vector to order segments
inputLineSegments.erase(unique(inputLineSegments.begin(), inputLineSegments.end()), inputLineSegments.end()); //remove any duplicate segments
for(int i = 0; i < inputLineSegments.size(); i++)
{
HalfSegment2D domHalfSeg = HalfSegment2D(inputLineSegments[i], true); //set dominant point half segment from segment
this->pimpl->lineSegments.push_back(domHalfSeg);
HalfSegment2D endHalfSeg = HalfSegment2D(inputLineSegments[i], false); //set end point half segment from segment
this->pimpl->lineSegments.push_back(endHalfSeg);
}
sort(this->pimpl->lineSegments.begin(), this->pimpl->lineSegments.end());
}
//copy constructor
Line2D::Line2D(const Line2D &sourceLine2D): pimpl(new Impl(*sourceLine2D.pimpl))
{
}
//move constructor
Line2D::Line2D(Line2D &&sourceLine2D)
{
this->pimpl = move(sourceLine2D.pimpl);
sourceLine2D.pimpl = nullptr;
}
//destructor
Line2D::~Line2D(){}
Line2D::iterator Line2D::begin()
{
return this->pimpl->lineSegments.begin();
}
Line2D::iterator Line2D::end()
{
return this->pimpl->lineSegments.end();
}