Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
gv_math.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <assert.h>
8#include <limits.h>
9#include <stdbool.h>
10#include <string.h>
11
13static inline int fcmp(double a, double b) {
14 if (a < b) {
15 return -1;
16 }
17 if (a > b) {
18 return 1;
19 }
20 return 0;
21}
22
24static inline int imax(int a, int b) { return a > b ? a : b; }
25
27static inline int imin(int a, int b) { return a < b ? a : b; }
28
43static inline bool is_exactly_equal(double a, double b) {
44 return memcmp(&a, &b, sizeof(a)) == 0;
45}
46
62static inline bool is_exactly_zero(double v) { return is_exactly_equal(v, 0); }
63
71static inline int scale_clamp(int original, double scale) {
72 assert(original >= 0);
73
74 if (scale < 0) {
75 return 0;
76 }
77
78 if (scale > 1 && original > INT_MAX / scale) {
79 return INT_MAX;
80 }
81
82 return (int)(original * scale);
83}
static pointf scale(double c, pointf p)
Definition geomprocs.h:130
static int scale_clamp(int original, double scale)
scale up or down a non-negative integer, clamping to [0, INT_MAX]
Definition gv_math.h:71
static bool is_exactly_zero(double v)
is a value precisely 0.0?
Definition gv_math.h:62
static bool is_exactly_equal(double a, double b)
are two values precisely the same?
Definition gv_math.h:43
static int imin(int a, int b)
minimum of two integers
Definition gv_math.h:27
static int fcmp(double a, double b)
comparator for doubles
Definition gv_math.h:13
static int imax(int a, int b)
maximum of two integers
Definition gv_math.h:24