/src/libreoffice/include/basegfx/vector/b2ivector.hxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <ostream> |
23 | | |
24 | | #include <basegfx/tuple/b2ituple.hxx> |
25 | | #include <basegfx/basegfxdllapi.h> |
26 | | |
27 | | namespace basegfx |
28 | | { |
29 | | class B2DHomMatrix; |
30 | | |
31 | | /** Base Point class with two sal_Int32 values |
32 | | |
33 | | This class derives all operators and common handling for |
34 | | a 2D data class from B2ITuple. All necessary extensions |
35 | | which are special for 2D Vectors are added here. |
36 | | |
37 | | @see B2ITuple |
38 | | */ |
39 | | class BASEGFX_DLLPUBLIC B2IVector : public ::basegfx::B2ITuple |
40 | | { |
41 | | public: |
42 | | /** Create a 2D Vector |
43 | | |
44 | | The vector is initialized to (0, 0) |
45 | | */ |
46 | | B2IVector() |
47 | 2.63M | {} |
48 | | |
49 | | /** Create a 2D Vector |
50 | | |
51 | | @param nX |
52 | | This parameter is used to initialize the X-coordinate |
53 | | of the 2D Vector. |
54 | | |
55 | | @param nY |
56 | | This parameter is used to initialize the Y-coordinate |
57 | | of the 2D Vector. |
58 | | */ |
59 | | B2IVector(sal_Int32 nX, sal_Int32 nY) |
60 | 2.13M | : B2ITuple(nX, nY) |
61 | 2.13M | {} |
62 | | |
63 | | /** constructor with tuple to allow copy-constructing |
64 | | from B2ITuple-based classes |
65 | | */ |
66 | | B2IVector(const ::basegfx::B2ITuple& rTuple) |
67 | | : B2ITuple(rTuple) |
68 | 0 | {} |
69 | | |
70 | | /** *=operator to allow usage from B2IVector, too |
71 | | */ |
72 | | B2IVector& operator*=( const B2IVector& rPnt ) |
73 | 0 | { |
74 | 0 | mnX *= rPnt.mnX; |
75 | 0 | mnY *= rPnt.mnY; |
76 | 0 | return *this; |
77 | 0 | } |
78 | | |
79 | | /** *=operator to allow usage from B2IVector, too |
80 | | */ |
81 | | B2IVector& operator*=(sal_Int32 t) |
82 | 0 | { |
83 | 0 | mnX *= t; |
84 | 0 | mnY *= t; |
85 | 0 | return *this; |
86 | 0 | } |
87 | | |
88 | | /** assignment operator to allow assigning the results |
89 | | of B2ITuple calculations |
90 | | */ |
91 | | B2IVector& operator=( const ::basegfx::B2ITuple& rVec ); |
92 | | |
93 | | /** Set the length of this 2D Vector |
94 | | |
95 | | @param fLen |
96 | | The to be achieved length of the 2D Vector |
97 | | */ |
98 | | B2IVector& setLength(double fLen); |
99 | | |
100 | | /** Calculate the Scalar with another 2D Vector |
101 | | |
102 | | @param rVec |
103 | | The second 2D Vector |
104 | | |
105 | | @return |
106 | | The Scalar value of the two involved 2D Vectors |
107 | | */ |
108 | 0 | double scalar( const B2IVector& rVec ) const { return((mnX * rVec.mnX) + (mnY * rVec.mnY)); } |
109 | | |
110 | | /** Transform vector by given transformation matrix. |
111 | | |
112 | | Since this is a vector, translational components of the |
113 | | matrix are disregarded. |
114 | | */ |
115 | | B2IVector& operator*=( const B2DHomMatrix& rMat ); |
116 | | }; |
117 | | |
118 | | // external operators |
119 | | |
120 | | template< typename charT, typename traits > |
121 | | inline std::basic_ostream<charT, traits> & operator <<( |
122 | | std::basic_ostream<charT, traits> & stream, const basegfx::B2IVector& vector ) |
123 | 0 | { |
124 | 0 | return stream << "(" << vector.getX() << "," << vector.getY() << ")"; |
125 | 0 | } |
126 | | |
127 | | } // end of namespace basegfx |
128 | | |
129 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |