Graphviz 13.0.0~dev.20250121.0651
Loading...
Searching...
No Matches
gv_math.h File Reference

Arithmetic helper functions. More...

#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
Include dependency graph for gv_math.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  { BYTES_PER_PIXEL = 4 }
 byte length of data per pixel in image data buffers More...
 

Functions

static int fcmp (double a, double b)
 comparator for doubles
 
static int imax (int a, int b)
 maximum of two integers
 
static int imin (int a, int b)
 minimum of two integers
 
static bool is_exactly_equal (double a, double b)
 are two values precisely the same?
 
static bool is_exactly_zero (double v)
 is a value precisely 0.0?
 
static int scale_clamp (int original, double scale)
 scale up or down a non-negative integer, clamping to [0, INT_MAX]
 
static void argb2rgba (size_t width, size_t height, unsigned char *data)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
BYTES_PER_PIXEL 

Definition at line 87 of file gv_math.h.

Function Documentation

◆ argb2rgba()

static void argb2rgba ( size_t  width,
size_t  height,
unsigned char *  data 
)
inlinestatic

in-place conversion of ARGB32 big endian to RGBA32 little endian

Image data originating from sources like Cairo comes in a 4-byte-per-pixel format ordered {blue, green, red, alpha}. Some output libraries/devices instead consume a 4-byte-per-pixel format ordered {red, green, blue, alpha}. This function converts the former to the latter.

It is confusing to refer to these formats as ARGB32 and RGBA32 when the first is big endian and the second is little endian, and thus the mappings of letters in the acronym to bytes in memory are opposites. Nevertheless that appears to be what is in common usage.

Parameters
widthWidth of the image in pixels
heightHeight of the image in pixels
data[inout] Image data in ARGB32 format on entry and RGBA32 format on exit

Definition at line 105 of file gv_math.h.

References BYTES_PER_PIXEL, and NULL.

Referenced by kitty_format().

Here is the caller graph for this function:

◆ fcmp()

static int fcmp ( double  a,
double  b 
)
inlinestatic

Definition at line 14 of file gv_math.h.

Referenced by countHorzCross(), and countVertCross().

Here is the caller graph for this function:

◆ imax()

static int imax ( int  a,
int  b 
)
inlinestatic

Definition at line 25 of file gv_math.h.

Referenced by agerr_va().

Here is the caller graph for this function:

◆ imin()

static int imin ( int  a,
int  b 
)
inlinestatic

Definition at line 28 of file gv_math.h.

Referenced by common_init_node(), dfs(), dfs(), make_map_internal(), node_distinct_coloring_internal2(), QuadTree_get_nearest(), QuadTree_get_nearest_internal(), and sfprint().

Here is the caller graph for this function:

◆ is_exactly_equal()

static bool is_exactly_equal ( double  a,
double  b 
)
inlinestatic

This function should only be used when you know you want comparison with no tolerance, which is rare. Floating-point arithmetic accumulates imprecision, so equality comparisons should generally include a non-zero tolerance to account for this. In general, this function is only applicable for checking things like “is this variable unchanged since a previous assignment from a literal?”

Parameters
aFirst operand to comparison
bSecond operand to comparison
Returns
True if the values are equal

Definition at line 44 of file gv_math.h.

Referenced by is_exactly_zero(), is_set(), pango_textlayout(), point_init(), poly_init(), rgb2hsv(), and routesplines_().

Here is the caller graph for this function:

◆ is_exactly_zero()

static bool is_exactly_zero ( double  v)
inlinestatic

This function should only be used when you know you want comparison with no tolerance, which is rare. Floating-point arithmetic accumulates imprecision, so equality comparisons should generally include a non-zero tolerance to account for this. Valid double representations even include -0.0, for which this function will return false. In general, this function is only applicable for checking things like “is this variable unchanged since a previous assignment from the literal 0?” or “did this value we parsed from user input originate from the string "0.0"?”

Parameters
vValue to check
Returns
True if the value is equal to exactly 0.0

Definition at line 63 of file gv_math.h.

References is_exactly_equal().

Referenced by dotneato_args_initialize(), emit_begin_node(), get_inputscale(), isBox(), isRect(), poly_init(), and poly_inside().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scale_clamp()

static int scale_clamp ( int  original,
double  scale 
)
inlinestatic
Parameters
originalValue to scale
scaleScale factor to apply
Returns
Clamped result

Definition at line 72 of file gv_math.h.

References scale().

Referenced by dot2_rank(), nsiter2(), and rank1().

Here is the call graph for this function:
Here is the caller graph for this function: