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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_basegfx.hxx" 26 #include <basegfx/tuple/b2ituple.hxx> 27 #include <basegfx/tuple/b2dtuple.hxx> 28 #include <rtl/instance.hxx> 29 30 namespace { struct EmptyTuple : public rtl::Static<basegfx::B2ITuple, EmptyTuple> {}; } 31 32 namespace basegfx 33 { 34 const B2ITuple& B2ITuple::getEmptyTuple() 35 { 36 return EmptyTuple::get(); 37 } 38 39 // external operators 40 ////////////////////////////////////////////////////////////////////////// 41 42 B2ITuple minimum(const B2ITuple& rTupA, const B2ITuple& rTupB) 43 { 44 B2ITuple aMin( 45 (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(), 46 (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY()); 47 return aMin; 48 } 49 50 B2ITuple maximum(const B2ITuple& rTupA, const B2ITuple& rTupB) 51 { 52 B2ITuple aMax( 53 (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(), 54 (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY()); 55 return aMax; 56 } 57 58 B2ITuple absolute(const B2ITuple& rTup) 59 { 60 B2ITuple aAbs( 61 (0 > rTup.getX()) ? -rTup.getX() : rTup.getX(), 62 (0 > rTup.getY()) ? -rTup.getY() : rTup.getY()); 63 return aAbs; 64 } 65 66 B2DTuple interpolate(const B2ITuple& rOld1, const B2ITuple& rOld2, double t) 67 { 68 B2DTuple aInt( 69 ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(), 70 ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY()); 71 return aInt; 72 } 73 74 B2DTuple average(const B2ITuple& rOld1, const B2ITuple& rOld2) 75 { 76 B2DTuple aAvg( 77 (rOld1.getX() + rOld2.getX()) * 0.5, 78 (rOld1.getY() + rOld2.getY()) * 0.5); 79 return aAvg; 80 } 81 82 B2DTuple average(const B2ITuple& rOld1, const B2ITuple& rOld2, const B2ITuple& rOld3) 83 { 84 B2DTuple aAvg( 85 (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0), 86 (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0)); 87 return aAvg; 88 } 89 90 B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB) 91 { 92 B2ITuple aSum(rTupA); 93 aSum += rTupB; 94 return aSum; 95 } 96 97 B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB) 98 { 99 B2ITuple aSub(rTupA); 100 aSub -= rTupB; 101 return aSub; 102 } 103 104 B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB) 105 { 106 B2ITuple aDiv(rTupA); 107 aDiv /= rTupB; 108 return aDiv; 109 } 110 111 B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB) 112 { 113 B2ITuple aMul(rTupA); 114 aMul *= rTupB; 115 return aMul; 116 } 117 118 B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t) 119 { 120 B2ITuple aNew(rTup); 121 aNew *= t; 122 return aNew; 123 } 124 125 B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup) 126 { 127 B2ITuple aNew(rTup); 128 aNew *= t; 129 return aNew; 130 } 131 132 B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t) 133 { 134 B2ITuple aNew(rTup); 135 aNew /= t; 136 return aNew; 137 } 138 139 B2ITuple operator/(sal_Int32 t, const B2ITuple& rTup) 140 { 141 B2ITuple aNew(t, t); 142 B2ITuple aTmp(rTup); 143 aNew /= aTmp; 144 return aNew; 145 } 146 147 } // end of namespace basegfx 148 149 // eof 150