X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Futil%2Ffixed_point.h;h=6afec5e3cb1effebc61ab291a0f4a5b27382ca77;hb=0f51f94e09af3ab07d55c057a09b44f0790599b9;hp=bea891742e7253c2cfc7b43c2dde5e5abeac86a2;hpb=24c6ddb693cb37e6e68798b6fff862d5968c5891;p=inkscape.git diff --git a/src/util/fixed_point.h b/src/util/fixed_point.h index bea891742..6afec5e3c 100644 --- a/src/util/fixed_point.h +++ b/src/util/fixed_point.h @@ -1,333 +1,333 @@ -/* - * Inkscape::Util::FixedPoint - fixed point type - * - * Authors: - * Jasper van de Gronde - * - * Copyright (C) 2006 Jasper van de Gronde - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H -#define SEEN_INKSCAPE_UTIL_FIXED_POINT_H - -#include "traits/reference.h" -#include -#include -#include - -namespace Inkscape { - -namespace Util { - -template -class FixedPoint { -public: - FixedPoint() {} - FixedPoint(const FixedPoint& value) : v(value.v) {} - FixedPoint(char value) : v(static_cast(value)<(value)<(value)<(value)<(value)<(value)<(floor(value*(1<>half_size, bh = val.v>>half_size; - v = static_cast(al*bl)>>precision; - if ( half_size >= precision ) { - v += ((al*bh)+(ah*bl)+((ah*bh)<>(precision-half_size); - v += (ah*bh)<<(2*half_size-precision); - } - return *this; - } - - FixedPoint& operator*=(char val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned char val) { v *= val; return *this; } - FixedPoint& operator*=(short val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned short val) { v *= val; return *this; } - FixedPoint& operator*=(int val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned int val) { v *= val; return *this; } - - FixedPoint operator+(FixedPoint val) const { FixedPoint r(*this); return r+=val; } - FixedPoint operator-(FixedPoint val) const { FixedPoint r(*this); return r-=val; } - FixedPoint operator*(FixedPoint val) const { FixedPoint r(*this); return r*=val; } - - FixedPoint operator*(char val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned char val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(short val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned short val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(int val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned int val) const { FixedPoint r(*this); return r*=val; } - - float operator*(float val) const { return static_cast(*this)*val; } - double operator*(double val) const { return static_cast(*this)*val; } - - operator char() const { return v>>precision; } - operator unsigned char() const { return v>>precision; } - operator short() const { return v>>precision; } - operator unsigned short() const { return v>>precision; } - operator int() const { return v>>precision; } - operator unsigned int() const { return v>>precision; } - - operator float() const { return ldexpf(v,-precision); } - operator double() const { return ldexp(v,-precision); } -private: - T v; -}; - -template FixedPoint operator *(char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(int a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned int a, FixedPoint b) { return b*=a; } - -template float operator *(float a, FixedPoint b) { return b*a; } -template double operator *(double a, FixedPoint b) { return b*a; } - -} - -} - -#endif -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : -/* - * Inkscape::Util::FixedPoint - fixed point type - * - * Authors: - * Jasper van de Gronde - * - * Copyright (C) 2006 Jasper van de Gronde - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H -#define SEEN_INKSCAPE_UTIL_FIXED_POINT_H - -#include "traits/reference.h" -#include -#include -#include - -namespace Inkscape { - -namespace Util { - -template -class FixedPoint { -public: - FixedPoint() {} - FixedPoint(const FixedPoint& value) : v(value.v) {} - FixedPoint(char value) : v(static_cast(value)<(value)<(value)<(value)<(value)<(value)<(floor(value*(1<>half_size, bh = val.v>>half_size; - v = static_cast(al*bl)>>precision; - if ( half_size >= precision ) { - v += ((al*bh)+(ah*bl)+((ah*bh)<>(precision-half_size); - v += (ah*bh)<<(2*half_size-precision); - } - return *this; - } - - FixedPoint& operator*=(char val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned char val) { v *= val; return *this; } - FixedPoint& operator*=(short val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned short val) { v *= val; return *this; } - FixedPoint& operator*=(int val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned int val) { v *= val; return *this; } - - FixedPoint operator+(FixedPoint val) const { FixedPoint r(*this); return r+=val; } - FixedPoint operator-(FixedPoint val) const { FixedPoint r(*this); return r-=val; } - FixedPoint operator*(FixedPoint val) const { FixedPoint r(*this); return r*=val; } - - FixedPoint operator*(char val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned char val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(short val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned short val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(int val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned int val) const { FixedPoint r(*this); return r*=val; } - - float operator*(float val) const { return static_cast(*this)*val; } - double operator*(double val) const { return static_cast(*this)*val; } - - operator char() const { return v>>precision; } - operator unsigned char() const { return v>>precision; } - operator short() const { return v>>precision; } - operator unsigned short() const { return v>>precision; } - operator int() const { return v>>precision; } - operator unsigned int() const { return v>>precision; } - - operator float() const { return ldexpf(v,-precision); } - operator double() const { return ldexp(v,-precision); } -private: - T v; -}; - -template FixedPoint operator *(char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(int a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned int a, FixedPoint b) { return b*=a; } - -template float operator *(float a, FixedPoint b) { return b*a; } -template double operator *(double a, FixedPoint b) { return b*a; } - -} - -} - -#endif -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : -/* - * Inkscape::Util::FixedPoint - fixed point type - * - * Authors: - * Jasper van de Gronde - * - * Copyright (C) 2006 Jasper van de Gronde - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H -#define SEEN_INKSCAPE_UTIL_FIXED_POINT_H - -#include "traits/reference.h" -#include -#include -#include - -namespace Inkscape { - -namespace Util { - -template -class FixedPoint { -public: - FixedPoint() {} - FixedPoint(const FixedPoint& value) : v(value.v) {} - FixedPoint(char value) : v(static_cast(value)<(value)<(value)<(value)<(value)<(value)<(floor(value*(1<>half_size, bh = val.v>>half_size; - v = static_cast(al*bl)>>precision; - if ( half_size >= precision ) { - v += ((al*bh)+(ah*bl)+((ah*bh)<>(precision-half_size); - v += (ah*bh)<<(2*half_size-precision); - } - return *this; - } - - FixedPoint& operator*=(char val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned char val) { v *= val; return *this; } - FixedPoint& operator*=(short val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned short val) { v *= val; return *this; } - FixedPoint& operator*=(int val) { v *= val; return *this; } - FixedPoint& operator*=(unsigned int val) { v *= val; return *this; } - - FixedPoint operator+(FixedPoint val) const { FixedPoint r(*this); return r+=val; } - FixedPoint operator-(FixedPoint val) const { FixedPoint r(*this); return r-=val; } - FixedPoint operator*(FixedPoint val) const { FixedPoint r(*this); return r*=val; } - - FixedPoint operator*(char val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned char val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(short val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned short val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(int val) const { FixedPoint r(*this); return r*=val; } - FixedPoint operator*(unsigned int val) const { FixedPoint r(*this); return r*=val; } - - float operator*(float val) const { return static_cast(*this)*val; } - double operator*(double val) const { return static_cast(*this)*val; } - - operator char() const { return v>>precision; } - operator unsigned char() const { return v>>precision; } - operator short() const { return v>>precision; } - operator unsigned short() const { return v>>precision; } - operator int() const { return v>>precision; } - operator unsigned int() const { return v>>precision; } - - operator float() const { return ldexpf(v,-precision); } - operator double() const { return ldexp(v,-precision); } -private: - T v; -}; - -template FixedPoint operator *(char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(int a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned int a, FixedPoint b) { return b*=a; } - -template float operator *(float a, FixedPoint b) { return b*a; } -template double operator *(double a, FixedPoint b) { return b*a; } - -} - -} - -#endif -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +/* + * Inkscape::Util::FixedPoint - fixed point type + * + * Authors: + * Jasper van de Gronde + * + * Copyright (C) 2006 Jasper van de Gronde + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H +#define SEEN_INKSCAPE_UTIL_FIXED_POINT_H + +#include "traits/reference.h" +#include +#include +#include + +namespace Inkscape { + +namespace Util { + +template +class FixedPoint { +public: + FixedPoint() {} + FixedPoint(const FixedPoint& value) : v(value.v) {} + FixedPoint(char value) : v(static_cast(value)<(value)<(value)<(value)<(value)<(value)<(floor(value*(1<>half_size, bh = val.v>>half_size; + v = static_cast(al*bl)>>precision; + if ( half_size >= precision ) { + v += ((al*bh)+(ah*bl)+((ah*bh)<>(precision-half_size); + v += (ah*bh)<<(2*half_size-precision); + } + return *this; + } + + FixedPoint& operator*=(char val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned char val) { v *= val; return *this; } + FixedPoint& operator*=(short val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned short val) { v *= val; return *this; } + FixedPoint& operator*=(int val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned int val) { v *= val; return *this; } + + FixedPoint operator+(FixedPoint val) const { FixedPoint r(*this); return r+=val; } + FixedPoint operator-(FixedPoint val) const { FixedPoint r(*this); return r-=val; } + FixedPoint operator*(FixedPoint val) const { FixedPoint r(*this); return r*=val; } + + FixedPoint operator*(char val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned char val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(short val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned short val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(int val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned int val) const { FixedPoint r(*this); return r*=val; } + + float operator*(float val) const { return static_cast(*this)*val; } + double operator*(double val) const { return static_cast(*this)*val; } + + operator char() const { return v>>precision; } + operator unsigned char() const { return v>>precision; } + operator short() const { return v>>precision; } + operator unsigned short() const { return v>>precision; } + operator int() const { return v>>precision; } + operator unsigned int() const { return v>>precision; } + + operator float() const { return ldexpf(v,-precision); } + operator double() const { return ldexp(v,-precision); } +private: + T v; +}; + +template FixedPoint operator *(char a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned char a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(short a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned short a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(int a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned int a, FixedPoint b) { return b*=a; } + +template float operator *(float a, FixedPoint b) { return b*a; } +template double operator *(double a, FixedPoint b) { return b*a; } + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +/* + * Inkscape::Util::FixedPoint - fixed point type + * + * Authors: + * Jasper van de Gronde + * + * Copyright (C) 2006 Jasper van de Gronde + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H +#define SEEN_INKSCAPE_UTIL_FIXED_POINT_H + +#include "traits/reference.h" +#include +#include +#include + +namespace Inkscape { + +namespace Util { + +template +class FixedPoint { +public: + FixedPoint() {} + FixedPoint(const FixedPoint& value) : v(value.v) {} + FixedPoint(char value) : v(static_cast(value)<(value)<(value)<(value)<(value)<(value)<(floor(value*(1<>half_size, bh = val.v>>half_size; + v = static_cast(al*bl)>>precision; + if ( half_size >= precision ) { + v += ((al*bh)+(ah*bl)+((ah*bh)<>(precision-half_size); + v += (ah*bh)<<(2*half_size-precision); + } + return *this; + } + + FixedPoint& operator*=(char val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned char val) { v *= val; return *this; } + FixedPoint& operator*=(short val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned short val) { v *= val; return *this; } + FixedPoint& operator*=(int val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned int val) { v *= val; return *this; } + + FixedPoint operator+(FixedPoint val) const { FixedPoint r(*this); return r+=val; } + FixedPoint operator-(FixedPoint val) const { FixedPoint r(*this); return r-=val; } + FixedPoint operator*(FixedPoint val) const { FixedPoint r(*this); return r*=val; } + + FixedPoint operator*(char val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned char val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(short val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned short val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(int val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned int val) const { FixedPoint r(*this); return r*=val; } + + float operator*(float val) const { return static_cast(*this)*val; } + double operator*(double val) const { return static_cast(*this)*val; } + + operator char() const { return v>>precision; } + operator unsigned char() const { return v>>precision; } + operator short() const { return v>>precision; } + operator unsigned short() const { return v>>precision; } + operator int() const { return v>>precision; } + operator unsigned int() const { return v>>precision; } + + operator float() const { return ldexpf(v,-precision); } + operator double() const { return ldexp(v,-precision); } +private: + T v; +}; + +template FixedPoint operator *(char a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned char a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(short a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned short a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(int a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned int a, FixedPoint b) { return b*=a; } + +template float operator *(float a, FixedPoint b) { return b*a; } +template double operator *(double a, FixedPoint b) { return b*a; } + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +/* + * Inkscape::Util::FixedPoint - fixed point type + * + * Authors: + * Jasper van de Gronde + * + * Copyright (C) 2006 Jasper van de Gronde + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H +#define SEEN_INKSCAPE_UTIL_FIXED_POINT_H + +#include "traits/reference.h" +#include +#include +#include + +namespace Inkscape { + +namespace Util { + +template +class FixedPoint { +public: + FixedPoint() {} + FixedPoint(const FixedPoint& value) : v(value.v) {} + FixedPoint(char value) : v(static_cast(value)<(value)<(value)<(value)<(value)<(value)<(floor(value*(1<>half_size, bh = val.v>>half_size; + v = static_cast(al*bl)>>precision; + if ( half_size >= precision ) { + v += ((al*bh)+(ah*bl)+((ah*bh)<>(precision-half_size); + v += (ah*bh)<<(2*half_size-precision); + } + return *this; + } + + FixedPoint& operator*=(char val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned char val) { v *= val; return *this; } + FixedPoint& operator*=(short val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned short val) { v *= val; return *this; } + FixedPoint& operator*=(int val) { v *= val; return *this; } + FixedPoint& operator*=(unsigned int val) { v *= val; return *this; } + + FixedPoint operator+(FixedPoint val) const { FixedPoint r(*this); return r+=val; } + FixedPoint operator-(FixedPoint val) const { FixedPoint r(*this); return r-=val; } + FixedPoint operator*(FixedPoint val) const { FixedPoint r(*this); return r*=val; } + + FixedPoint operator*(char val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned char val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(short val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned short val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(int val) const { FixedPoint r(*this); return r*=val; } + FixedPoint operator*(unsigned int val) const { FixedPoint r(*this); return r*=val; } + + float operator*(float val) const { return static_cast(*this)*val; } + double operator*(double val) const { return static_cast(*this)*val; } + + operator char() const { return v>>precision; } + operator unsigned char() const { return v>>precision; } + operator short() const { return v>>precision; } + operator unsigned short() const { return v>>precision; } + operator int() const { return v>>precision; } + operator unsigned int() const { return v>>precision; } + + operator float() const { return ldexpf(v,-precision); } + operator double() const { return ldexp(v,-precision); } +private: + T v; +}; + +template FixedPoint operator *(char a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned char a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(short a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned short a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(int a, FixedPoint b) { return b*=a; } +template FixedPoint operator *(unsigned int a, FixedPoint b) { return b*=a; } + +template float operator *(float a, FixedPoint b) { return b*a; } +template double operator *(double a, FixedPoint b) { return b*a; } + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :