xref: /AOO42X/main/basegfx/inc/basegfx/vector/b2ivector.hxx (revision 7871dc3ea494bf86c742e1f4dfc9c6e20f5bcb2a)
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_VECTOR_B2IVECTOR_HXX
25 #define _BGFX_VECTOR_B2IVECTOR_HXX
26 
27 #include <basegfx/tuple/b2ituple.hxx>
28 #include <basegfx/vector/b2enums.hxx>
29 
30 namespace basegfx
31 {
32     // predeclaration
33     class B2DHomMatrix;
34 
35     /** Base Point class with two sal_Int32 values
36 
37         This class derives all operators and common handling for
38         a 2D data class from B2ITuple. All necessary extensions
39         which are special for 2D Vectors are added here.
40 
41         @see B2ITuple
42     */
43     class B2IVector : public ::basegfx::B2ITuple
44     {
45     public:
46         /** Create a 2D Vector
47 
48             The vector is initialized to (0, 0)
49         */
50         B2IVector()
51         :   B2ITuple()
52         {}
53 
54         /** Create a 2D Vector
55 
56             @param nX
57             This parameter is used to initialize the X-coordinate
58             of the 2D Vector.
59 
60             @param nY
61             This parameter is used to initialize the Y-coordinate
62             of the 2D Vector.
63         */
64         B2IVector(sal_Int32 nX, sal_Int32 nY)
65         :   B2ITuple(nX, nY)
66         {}
67 
68         /** Create a copy of a 2D Vector
69 
70             @param rVec
71             The 2D Vector which will be copied.
72         */
73         B2IVector(const B2IVector& rVec)
74         :   B2ITuple(rVec)
75         {}
76 
77         /** constructor with tuple to allow copy-constructing
78             from B2ITuple-based classes
79         */
80         B2IVector(const ::basegfx::B2ITuple& rTuple)
81         :   B2ITuple(rTuple)
82         {}
83 
84         ~B2IVector()
85         {}
86 
87         /** *=operator to allow usage from B2IVector, too
88         */
89         B2IVector& operator*=( const B2IVector& rPnt )
90         {
91             mnX *= rPnt.mnX;
92             mnY *= rPnt.mnY;
93             return *this;
94         }
95 
96         /** *=operator to allow usage from B2IVector, too
97         */
98         B2IVector& operator*=(sal_Int32 t)
99         {
100             mnX *= t;
101             mnY *= t;
102             return *this;
103         }
104 
105         /** assignment operator to allow assigning the results
106             of B2ITuple calculations
107         */
108         B2IVector& operator=( const ::basegfx::B2ITuple& rVec );
109 
110         /** Calculate the length of this 2D Vector
111 
112             @return The Length of the 2D Vector
113         */
114         double getLength() const;
115 
116         /** Set the length of this 2D Vector
117 
118             @param fLen
119             The to be achieved length of the 2D Vector
120         */
121         B2IVector& setLength(double fLen);
122 
123         /** Calculate the Scalar with another 2D Vector
124 
125             @param rVec
126             The second 2D Vector
127 
128             @return
129             The Scalar value of the two involved 2D Vectors
130         */
131         double scalar( const B2IVector& rVec ) const;
132 
133         /** Calculate the length of the cross product with another 2D Vector
134 
135             In 2D, returning an actual vector does not make much
136             sense here. The magnitude, although, can be readily
137             used for tasks such as angle calculations, since for
138             the returned value, the following equation holds:
139             retVal = getLength(this)*getLength(rVec)*sin(theta),
140             with theta being the angle between the two vectors.
141 
142             @param rVec
143             The second 2D Vector
144 
145             @return
146             The length of the cross product of the two involved 2D Vectors
147         */
148         double cross( const B2IVector& rVec ) const;
149 
150         /** Calculate the Angle with another 2D Vector
151 
152             @param rVec
153             The second 2D Vector
154 
155             @return
156             The Angle value of the two involved 2D Vectors in -pi/2 < return < pi/2
157         */
158         double angle( const B2IVector& rVec ) const;
159 
160         /** Transform vector by given transformation matrix.
161 
162             Since this is a vector, translational components of the
163             matrix are disregarded.
164         */
165         B2IVector& operator*=( const B2DHomMatrix& rMat );
166 
167         static const B2IVector& getEmptyVector();
168     };
169 
170     // external operators
171     //////////////////////////////////////////////////////////////////////////
172 
173     /** Calculate the orientation to another 2D Vector
174 
175         @param rVecA
176         The first 2D Vector
177 
178         @param rVecB
179         The second 2D Vector
180 
181         @return
182         The mathematical Orientation of the two involved 2D Vectors
183     */
184     B2VectorOrientation getOrientation( const B2IVector& rVecA, const B2IVector& rVecB );
185 
186     /** Calculate a perpendicular 2D Vector to the given one
187 
188         @param rVec
189         The source 2D Vector
190 
191         @return
192         A 2D Vector perpendicular to the one given in parameter rVec
193     */
194     B2IVector getPerpendicular( const B2IVector& rVec );
195 
196     /** Test two vectors which need not to be normalized for parallelism
197 
198         @param rVecA
199         The first 2D Vector
200 
201         @param rVecB
202         The second 2D Vector
203 
204         @return
205         bool if the two values are parallel. Also true if
206         one of the vectors is empty.
207     */
208     bool areParallel( const B2IVector& rVecA, const B2IVector& rVecB );
209 
210     /** Transform vector by given transformation matrix.
211 
212         Since this is a vector, translational components of the
213         matrix are disregarded.
214     */
215     B2IVector operator*( const B2DHomMatrix& rMat, const B2IVector& rVec );
216 
217     /** Test continuity between given vectors.
218 
219         The two given vectors are assumed to describe control points on a
220         common point. Calculate if there is a continuity between them.
221     */
222     B2VectorContinuity getContinuity( const B2IVector& rBackVector, const B2IVector& rForwardVector );
223 
224 } // end of namespace basegfx
225 
226 #endif /* _BGFX_VECTOR_B2IVECTOR_HXX */
227