libMVRgdtf 40bc00a
A library for GDTF and MVR
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VWLine2D.h
Go to the documentation of this file.
1//
2// Copyright Nemetschek Vectorworks, Inc.
3// Use of this file is governed by the Nemetschek Vectorworks SDK License Agreement
4// http://developer.vectorworks.net/index.php?title=Vectorworks_SDK_License
5//
6
7#ifndef VECTORWORKS_LINE_2D__H
8#define VECTORWORKS_LINE_2D__H
9
10#pragma once
11
12namespace VectorworksMVR
13{
14 namespace VWFC
15 {
16 namespace Math
17 {
19 {
20 public:
21 VWLine2D();
22 VWLine2D(double x1, double y1, double x2, double y2);
23 VWLine2D(const VWPoint2D& begPt, const VWPoint2D& endPt);
24 VWLine2D(const VWLine2D& src);
25 virtual ~VWLine2D();
26
27 VWLine2D& operator=(const VWLine2D& src);
28
29 const VWPoint2D& GetStart() const;
31 const VWPoint2D& GetEnd() const;
33 void GetLine(VWPoint2D& outPtStart, VWPoint2D& outPtEnd) const;
34
35
36 void SetStart(const VWPoint2D& pt);
37 void SetEnd(const VWPoint2D& pt);
38 void SetLine(double x1, double y1, double x2, double y2);
39 void SetLine(const VWPoint2D& ptStart, const VWPoint2D& ptEnd);
40
41 void ReverseSides();
42
43 VWLine2D operator+(const VWPoint2D& p) const;
44 VWLine2D operator-(const VWPoint2D& p) const;
45 VWLine2D operator*(double scalar) const;
46 VWLine2D operator/(double scalar) const;
47
48 VWLine2D& operator+=(const VWPoint2D& p);
49 VWLine2D& operator-=(const VWPoint2D& p);
50 VWLine2D& operator*=(double scalar);
51 VWLine2D& operator/=(double scalar);
52
53 // math functions
54 public:
55 // return the center point of the line
56 VWPoint2D CenterPt() const;
57 // return the length of the line
58 double GetLength() const;
59 // calculate the line equation
60 void CalcLineEquation(double& outA, double& outB, double& outC) const;
61 // return true if the specified point is on the line within an epsilon
62 bool PtOnLine(const VWPoint2D& pt, double dEpsilon) const;
63 bool PtOnLineStart(const VWPoint2D& pt, double dEpsilon) const;
64 bool PtOnLineEnd(const VWPoint2D& pt, double dEpsilon) const;
65 bool PtOnLinePoints(const VWPoint2D& pt, double dEpsilon) const;
66 // checks if point is on left side of the line.
67 bool PtOnLeft(const VWPoint2D& pt) const;
68 // get the angle 0 .. 90 from this line to the specified line
69 double GetAngle90(const VWLine2D& line) const;
70 // return direction of the line: normal vector (b - a)
71 VWPoint2D GetDirection() const;
72 // teturns a point on this line which is closest to the input point.
73 VWPoint2D PtPerpLine(double x, double y) const;
74 VWPoint2D PtPerpLine(const VWPoint2D& pt) const;
75 // returns the closest point to this line segment or the closest end
76 VWPoint2D PtPerpLineSeg(const VWPoint2D& pt) const;
77 // returns the closest point to this line segment or the closest segment end, also returns the squared distance to the found point.
78 VWPoint2D PtPerpLineSeg(const VWPoint2D& pt, double& outSqrDist) const;
79 // return the distance from the specified point to the line
80 double Distance(double x, double y) const;
81 double Distance(const VWPoint2D& pt) const;
82 double DistanceSeg(const VWPoint2D& pt) const;
83 // intersect the infinite lines. The result point can be outside the line segments
84 // return false if the lines are parallel
85 bool IntersectLines(const VWLine2D& line, VWPoint2D& outIntersPt) const;
86 bool IntersectLines(const VWPoint2D& a, const VWPoint2D& b, VWPoint2D& outIntersPt) const;
87 // intersect the infinite lines. The result point can be outside the line segments
88 // return false if the lines are parallel
89 // outPtOnLineSegs returns true if the intersection point lies on both line segments
90 bool IntersectLines(const VWLine2D& line, VWPoint2D& outIntersPt, bool& outPtOnLineSegs) const;
91 bool IntersectLines(const VWPoint2D& a, const VWPoint2D& b, VWPoint2D& outIntersPt, bool& outPtOnLineSegs) const;
92 // interset the line segments.
93 // return false if the lines are parallel or the line segments
94 // doest intersect each oter in the bound of the segments
95 bool IntersectLineSegments(const VWLine2D& line, VWPoint2D& outIntersPt) const;
96 bool IntersectLineSegments(const VWPoint2D& a, const VWPoint2D& b, VWPoint2D& outIntersPt) const;
97 // only check if line segments intersect. for faster check.
98 bool AreLineSegmentsIntersecting(const VWLine2D& line, double dEpsilon) const;
99 bool AreLineSegmentsIntersecting(const VWPoint2D& a, const VWPoint2D& b, double dEpsilon) const;
100 bool AreLineSegmentsIntersecting(const VWLine2D& line, VWPoint2D& outIntersPt, bool& outParallel, double epsilon) const;
101 // return translated point into a coordinate system defined by this line.
102 VWPoint2D RelativeCoords(const VWPoint2D& pt) const;
103 // rotate this point at specified angle in degrees and center point
104 void RotateAtDeg(const VWPoint2D& centerPt, double_gs dDegAngle);
105 // rotate this point at specified angle in radians and center point
106 void RotateAtRad(const VWPoint2D& centerPt, double_gs dRadAngle);
107 // return true if the specified two points are on the same side of the line
108 bool AreOnSameSide(double x1, double y1, double x2, double y2);
109 bool AreOnSameSide(const VWPoint2D& a, const VWPoint2D& b);
110
111 // Boolean Functions
112 bool Subtract(const VWLine2D& tool, std::vector<VWLine2D> results) const;
113
114 // Tools
115 public:
116 static bool PtOnLine(const VWPoint2D& pt, const VWPoint2D& lineA, const VWPoint2D& lineB, double dEpsilon);
117 static void IntersectLines(const VWPoint2D& p1, const VWPoint2D& p2, const VWPoint2D& p3, const VWPoint2D& p4, VWPoint2D& outInters, bool& outParallel, bool& outOnSegment1, bool& outOnSegment2);
118 static void IntersectLines(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double& outIntersX, double& outIntersY, bool& outParallel, bool& outOnSegment1, bool& outOnSegment2, double dEpsilon);
119 static void IntersectLines(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double& outIntersX, double& outIntersY, bool& outParallel, bool& outOnSeg1Pt1, bool& outOnSeg1Pt2, bool& outOnSegment1, bool& outOnSegment2, double epsilon);
120 static void IntersectLines(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double& outIntersX, double& outIntersY, bool& outParallel, bool& outOnSeg1Pt1, bool& outOnSeg1Pt2, bool& outOnSegment1, bool& outOnSegment2, double epsCoord, double epsCollinear);
121 static void IntersectLines(const VWPoint2D& a1, const VWPoint2D& a2, const VWPoint2D& b1, const VWPoint2D& b2, bool& intersect, bool& parallel, VWPoint2D& int0, double epsilon);
122 static void IntersectLines(const VWPoint2D& pt1, const VWPoint2D& pt2, const VWPoint2D& pt3, const VWPoint2D& pt4, VWLine2D& outIntersLine, bool& outParallel, bool& outOnSeg1, bool& outOnSeg2, double epsCoord, double epsCollinear);
123 // only check if line segments intersect. for faster check.
124 static bool AreLineSegmentsIntersecting(const VWPoint2D& p1, const VWPoint2D& p2, const VWPoint2D& p3, const VWPoint2D& p4, double dEpsilon);
125 static bool AreLineSegmentsIntersecting(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double dEpsilon);
126 static bool AreLineSegmentsIntersecting(const VWPoint2D& p1, const VWPoint2D& p2, const VWPoint2D& p3, const VWPoint2D& p4, VWPoint2D& outIntersPt, bool& outParallel, double epsilon);
127 static bool AreLineSegmentsIntersecting(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double& outIntersX, double& outIntersY, bool& outParallel, double epsilon);
128 // distance from point (x0,y0) to line [(x1,y1)(x2,y2)]
129 static double Distance(double x0, double y0, double x1, double y1, double x2, double y2 );
130 // check for intersection between bounding boxes of line segments.
131 static bool DoLineSegmentsBoundsIntersect(const VWPoint2D& p1, const VWPoint2D& p2, const VWPoint2D& p3, const VWPoint2D& p4, double epsilon);
132 static bool DoLineSegmentsBoundsIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double epsilon);
133 // returns the closest point to the line segment or the closest segment end, also returns the squared distance to the found point.
134 static VWPoint2D PtPerpLineSeg(const VWPoint2D& pt, const VWPoint2D& lnPt0, const VWPoint2D& lnPt1, double& outSqrDist);
135 // returns the closest point to the line segment. it is a optimized/faster version which uses squared length.
136 static void PtPerpLine(double pX, double pY, double l1X, double l1Y, double l2X, double l2Y, double& outProjX, double& outProjY);
137 // checks if point is on left side of the line defined by two points.
138 static bool PtOnLeftOfLine(const VWPoint2D& pt, const VWPoint2D& lnPt0, const VWPoint2D& lnPt1);
139 // checks if point is on left side of the ray defined by ray point and vector.
140 static bool PtOnLeftOfRay(const VWPoint2D& pt, const VWPoint2D& rayPt, const VWPoint2D& rayVec);
141
142 protected:
145 };
146
147 // array of lines definition.
148 typedef std::vector<VWLine2D> TSTLLines2DArray;
149 }
150 }
151}
152
153#endif // VECTORWORKS_LINE_2D__H
Definition VWLine2D.h:19
static bool DoLineSegmentsBoundsIntersect(const VWPoint2D &p1, const VWPoint2D &p2, const VWPoint2D &p3, const VWPoint2D &p4, double epsilon)
Definition VWLine2D.cpp:777
VWPoint2D GetDirection() const
Definition VWLine2D.cpp:293
VWLine2D operator-(const VWPoint2D &p) const
Definition VWLine2D.cpp:106
bool PtOnLinePoints(const VWPoint2D &pt, double dEpsilon) const
Definition VWLine2D.cpp:242
double DistanceSeg(const VWPoint2D &pt) const
Definition VWLine2D.cpp:354
bool PtOnLineStart(const VWPoint2D &pt, double dEpsilon) const
Definition VWLine2D.cpp:232
double Distance(double x, double y) const
Definition VWLine2D.cpp:339
double GetLength() const
Definition VWLine2D.cpp:216
VWLine2D operator+(const VWPoint2D &p) const
Definition VWLine2D.cpp:99
VWLine2D & operator-=(const VWPoint2D &p)
Definition VWLine2D.cpp:184
void GetLine(VWPoint2D &outPtStart, VWPoint2D &outPtEnd) const
Definition VWLine2D.cpp:62
bool PtOnLineEnd(const VWPoint2D &pt, double dEpsilon) const
Definition VWLine2D.cpp:237
VWLine2D operator*(double scalar) const
Definition VWLine2D.cpp:163
VWLine2D & operator+=(const VWPoint2D &p)
Definition VWLine2D.cpp:177
void RotateAtDeg(const VWPoint2D &centerPt, double_gs dDegAngle)
Definition VWLine2D.cpp:459
static void IntersectLines(const VWPoint2D &pt1, const VWPoint2D &pt2, const VWPoint2D &pt3, const VWPoint2D &pt4, VWLine2D &outIntersLine, bool &outParallel, bool &outOnSeg1, bool &outOnSeg2, double epsCoord, double epsCollinear)
bool Subtract(const VWLine2D &tool, std::vector< VWLine2D > results) const
Definition VWLine2D.cpp:113
bool AreOnSameSide(double x1, double y1, double x2, double y2)
Definition VWLine2D.cpp:366
double GetAngle90(const VWLine2D &line) const
Definition VWLine2D.cpp:276
VWPoint2D CenterPt() const
Definition VWLine2D.cpp:210
static bool PtOnLeftOfRay(const VWPoint2D &pt, const VWPoint2D &rayPt, const VWPoint2D &rayVec)
Definition VWLine2D.cpp:886
VWLine2D & operator/=(double scalar)
Definition VWLine2D.cpp:198
const VWPoint2D & GetStart() const
Definition VWLine2D.cpp:42
VWPoint2D PtPerpLineSeg(const VWPoint2D &pt) const
Definition VWLine2D.cpp:315
VWLine2D & operator=(const VWLine2D &src)
Definition VWLine2D.cpp:35
bool PtOnLine(const VWPoint2D &pt, double dEpsilon) const
Definition VWLine2D.cpp:254
const VWPoint2D & GetEnd() const
Definition VWLine2D.cpp:52
void SetStart(const VWPoint2D &pt)
Definition VWLine2D.cpp:68
bool AreLineSegmentsIntersecting(const VWLine2D &line, double dEpsilon) const
Definition VWLine2D.cpp:433
bool PtOnLeft(const VWPoint2D &pt) const
Definition VWLine2D.cpp:248
void SetLine(double x1, double y1, double x2, double y2)
Definition VWLine2D.cpp:78
VWLine2D operator/(double scalar) const
Definition VWLine2D.cpp:170
VWPoint2D PtPerpLine(double x, double y) const
Definition VWLine2D.cpp:310
VWPoint2D m_ptStart
Definition VWLine2D.h:143
virtual ~VWLine2D()
Definition VWLine2D.cpp:31
VWPoint2D m_ptEnd
Definition VWLine2D.h:144
void RotateAtRad(const VWPoint2D &centerPt, double_gs dRadAngle)
Definition VWLine2D.cpp:466
VWLine2D & operator*=(double scalar)
Definition VWLine2D.cpp:191
void ReverseSides()
Definition VWLine2D.cpp:92
static bool PtOnLeftOfLine(const VWPoint2D &pt, const VWPoint2D &lnPt0, const VWPoint2D &lnPt1)
Definition VWLine2D.cpp:880
VWPoint2D RelativeCoords(const VWPoint2D &pt) const
Definition VWLine2D.cpp:451
bool IntersectLineSegments(const VWLine2D &line, VWPoint2D &outIntersPt) const
Definition VWLine2D.cpp:418
bool IntersectLines(const VWLine2D &line, VWPoint2D &outIntersPt) const
Definition VWLine2D.cpp:382
VWLine2D()
Definition VWLine2D.cpp:11
void SetEnd(const VWPoint2D &pt)
Definition VWLine2D.cpp:73
void CalcLineEquation(double &outA, double &outB, double &outC) const
Definition VWLine2D.cpp:221
Definition VWPoint2D.h:17
std::vector< VWLine2D > TSTLLines2DArray
Definition VWLine2D.h:148
Definition CieColor.h:9
Real64 double_gs
Definition MCFloat.h:35