1*09dbbe93SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*09dbbe93SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*09dbbe93SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*09dbbe93SAndrew Rist * distributed with this work for additional information 6*09dbbe93SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*09dbbe93SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*09dbbe93SAndrew Rist * "License"); you may not use this file except in compliance 9*09dbbe93SAndrew Rist * with the License. You may obtain a copy of the License at 10*09dbbe93SAndrew Rist * 11*09dbbe93SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*09dbbe93SAndrew Rist * 13*09dbbe93SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*09dbbe93SAndrew Rist * software distributed under the License is distributed on an 15*09dbbe93SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*09dbbe93SAndrew Rist * KIND, either express or implied. See the License for the 17*09dbbe93SAndrew Rist * specific language governing permissions and limitations 18*09dbbe93SAndrew Rist * under the License. 19*09dbbe93SAndrew Rist * 20*09dbbe93SAndrew Rist *************************************************************/ 21*09dbbe93SAndrew Rist 22*09dbbe93SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_basegfx.hxx" 26cdf0e10cSrcweir #include <basegfx/tuple/b2ituple.hxx> 27cdf0e10cSrcweir #include <basegfx/tuple/b2dtuple.hxx> 28cdf0e10cSrcweir #include <rtl/instance.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir namespace { struct EmptyTuple : public rtl::Static<basegfx::B2ITuple, EmptyTuple> {}; } 31cdf0e10cSrcweir 32cdf0e10cSrcweir namespace basegfx 33cdf0e10cSrcweir { 34cdf0e10cSrcweir const B2ITuple& B2ITuple::getEmptyTuple() 35cdf0e10cSrcweir { 36cdf0e10cSrcweir return EmptyTuple::get(); 37cdf0e10cSrcweir } 38cdf0e10cSrcweir 39cdf0e10cSrcweir // external operators 40cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 41cdf0e10cSrcweir 42cdf0e10cSrcweir B2ITuple minimum(const B2ITuple& rTupA, const B2ITuple& rTupB) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir B2ITuple aMin( 45cdf0e10cSrcweir (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(), 46cdf0e10cSrcweir (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY()); 47cdf0e10cSrcweir return aMin; 48cdf0e10cSrcweir } 49cdf0e10cSrcweir 50cdf0e10cSrcweir B2ITuple maximum(const B2ITuple& rTupA, const B2ITuple& rTupB) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir B2ITuple aMax( 53cdf0e10cSrcweir (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(), 54cdf0e10cSrcweir (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY()); 55cdf0e10cSrcweir return aMax; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir B2ITuple absolute(const B2ITuple& rTup) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir B2ITuple aAbs( 61cdf0e10cSrcweir (0 > rTup.getX()) ? -rTup.getX() : rTup.getX(), 62cdf0e10cSrcweir (0 > rTup.getY()) ? -rTup.getY() : rTup.getY()); 63cdf0e10cSrcweir return aAbs; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir B2DTuple interpolate(const B2ITuple& rOld1, const B2ITuple& rOld2, double t) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir B2DTuple aInt( 69cdf0e10cSrcweir ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), 70cdf0e10cSrcweir ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY()); 71cdf0e10cSrcweir return aInt; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir B2DTuple average(const B2ITuple& rOld1, const B2ITuple& rOld2) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir B2DTuple aAvg( 77cdf0e10cSrcweir (rOld1.getX() + rOld2.getX()) * 0.5, 78cdf0e10cSrcweir (rOld1.getY() + rOld2.getY()) * 0.5); 79cdf0e10cSrcweir return aAvg; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir B2DTuple average(const B2ITuple& rOld1, const B2ITuple& rOld2, const B2ITuple& rOld3) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir B2DTuple aAvg( 85cdf0e10cSrcweir (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), 86cdf0e10cSrcweir (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0)); 87cdf0e10cSrcweir return aAvg; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir B2ITuple aSum(rTupA); 93cdf0e10cSrcweir aSum += rTupB; 94cdf0e10cSrcweir return aSum; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir B2ITuple aSub(rTupA); 100cdf0e10cSrcweir aSub -= rTupB; 101cdf0e10cSrcweir return aSub; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir B2ITuple aDiv(rTupA); 107cdf0e10cSrcweir aDiv /= rTupB; 108cdf0e10cSrcweir return aDiv; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir B2ITuple aMul(rTupA); 114cdf0e10cSrcweir aMul *= rTupB; 115cdf0e10cSrcweir return aMul; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir B2ITuple aNew(rTup); 121cdf0e10cSrcweir aNew *= t; 122cdf0e10cSrcweir return aNew; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir B2ITuple aNew(rTup); 128cdf0e10cSrcweir aNew *= t; 129cdf0e10cSrcweir return aNew; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir B2ITuple aNew(rTup); 135cdf0e10cSrcweir aNew /= t; 136cdf0e10cSrcweir return aNew; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir B2ITuple operator/(sal_Int32 t, const B2ITuple& rTup) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir B2ITuple aNew(t, t); 142cdf0e10cSrcweir B2ITuple aTmp(rTup); 143cdf0e10cSrcweir aNew /= aTmp; 144cdf0e10cSrcweir return aNew; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir } // end of namespace basegfx 148cdf0e10cSrcweir 149cdf0e10cSrcweir // eof 150