1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: b2ituple.cxx,v $
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
> {}; }
41 const B2ITuple
& B2ITuple::getEmptyTuple()
43 return EmptyTuple::get();
47 //////////////////////////////////////////////////////////////////////////
49 B2ITuple
minimum(const B2ITuple
& rTupA
, const B2ITuple
& rTupB
)
52 (rTupB
.getX() < rTupA
.getX()) ? rTupB
.getX() : rTupA
.getX(),
53 (rTupB
.getY() < rTupA
.getY()) ? rTupB
.getY() : rTupA
.getY());
57 B2ITuple
maximum(const B2ITuple
& rTupA
, const B2ITuple
& rTupB
)
60 (rTupB
.getX() > rTupA
.getX()) ? rTupB
.getX() : rTupA
.getX(),
61 (rTupB
.getY() > rTupA
.getY()) ? rTupB
.getY() : rTupA
.getY());
65 B2ITuple
absolute(const B2ITuple
& rTup
)
68 (0 > rTup
.getX()) ? -rTup
.getX() : rTup
.getX(),
69 (0 > rTup
.getY()) ? -rTup
.getY() : rTup
.getY());
73 B2DTuple
interpolate(const B2ITuple
& rOld1
, const B2ITuple
& rOld2
, double t
)
76 ((rOld2
.getX() - rOld1
.getX()) * t
) + rOld1
.getX(),
77 ((rOld2
.getY() - rOld1
.getY()) * t
) + rOld1
.getY());
81 B2DTuple
average(const B2ITuple
& rOld1
, const B2ITuple
& rOld2
)
84 (rOld1
.getX() + rOld2
.getX()) * 0.5,
85 (rOld1
.getY() + rOld2
.getY()) * 0.5);
89 B2DTuple
average(const B2ITuple
& rOld1
, const B2ITuple
& rOld2
, const B2ITuple
& rOld3
)
92 (rOld1
.getX() + rOld2
.getX() + rOld3
.getX()) * (1.0 / 3.0),
93 (rOld1
.getY() + rOld2
.getY() + rOld3
.getY()) * (1.0 / 3.0));
97 B2ITuple
operator+(const B2ITuple
& rTupA
, const B2ITuple
& rTupB
)
104 B2ITuple
operator-(const B2ITuple
& rTupA
, const B2ITuple
& rTupB
)
106 B2ITuple
aSub(rTupA
);
111 B2ITuple
operator/(const B2ITuple
& rTupA
, const B2ITuple
& rTupB
)
113 B2ITuple
aDiv(rTupA
);
118 B2ITuple
operator*(const B2ITuple
& rTupA
, const B2ITuple
& rTupB
)
120 B2ITuple
aMul(rTupA
);
125 B2ITuple
operator*(const B2ITuple
& rTup
, sal_Int32 t
)
132 B2ITuple
operator*(sal_Int32 t
, const B2ITuple
& rTup
)
139 B2ITuple
operator/(const B2ITuple
& rTup
, sal_Int32 t
)
146 B2ITuple
operator/(sal_Int32 t
, const B2ITuple
& rTup
)
154 } // end of namespace basegfx