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