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