wxArt2D
liner.h
Go to the documentation of this file.
1 /*! \file wx/artbase/liner.h
2  \brief basic 2 point line class for intersection and contouring routines.
3  \author Klaas Holwerda
4  \date Created 1/10/2000
5 
6  Copyright: 2000-2004 (c) Klaas Holwerda
7 
8  Licence: wxWidgets Licence
9 
10  RCS-ID: $Id: liner.h,v 1.11 2009/07/06 21:06:29 titato Exp $
11 */
12 #ifndef __WXLINER_H
13 #define __WXLINER_H
14 
15 
16 #include "wx/artbase/afmatrix.h"
17 
18 enum OUTPRODUCT {R_IS_LEFT, R_IS_ON, R_IS_RIGHT};
19 
20 // Status of a point to a a2dLine
21 enum R_PointStatus {R_LEFT_SIDE, R_RIGHT_SIDE, R_ON_AREA, R_IN_AREA};
22 
23 #undef _BB
24 #undef _AA
25 #undef _CC
26 
27 //!Line calculations.
28 /*! A line class to intersect lines and line segments.
29 Next to that the are point on/in Line and Line Segment tests.
30 The class is designed to be accurate and can deal with vertical and horizontal lines.
31 A snap factor (marge) is often required to do proper calculations
32 
33  \ingroup general
34  \ingroup drawer
35 */
36 class A2DARTBASEDLLEXP a2dLine
37 {
38 public:
39 
40  //!create a line with given end and begin point
41  /*!
42  \remark line parameters will not be calculated automatically.
43  \param x1 X begin point
44  \param y1 Y begin point
45  \param x2 X end point
46  \param y2 Y end point
47  */
48  a2dLine( double x1 = 0, double y1 = 0, double x2 = 0, double y2 = 0 );
49 
50  //!create a line with given end and begin point
51  /*!
52  \remark line parameters will not be calculated automatically.
53  \param a begin point
54  \param b end point
55  */
56  a2dLine( const a2dPoint2D& a, const a2dPoint2D& b );
57 
58  a2dLine( const a2dLine& other );
59 
60  //! destructor
61  ~a2dLine();
62 
63  a2dLine& operator = ( const a2dLine& other );
64 
65  //! Get the beginpoint from a a2dLine
66  a2dPoint2D GetBeginPoint() const;
67 
68  //! Get the endpoint from a a2dLine
69  a2dPoint2D GetEndPoint() const;
70 
71  //! Check if two wxLines intersects
72  /*! \param line line to intersect with
73  \param Marge within volume at this distance still an intersection
74  \return true is intersecting
75  */
76  bool CheckIntersect( a2dLine& line, double Marge ) const;
77 
78  //! Intersects two wxLines
79  /*! \param line line to intersect with
80  \param bp beginpoint
81  \param ep endpoint
82  \param Marge within volume at this distance still an intersection
83 
84  \return 0: If there are no crossings
85  1: If there is one crossing
86  2: If there are two crossings
87  */
88  int Intersect( a2dLine& line, a2dPoint2D& bp , a2dPoint2D& ep , double Marge ) const;
89 
90  //!intersect two (infinit) lines
91  bool Intersect( a2dLine& lijn, a2dPoint2D& crossing ) const;
92 
93  //!For an infinite a2dLine
94  R_PointStatus PointOnLine( const a2dPoint2D& a_Point, double& Distance, double Marge ) const;
95 
96  //!For a non-infinite a2dLine
97  R_PointStatus PointInLine( const a2dPoint2D& a_Point, double& Distance, double Marge ) const;
98 
99  //! return point after projecting p to this line.
100  a2dPoint2D ProjectedPoint( const a2dPoint2D& p ) const;
101 
102  //!Calculate the distance of a point from the line. Works even if l==0
103  /*!\param p the point to which the closest point on the line is searched
104  \param nearest if not 0, the closest point to p on the line is assigned to nearest
105  */
106  double PointDistance( const a2dPoint2D& p, a2dPoint2D* nearest ) const;
107 
108  //!Calculate the orthogonal distance of a point from the line. Works even if l==0
109  /*!\param p the point to which the closest point on the line is searched
110  \param nearest if not 0, the closest point to p on the line is assigned to nearest
111  */
112  double PointDistanceOrhto( const a2dPoint2D& p, a2dPoint2D* nearest ) const;
113 
114  //! outproduct of two wxLines
115  OUTPRODUCT OutProduct( const a2dLine& two, double accur ) const;
116 
117  //! Caclulate Y if X is known
118  double Calculate_Y( double X ) const;
119 
120  //!calculate point Perpendicula at distance from the line, through given point
121  void Virtual_Point( a2dPoint2D& a_point, double distance ) const;
122 
123  //!calculate point on line at distance from the begin or end of line
124  a2dPoint2D DistancePoint( double distance, bool begin ) const;
125 
126  //! create a line through a_point and which is pperpendicular to this
127  a2dLine* CreatePerpendicularLineAt( const a2dPoint2D& a_point ) const;
128 
129  //! Calculate the parameters if invalid
130  void CalculateLineParameters();
131 
132  //!Calculate point for a contour at a given distance
133  void OffsetContour( const a2dLine& nextline, double factor, a2dPoint2D& offsetpoint ) const;
134 
135  //! return length of vector
136  double GetLength() const;
137 
138 private:
139 
140  //! Function needed for Intersect
141  int ActionOnTable1( R_PointStatus, R_PointStatus ) const;
142 
143  //! Function needed for Intersect
144  int ActionOnTable2( R_PointStatus, R_PointStatus ) const;
145 
146 
147  //! delta y (normalized by length)
148  double m_AA;
149 
150  //! delta x (normalized by length)
151  double m_BB;
152 
153  //! vector (normalized by length)
154  double m_CC;
155 
156  //!beginpoint
157  a2dPoint2D m_a;
158 
159  //! end point
160  a2dPoint2D m_b;
161 
162  //! are the line parameters valid
163  bool m_valid_parameters;
164 };
165 
166 #endif
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
Definition: artglob.h:47
Line calculations.
Definition: liner.h:36
affine matrix class
liner.h Source File -- Sun Oct 12 2014 17:04:22 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation