fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / dialogs / mcvmath.hxx
bloba4ce6bd5f8017e2c8a7103c230f593f0251b4d91
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVTOOLS_SOURCE_DIALOGS_MCVMATH_HXX
21 #define INCLUDED_SVTOOLS_SOURCE_DIALOGS_MCVMATH_HXX
23 #include <tools/solar.h>
25 class FixCpx;
27 // No of fractal bits
28 // allowed range 0..14, must be even
29 #define FIX_POST 14
31 // scale for ...Big() -Functions
32 #if (FIX_POST>=4)
33 #define FIX_P2 4
34 #define FIX_P3 (FIX_POST-FIX_P2)
35 #else
36 #define FIX_P2 0
37 #define FIX_P3 FIX_POST
38 #endif
40 #if (FIX_POST>=1)
41 #define FIX_ADD (1<<(FIX_POST-1))
42 #else
43 #define FIX_ADD 0
44 #endif
46 #if (FIX_P2>=1)
47 #define FIX_A2 (1<<(FIX_P2-1))
48 #else
49 #define FIX_A2 0
50 #endif
52 #if (FIX_P3>=1)
53 #define FIX_A3 (1<<(FIX_P3-1))
54 #else
55 #define FIX_A3 0
56 #endif
59 // - Fix -
62 class Fix
64 private:
65 friend class FixCpx;
67 public:
68 long x;
70 public:
71 Fix() { x=0; }
72 Fix( int i ) { x=(long(i)<<FIX_POST); }
73 Fix( short l ) { x=(long(l)<<FIX_POST); }
74 Fix( sal_uInt16 l ) { x=(long(l)<<FIX_POST); }
75 Fix( long l ) { x=(l<<FIX_POST); }
76 Fix( long Z, long N ) { x=(Z<<FIX_POST)/N; }
78 enum class Bits { Bits };
80 Fix(long bits, Bits): x(bits) {}
82 void SetInternVal( long nVal ) { x=nVal; }
83 long GetInternVal() const { return x; }
85 void operator+= ( const Fix& a ) { x+=a.x; }
86 void operator-= ( const Fix& a ) { x-=a.x; }
87 void operator*= ( const Fix& a ) { x=(x*a.x+FIX_ADD)>>FIX_POST; }
88 void operator/= ( const Fix& a ) { x=(x<<FIX_POST)/a.x; }
89 friend Fix operator- ( const Fix& a );
91 void MultBig( const Fix& a )
92 { x=((((a.x+FIX_A2)>>FIX_P2)*x+FIX_A3)>>FIX_P3); }
93 void DivBig( const Fix& a )
94 { x=((x<<FIX_P3)/a.x)<<FIX_P2; }
96 friend bool operator> ( const Fix& a, const Fix& b ) { return a.x > b.x; }
97 friend bool operator< ( const Fix& a, const Fix& b ) { return a.x < b.x; }
99 operator long() const { return (x+FIX_ADD) >> FIX_POST; }
100 operator double() const { return double(x)/(1<<FIX_POST); }
102 friend Fix operator+ ( const Fix& a, const Fix& b );
103 friend Fix operator- ( const Fix& a, const Fix& b );
104 friend Fix operator* ( const Fix& a, const Fix& b );
105 friend Fix operator/ ( const Fix& a, const Fix& b );
107 friend FixCpx operator-( const FixCpx& a );
111 // - FixCpx -
114 class FixCpx
116 public:
117 Fix r;
118 Fix i;
120 public:
121 FixCpx() : r(), i() {}
122 FixCpx( Fix a ) : r( a ), i() {}
123 FixCpx( Fix a, Fix b ) : r( a ), i( b ) {}
125 Fix& GetReal() { return r; }
126 Fix& GetImag() { return i; }
128 void operator*= ( const FixCpx& ra );
129 void MultBig( const FixCpx& ra, const FixCpx& rb );
131 friend FixCpx operator+ ( const FixCpx& a, const FixCpx& b );
132 friend FixCpx operator- ( const FixCpx& a, const FixCpx& b );
133 friend FixCpx operator* ( const FixCpx& a, const FixCpx& b );
134 friend FixCpx operator/ ( const FixCpx& a, const FixCpx& b );
135 friend FixCpx operator- ( const FixCpx& a );
138 inline Fix operator- ( const Fix& a )
140 Fix f;
141 f.x = -a.x;
142 return f;
145 inline Fix operator+ ( const Fix& a, const Fix& b )
147 return Fix(a.x+b.x, Fix::Bits::Bits);
150 inline Fix operator- ( const Fix& a, const Fix& b )
152 return Fix(a.x-b.x, Fix::Bits::Bits);
155 inline Fix operator* ( const Fix& a, const Fix& b )
157 return Fix((a.x*b.x+FIX_ADD)>>FIX_POST, Fix::Bits::Bits);
160 inline Fix operator/ ( const Fix& a, const Fix& b )
162 return Fix((a.x<<FIX_POST)/b.x, Fix::Bits::Bits);
165 inline FixCpx operator- ( const FixCpx& a )
167 FixCpx fc;
169 fc.r.x = -a.r.x;
170 fc.i.x = -a.i.x;
171 return fc;
174 inline FixCpx operator+ ( const FixCpx& a, const FixCpx& b )
176 return FixCpx( a.r+b.r, a.i+b.i );
179 inline FixCpx operator- ( const FixCpx& a, const FixCpx& b )
181 return FixCpx( a.r-b.r, a.i-b.i );
184 inline void FixCpx::operator*= ( const FixCpx& ra )
186 Fix rr = ra.r*r-ra.i*i;
187 i = ra.r*i+ra.i*r;
188 r = rr;
191 inline FixCpx operator* ( const FixCpx& a, const FixCpx& b )
193 return FixCpx( a.r*b.r-a.i*b.i, a.r*b.i+a.i*b.r );
196 inline FixCpx operator/ ( const FixCpx& a, const FixCpx& b )
198 return FixCpx( (a.r*b.r+a.i*b.i)/(b.r*b.r+b.i*b.i),
199 (b.r*a.r-a.r*b.i)/(b.r*b.r+b.i*b.i) );
204 Fix ImpMultBig2( const Fix& a, const Fix& b );
206 sal_uInt16 ImpSqrt( sal_uLong nRadi );
207 FixCpx ImpExPI( sal_uInt16 nPhi );
209 #endif // INCLUDED_SVTOOLS_SOURCE_DIALOGS_MCVMATH_HXX
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */