1/* $Id$ $Revision$ */
2/* vim:set shiftwidth=4 ts=8: */
3
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14/* geometric functions (e.g. on points and boxes) with application to, but
15 * no specific dependence on graphs */
16
17#ifndef GV_ARITH_H
18#define GV_ARITH_H
19
20/* for sincos */
21#ifndef _GNU_SOURCE
22#define _GNU_SOURCE 1
23#endif
24
25#include <limits.h>
26#include <math.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#ifdef MIN
33#undef MIN
34#endif
35#define MIN(a,b) ((a)<(b)?(a):(b))
36
37#ifdef MAX
38#undef MAX
39#endif
40#define MAX(a,b) ((a)>(b)?(a):(b))
41
42#ifdef ABS
43#undef ABS
44#endif
45#define ABS(a) ((a) >= 0 ? (a) : -(a))
46
47#define AVG(a,b) ((a + b) / 2)
48#define SGN(a) (((a)<0)? -1 : 1)
49#define CMP(a,b) (((a)<(b)) ? -1 : (((a)>(b)) ? 1 : 0))
50
51#ifndef INT_MAX
52#define INT_MAX ((int)(~(unsigned)0 >> 1))
53#endif
54
55#ifndef INT_MIN
56#define INT_MIN (-INT_MAX - 1)
57#endif
58
59#ifndef MAXSHORT
60#define MAXSHORT (0x7fff)
61#endif
62
63#ifndef MAXDOUBLE
64#define MAXDOUBLE 1.7976931348623157e+308
65#endif
66
67#ifndef MAXFLOAT
68#define MAXFLOAT ((float)3.40282347e+38) // exact value: 0x1.fffffep+127f
69#endif
70
71#ifdef BETWEEN
72#undef BETWEEN
73#endif
74#define BETWEEN(a,b,c) (((a) <= (b)) && ((b) <= (c)))
75
76#ifndef M_PI
77#define M_PI 3.14159265358979323846
78#endif
79
80#ifndef SQRT2
81#define SQRT2 1.41421356237309504880
82#endif
83
84#define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5))
85#define RADIANS(deg) ((deg)/180.0 * M_PI)
86#define DEGREES(rad) ((rad)/M_PI * 180.0)
87
88#define SQR(a) ((a) * (a))
89
90#ifdef HAVE_SINCOS
91 extern void sincos(double x, double *s, double *c);
92#else
93# define sincos(x,s,c) *s = sin(x); *c = cos(x)
94#endif
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif
101