source: trunk/poppler/mypoppler/splash/SplashMath.h @ 461

Last change on this file since 461 was 461, checked in by Silvan Scherrer, 11 years ago

poppler update to 0.14.2

File size: 2.5 KB
Line 
1//========================================================================
2//
3// SplashMath.h
4//
5//========================================================================
6
7//========================================================================
8//
9// Modified under the Poppler project - http://poppler.freedesktop.org
10//
11// All changes made under the Poppler project to this file are licensed
12// under GPL version 2 or later
13//
14// Copyright (C) 2009, 2010 Albert Astals Cid <aacid@kde.org>
15//
16// To see a description of the changes please see the Changelog file that
17// came with your tarball or type make ChangeLog if you are building from git
18//
19//========================================================================
20
21#ifndef SPLASHMATH_H
22#define SPLASHMATH_H
23
24#if USE_FIXEDPOINT
25#include "goo/FixedPoint.h"
26#else
27#include <math.h>
28#endif
29#include "SplashTypes.h"
30
31static inline SplashCoord splashAbs(SplashCoord x) {
32#if USE_FIXEDPOINT
33  return FixedPoint::abs(x);
34#elif USE_FLOAT
35  return fabsf(x);
36#else
37  return fabs(x);
38#endif
39}
40
41static inline int splashFloor(SplashCoord x) {
42  #if USE_FIXEDPOINT
43    return FixedPoint::floor(x);
44  #elif USE_FLOAT
45    return (int)floorf(x);
46  #else
47    if (x > 0) return (int)x;
48    else return (int)floor(x);
49  #endif
50}
51
52static inline int splashCeil(SplashCoord x) {
53#if USE_FIXEDPOINT
54  return FixedPoint::ceil(x);
55#elif USE_FLOAT
56  return (int)ceilf(x);
57#else
58  return (int)ceil(x);
59#endif
60}
61
62static inline int splashRound(SplashCoord x) {
63#if USE_FIXEDPOINT
64  return FixedPoint::round(x);
65#else
66  return (int)splashFloor(x + 0.5);
67#endif
68}
69
70static inline SplashCoord splashSqrt(SplashCoord x) {
71#if USE_FIXEDPOINT
72  return FixedPoint::sqrt(x);
73#elif USE_FLOAT
74  return sqrtf(x);
75#else
76  return sqrt(x);
77#endif
78}
79
80static inline SplashCoord splashPow(SplashCoord x, SplashCoord y) {
81#if USE_FIXEDPOINT
82  return FixedPoint::pow(x, y);
83#elif USE_FLOAT
84  return powf(x, y);
85#else
86  return pow(x, y);
87#endif
88}
89
90static inline SplashCoord splashDist(SplashCoord x0, SplashCoord y0,
91                                     SplashCoord x1, SplashCoord y1) {
92  SplashCoord dx, dy;
93  dx = x1 - x0;
94  dy = y1 - y0;
95#if USE_FIXEDPOINT
96  // this handles the situation where dx*dx or dy*dy is too large to
97  // fit in the 16.16 fixed point format
98  SplashCoord dxa, dya;
99  dxa = splashAbs(dx);
100  dya = splashAbs(dy);
101  if (dxa == 0 && dya == 0) {
102    return 0;
103  } else if (dxa > dya) {
104    return dxa * FixedPoint::sqrt(dya / dxa + 1);
105  } else {
106    return dya * FixedPoint::sqrt(dxa / dya + 1);
107  }
108#else
109  return splashSqrt(dx * dx + dy * dy);
110#endif
111}
112
113#endif
Note: See TracBrowser for help on using the repository browser.