merge the formfield patch from ooo-build
[ooovba.git] / basegfx / source / tuple / b2ituple.cxx
blob9abefd72498e6994e7b4b75b451a9c31c879ad13
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: b2ituple.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basegfx.hxx"
33 #include <basegfx/tuple/b2ituple.hxx>
34 #include <basegfx/tuple/b2dtuple.hxx>
35 #include <rtl/instance.hxx>
37 namespace { struct EmptyTuple : public rtl::Static<basegfx::B2ITuple, EmptyTuple> {}; }
39 namespace basegfx
41 const B2ITuple& B2ITuple::getEmptyTuple()
43 return EmptyTuple::get();
46 // external operators
47 //////////////////////////////////////////////////////////////////////////
49 B2ITuple minimum(const B2ITuple& rTupA, const B2ITuple& rTupB)
51 B2ITuple aMin(
52 (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
53 (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY());
54 return aMin;
57 B2ITuple maximum(const B2ITuple& rTupA, const B2ITuple& rTupB)
59 B2ITuple aMax(
60 (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
61 (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY());
62 return aMax;
65 B2ITuple absolute(const B2ITuple& rTup)
67 B2ITuple aAbs(
68 (0 > rTup.getX()) ? -rTup.getX() : rTup.getX(),
69 (0 > rTup.getY()) ? -rTup.getY() : rTup.getY());
70 return aAbs;
73 B2DTuple interpolate(const B2ITuple& rOld1, const B2ITuple& rOld2, double t)
75 B2DTuple aInt(
76 ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
77 ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY());
78 return aInt;
81 B2DTuple average(const B2ITuple& rOld1, const B2ITuple& rOld2)
83 B2DTuple aAvg(
84 (rOld1.getX() + rOld2.getX()) * 0.5,
85 (rOld1.getY() + rOld2.getY()) * 0.5);
86 return aAvg;
89 B2DTuple average(const B2ITuple& rOld1, const B2ITuple& rOld2, const B2ITuple& rOld3)
91 B2DTuple aAvg(
92 (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0),
93 (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0));
94 return aAvg;
97 B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB)
99 B2ITuple aSum(rTupA);
100 aSum += rTupB;
101 return aSum;
104 B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB)
106 B2ITuple aSub(rTupA);
107 aSub -= rTupB;
108 return aSub;
111 B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB)
113 B2ITuple aDiv(rTupA);
114 aDiv /= rTupB;
115 return aDiv;
118 B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB)
120 B2ITuple aMul(rTupA);
121 aMul *= rTupB;
122 return aMul;
125 B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t)
127 B2ITuple aNew(rTup);
128 aNew *= t;
129 return aNew;
132 B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup)
134 B2ITuple aNew(rTup);
135 aNew *= t;
136 return aNew;
139 B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t)
141 B2ITuple aNew(rTup);
142 aNew /= t;
143 return aNew;
146 B2ITuple operator/(sal_Int32 t, const B2ITuple& rTup)
148 B2ITuple aNew(t, t);
149 B2ITuple aTmp(rTup);
150 aNew /= aTmp;
151 return aNew;
154 } // end of namespace basegfx
156 // eof