1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _BGFX_VECTOR_B2IVECTOR_HXX
29 #define _BGFX_VECTOR_B2IVECTOR_HXX
30 
31 #include <basegfx/tuple/b2ituple.hxx>
32 #include <basegfx/vector/b2enums.hxx>
33 
34 namespace basegfx
35 {
36 	// predeclaration
37 	class B2DHomMatrix;
38 
39 	/** Base Point class with two sal_Int32 values
40 
41 		This class derives all operators and common handling for
42 		a 2D data class from B2ITuple. All necessary extensions
43 		which are special for 2D Vectors are added here.
44 
45 		@see B2ITuple
46 	*/
47 	class B2IVector : public ::basegfx::B2ITuple
48 	{
49 	public:
50 		/**	Create a 2D Vector
51 
52         	The vector is initialized to (0, 0)
53 		*/
54 		B2IVector()
55 		:	B2ITuple()
56 		{}
57 
58 		/**	Create a 2D Vector
59 
60 			@param nX
61 			This parameter is used to initialize the X-coordinate
62 			of the 2D Vector.
63 
64 			@param nY
65 			This parameter is used to initialize the Y-coordinate
66 			of the 2D Vector.
67 		*/
68 		B2IVector(sal_Int32 nX, sal_Int32 nY)
69 		:	B2ITuple(nX, nY)
70 		{}
71 
72 		/**	Create a copy of a 2D Vector
73 
74 			@param rVec
75 			The 2D Vector which will be copied.
76 		*/
77 		B2IVector(const B2IVector& rVec)
78 		:	B2ITuple(rVec)
79 		{}
80 
81 		/** constructor with tuple to allow copy-constructing
82 			from B2ITuple-based classes
83 		*/
84 		B2IVector(const ::basegfx::B2ITuple& rTuple)
85 		:	B2ITuple(rTuple)
86 		{}
87 
88 		~B2IVector()
89 		{}
90 
91 		/** *=operator to allow usage from B2IVector, too
92 		*/
93 		B2IVector& operator*=( const B2IVector& rPnt )
94 		{
95 			mnX *= rPnt.mnX;
96 			mnY *= rPnt.mnY;
97 			return *this;
98 		}
99 
100 		/** *=operator to allow usage from B2IVector, too
101 		*/
102 		B2IVector& operator*=(sal_Int32 t)
103 		{
104 			mnX *= t;
105 			mnY *= t;
106 			return *this;
107 		}
108 
109 		/** assignment operator to allow assigning the results
110 			of B2ITuple calculations
111 		*/
112 		B2IVector& operator=( const ::basegfx::B2ITuple& rVec );
113 
114 		/** Calculate the length of this 2D Vector
115 
116 			@return The Length of the 2D Vector
117 		*/
118 		double getLength() const;
119 
120 		/** Set the length of this 2D Vector
121 
122 			@param fLen
123 			The to be achieved length of the 2D Vector
124 		*/
125 		B2IVector& setLength(double fLen);
126 
127 		/** Calculate the Scalar with another 2D Vector
128 
129 			@param rVec
130 			The second 2D Vector
131 
132 			@return
133 			The Scalar value of the two involved 2D Vectors
134 		*/
135 		double scalar( const B2IVector& rVec ) const;
136 
137 		/** Calculate the length of the cross product with another 2D Vector
138 
139             In 2D, returning an actual vector does not make much
140             sense here. The magnitude, although, can be readily
141             used for tasks such as angle calculations, since for
142             the returned value, the following equation holds:
143             retVal = getLength(this)*getLength(rVec)*sin(theta),
144             with theta being the angle between the two vectors.
145 
146 			@param rVec
147 			The second 2D Vector
148 
149 			@return
150 			The length of the cross product of the two involved 2D Vectors
151 		*/
152 		double cross( const B2IVector& rVec ) const;
153 
154 		/** Calculate the Angle with another 2D Vector
155 
156 			@param rVec
157 			The second 2D Vector
158 
159 			@return
160 			The Angle value of the two involved 2D Vectors in -pi/2 < return < pi/2
161 		*/
162 		double angle( const B2IVector& rVec ) const;
163 
164 		/** Transform vector by given transformation matrix.
165 
166         	Since this is a vector, translational components of the
167         	matrix are disregarded.
168 		*/
169 		B2IVector& operator*=( const B2DHomMatrix& rMat );
170 
171 		static const B2IVector& getEmptyVector();
172 	};
173 
174 	// external operators
175 	//////////////////////////////////////////////////////////////////////////
176 
177 	/** Calculate the orientation to another 2D Vector
178 
179 		@param rVecA
180 		The first 2D Vector
181 
182 		@param rVecB
183 		The second 2D Vector
184 
185 		@return
186 		The mathematical Orientation of the two involved 2D Vectors
187 	*/
188 	B2VectorOrientation getOrientation( const B2IVector& rVecA, const B2IVector& rVecB );
189 
190 	/** Calculate a perpendicular 2D Vector to the given one
191 
192 		@param rVec
193 		The source 2D Vector
194 
195 		@return
196 		A 2D Vector perpendicular to the one given in parameter rVec
197 	*/
198 	B2IVector getPerpendicular( const B2IVector& rVec );
199 
200 	/** Test two vectors which need not to be normalized for parallelism
201 
202 		@param rVecA
203 		The first 2D Vector
204 
205 		@param rVecB
206 		The second 2D Vector
207 
208 		@return
209 		bool if the two values are parallel. Also true if
210 		one of the vectors is empty.
211 	*/
212 	bool areParallel( const B2IVector& rVecA, const B2IVector& rVecB );
213 
214 	/** Transform vector by given transformation matrix.
215 
216 		Since this is a vector, translational components of the
217     	matrix are disregarded.
218 	*/
219 	B2IVector operator*( const B2DHomMatrix& rMat, const B2IVector& rVec );
220 
221 	/** Test continuity between given vectors.
222 
223 		The two given vectors are assumed to describe control points on a
224     	common point. Calculate if there is a continuity between them.
225 	*/
226 	B2VectorContinuity getContinuity( const B2IVector& rBackVector, const B2IVector& rForwardVector );
227 
228 } // end of namespace basegfx
229 
230 #endif /* _BGFX_VECTOR_B2IVECTOR_HXX */
231