1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BGFX_POINT_B2DHOMPOINT_HXX
25 #define _BGFX_POINT_B2DHOMPOINT_HXX
26 
27 #include <basegfx/point/b2dpoint.hxx>
28 
29 namespace basegfx
30 {
31 	/** Basic homogen Point class with two double values and one homogen factor
32 
33 		This class provides access to homogen coordinates in 2D.
34 		For this purpose all the operators which need to do specific
35 		action due to their homogenity are implemented here.
36 		The only caveat are member methods which are declared as const
37 		but do change the content. These are documented for that reason.
38 		The class is designed to provide homogenous coordinates without
39 		direct access to the homogen part (mfW). This is also the reason
40 		for leaving out the [] operators which return references to members.
41 
42 		@see B2DTuple
43 	*/
44 	class B2DHomPoint
45 	{
46 	protected:
47 		/// This member contains the coordinate part of the point
48 		::basegfx::B2DTuple					maTuple;
49 
50 		/// This Member holds the homogenous part of the point
51 		double										mfW;
52 
53 		/**	Test if this homogen point does have a homogenous part
54 
55 			@return Returns true if this point has no homogenous part
56 		*/
57 		bool implIsHomogenized() const;
58 
59 		/**	Remove homogenous part of this Point
60 
61 			This method does necessary calculations to remove
62 			the evtl. homogenous part of this Point. This may
63 			change all members.
64 		*/
65 		void implHomogenize();
66 
67 		/**	Test and on demand remove homogenous part
68 
69 			This method tests if this Point does have a homogenous part
70 			and then evtl. takes actions to remove that part.
71 
72 			@attention Even when this method is const it may change all
73 			members of this instance. This is due to the fact that changing
74 			the homogenous part of a homogenous point does from a mathematical
75 			point of view not change the point at all.
76 		*/
77 		void implTestAndHomogenize() const;
78 
79 	public:
80 		/**	Create a homogen point
81 
82         	The point is initialized to (0.0, 0.0)
83 		*/
84 		B2DHomPoint()
85 		:	maTuple(),
86 			mfW(1.0)
87 		{}
88 
89 		/**	Create a homogen point
90 
91 			@param fX
92 			This parameter is used to initialize the X-coordinate
93 			of the Point. The homogenous part is initialized to 1.0.
94 
95 			@param fY
96 			This parameter is used to initialize the Y-coordinate
97 			of the Point. The homogenous part is initialized to 1.0.
98 		*/
99 		B2DHomPoint(double fX, double fY)
100 		:	maTuple(fX, fY),
101 			mfW(1.0)
102 		{}
103 
104 		/**	Create a copy of a 2D Point
105 
106 			@param rVec
107 			The 2D point which will be copied. The homogenous part
108 			is initialized to 1.0.
109 		*/
110 		B2DHomPoint(const B2DPoint& rVec)
111 		:	maTuple(rVec),
112 			mfW(1.0)
113 		{}
114 
115 		/**	Create a copy of a homogen point
116 
117 			@param rVec
118 			The homogen point which will be copied. The homogenous part
119 			is copied, too.
120 		*/
121 		B2DHomPoint(const B2DHomPoint& rVec)
122 		:	maTuple(rVec.maTuple.getX(), rVec.maTuple.getY()),
123 			mfW(rVec.mfW)
124 		{}
125 
126 		~B2DHomPoint()
127 		{}
128 
129 		/**	Get a 2D point from this homogenous point
130 
131 			This method normalizes this homogen point if necessary and
132 			returns the corresponding 2D point for this homogen point.
133 
134 			@attention Even when this method is const it may change all
135 			members of this instance.
136 		*/
137 		B2DPoint getB2DPoint() const;
138 
139 		/**	Get X-coordinate
140 
141 			This method normalizes this homogen point if necessary and
142 			returns the corresponding X-coordinate for this homogen point.
143 
144 			@attention Even when this method is const it may change all
145 			members of this instance.
146 		*/
147 		double getX() const;
148 
149 		/**	Get Y-coordinate
150 
151 			This method normalizes this homogen point if necessary and
152 			returns the corresponding Y-coordinate for this homogen point.
153 
154 			@attention Even when this method is const it may change all
155 			members of this instance.
156 		*/
157 		double getY() const;
158 
159 		/**	Set X-coordinate of the homogen point.
160 
161 			This method sets the X-coordinate of the homogen point. If
162 			the point does have a homogenous part this is taken into account.
163 
164 			@param fX
165 			The to-be-set X-coordinate without homogenous part.
166 		*/
167 		void setX(double fX);
168 
169 		/**	Set Y-coordinate of the homogen point.
170 
171 			This method sets the Y-coordinate of the homogen point. If
172 			the point does have a homogenous part this is taken into account.
173 
174 			@param fY
175 			The to-be-set Y-coordinate without homogenous part.
176 		*/
177 		void setY(double fY);
178 
179 		// operators
180 		//////////////////////////////////////////////////////////////////////
181 
182 		B2DHomPoint& operator+=( const B2DHomPoint& rPnt );
183 
184 		B2DHomPoint& operator-=( const B2DHomPoint& rPnt );
185 
186 		B2DHomPoint& operator*=(double t);
187 
188 		B2DHomPoint& operator*=( const B2DHomMatrix& rMat );
189 
190 		B2DHomPoint& operator/=(double t);
191 
192 		B2DHomPoint& operator-(void);
193 
194 		bool operator==( const B2DHomPoint& rPnt ) const;
195 
196 		bool operator!=( const B2DHomPoint& rPnt ) const;
197 
198 		B2DHomPoint& operator=( const B2DHomPoint& rPnt );
199 	};
200 
201 	// external operators
202 	//////////////////////////////////////////////////////////////////////////
203 
204 	B2DHomPoint minimum(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB);
205 
206 	B2DHomPoint maximum(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB);
207 
208 	B2DHomPoint absolute(const B2DHomPoint& rVec);
209 
210 	B2DHomPoint interpolate(B2DHomPoint& rOld1, B2DHomPoint& rOld2, double t);
211 
212 	B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2);
213 
214 	B2DHomPoint average(B2DHomPoint& rOld1, B2DHomPoint& rOld2, B2DHomPoint& rOld3);
215 
216 	B2DHomPoint operator+(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB);
217 
218 	B2DHomPoint operator-(const B2DHomPoint& rVecA, const B2DHomPoint& rVecB);
219 
220 	B2DHomPoint operator*(const B2DHomPoint& rVec, double t);
221 
222 	B2DHomPoint operator*(double t, const B2DHomPoint& rVec);
223 
224 	B2DHomPoint operator*( const B2DHomMatrix& rMat, const B2DHomPoint& rPoint );
225 
226 	B2DHomPoint operator/(const B2DHomPoint& rVec, double t);
227 
228 	B2DHomPoint operator/(double t, const B2DHomPoint& rVec);
229 } // end of namespace basegfx
230 
231 #endif /* _BGFX_POINT_B2DHOMPOINT_HXX */
232