FDL Core Library
ASC Framing Decision List — C/C++ Reference Implementation
Loading...
Searching...
No Matches
Functions
fdl_value_types.cpp File Reference

Value-type operations: dimensions arithmetic, point arithmetic, floating-point comparison. More...

#include "fdl/fdl_core.h"
#include "fdl_constants.h"
#include <algorithm>
#include <cmath>
#include <cstdlib>

Functions

double fdl_fp_rel_tol (void)
 Relative tolerance for floating-point comparison.
 
double fdl_fp_abs_tol (void)
 Absolute tolerance for floating-point comparison.
 
fdl_dimensions_f64_t fdl_dimensions_normalize (fdl_dimensions_f64_t dims, double squeeze)
 Normalize dimensions by applying anamorphic squeeze to width.
 
fdl_dimensions_f64_t fdl_dimensions_scale (fdl_dimensions_f64_t dims, double scale_factor, double target_squeeze)
 Scale normalized dimensions and apply target squeeze.
 
fdl_dimensions_f64_t fdl_dimensions_normalize_and_scale (fdl_dimensions_f64_t dims, double input_squeeze, double scale_factor, double target_squeeze)
 Normalize and scale in one step.
 
fdl_dimensions_f64_t fdl_dimensions_sub (fdl_dimensions_f64_t a, fdl_dimensions_f64_t b)
 Subtract two dimensions: result = a - b.
 
int fdl_dimensions_equal (fdl_dimensions_f64_t a, fdl_dimensions_f64_t b)
 Check if dimensions are approximately equal within FDL tolerance.
 
int fdl_dimensions_f64_gt (fdl_dimensions_f64_t a, fdl_dimensions_f64_t b)
 Check if a > b using OR logic (either width or height is greater).
 
int fdl_dimensions_f64_lt (fdl_dimensions_f64_t a, fdl_dimensions_f64_t b)
 Check if a < b using OR logic (either width or height is less).
 
int fdl_dimensions_is_zero (fdl_dimensions_f64_t dims)
 Check if both width and height are zero.
 
int fdl_dimensions_i64_is_zero (fdl_dimensions_i64_t dims)
 Check if both width and height are zero (int64 variant).
 
fdl_dimensions_f64_t fdl_dimensions_i64_normalize (fdl_dimensions_i64_t dims, double squeeze)
 Normalize int64 dimensions by applying anamorphic squeeze to width.
 
fdl_dimensions_i64_t fdl_dimensions_f64_to_i64 (fdl_dimensions_f64_t dims)
 Convert float dimensions to int64 by truncation.
 
int fdl_dimensions_i64_gt (fdl_dimensions_i64_t a, fdl_dimensions_i64_t b)
 Check if a > b using OR logic (either width or height is greater).
 
int fdl_dimensions_i64_lt (fdl_dimensions_i64_t a, fdl_dimensions_i64_t b)
 Check if a < b using OR logic (either width or height is less).
 
fdl_point_f64_t fdl_point_normalize (fdl_point_f64_t point, double squeeze)
 Normalize a point by applying anamorphic squeeze to x.
 
fdl_point_f64_t fdl_point_scale (fdl_point_f64_t point, double scale_factor, double target_squeeze)
 Scale a normalized point and apply target squeeze.
 
fdl_point_f64_t fdl_point_add (fdl_point_f64_t a, fdl_point_f64_t b)
 Add two points: result = a + b.
 
fdl_point_f64_t fdl_point_sub (fdl_point_f64_t a, fdl_point_f64_t b)
 Subtract two points: result = a - b.
 
fdl_point_f64_t fdl_point_mul_scalar (fdl_point_f64_t a, double scalar)
 Multiply point by scalar.
 
fdl_point_f64_t fdl_point_clamp (fdl_point_f64_t point, double min_val, double max_val, int has_min, int has_max)
 Clamp point values to [min_val, max_val].
 
int fdl_point_is_zero (fdl_point_f64_t point)
 Check if both x and y are zero.
 
fdl_point_f64_t fdl_point_normalize_and_scale (fdl_point_f64_t point, double input_squeeze, double scale_factor, double target_squeeze)
 Normalize and scale a point in one step.
 
int fdl_point_equal (fdl_point_f64_t a, fdl_point_f64_t b)
 Check approximate equality within FDL tolerances.
 
int fdl_point_f64_lt (fdl_point_f64_t a, fdl_point_f64_t b)
 Check if a < b using OR logic (either x or y is less).
 
int fdl_point_f64_gt (fdl_point_f64_t a, fdl_point_f64_t b)
 Check if a > b using OR logic (either x or y is greater).
 
void fdl_free (void *ptr)
 Free memory allocated by fdl_core functions.
 

Detailed Description

Value-type operations: dimensions arithmetic, point arithmetic, floating-point comparison.

Function Documentation

◆ fdl_fp_rel_tol()

double fdl_fp_rel_tol ( void  )

Relative tolerance for floating-point comparison.

Returns
1e-9.

◆ fdl_fp_abs_tol()

double fdl_fp_abs_tol ( void  )

Absolute tolerance for floating-point comparison.

Returns
1e-6.

◆ fdl_dimensions_normalize()

fdl_dimensions_f64_t fdl_dimensions_normalize ( fdl_dimensions_f64_t  dims,
double  squeeze 
)

Normalize dimensions by applying anamorphic squeeze to width.

Converts from squeezed (sensor) coordinates to unsqueezed (display) coordinates. width *= squeeze; height unchanged.

Parameters
dimsDimensions to normalize.
squeezeAnamorphic squeeze factor (e.g. 2.0 for 2x anamorphic).
Returns
Normalized dimensions.

◆ fdl_dimensions_scale()

fdl_dimensions_f64_t fdl_dimensions_scale ( fdl_dimensions_f64_t  dims,
double  scale_factor,
double  target_squeeze 
)

Scale normalized dimensions and apply target squeeze.

width = (width * scale_factor) / target_squeeze; height = height * scale_factor.

Parameters
dimsNormalized dimensions to scale.
scale_factorScale multiplier.
target_squeezeTarget anamorphic squeeze to apply.
Returns
Scaled dimensions in target coordinate space.

◆ fdl_dimensions_normalize_and_scale()

fdl_dimensions_f64_t fdl_dimensions_normalize_and_scale ( fdl_dimensions_f64_t  dims,
double  input_squeeze,
double  scale_factor,
double  target_squeeze 
)

Normalize and scale in one step.

Equivalent to fdl_dimensions_scale(fdl_dimensions_normalize(dims, input_squeeze), ...).

Parameters
dimsDimensions to transform.
input_squeezeSource anamorphic squeeze factor.
scale_factorScale multiplier.
target_squeezeTarget anamorphic squeeze factor.
Returns
Transformed dimensions.

◆ fdl_dimensions_sub()

Subtract two dimensions: result = a - b.

Parameters
aMinuend dimensions.
bSubtrahend dimensions.
Returns
Component-wise difference (a.width - b.width, a.height - b.height).

◆ fdl_dimensions_equal()

int fdl_dimensions_equal ( fdl_dimensions_f64_t  a,
fdl_dimensions_f64_t  b 
)

Check if dimensions are approximately equal within FDL tolerance.

Uses relative tolerance of 1e-9 and absolute tolerance of 1e-6.

Parameters
aFirst dimensions.
bSecond dimensions.
Returns
FDL_TRUE if approximately equal, FDL_FALSE otherwise.

◆ fdl_dimensions_f64_gt()

int fdl_dimensions_f64_gt ( fdl_dimensions_f64_t  a,
fdl_dimensions_f64_t  b 
)

Check if a > b using OR logic (either width or height is greater).

Parameters
aFirst dimensions.
bSecond dimensions.
Returns
FDL_TRUE if a.width > b.width OR a.height > b.height, FDL_FALSE otherwise.

◆ fdl_dimensions_f64_lt()

int fdl_dimensions_f64_lt ( fdl_dimensions_f64_t  a,
fdl_dimensions_f64_t  b 
)

Check if a < b using OR logic (either width or height is less).

Parameters
aFirst dimensions.
bSecond dimensions.
Returns
FDL_TRUE if a.width < b.width OR a.height < b.height, FDL_FALSE otherwise.

◆ fdl_dimensions_is_zero()

int fdl_dimensions_is_zero ( fdl_dimensions_f64_t  dims)

Check if both width and height are zero.

Parameters
dimsDimensions to test.
Returns
FDL_TRUE if both components are zero, FDL_FALSE otherwise.

◆ fdl_dimensions_i64_is_zero()

int fdl_dimensions_i64_is_zero ( fdl_dimensions_i64_t  dims)

Check if both width and height are zero (int64 variant).

Parameters
dimsInteger dimensions to test.
Returns
FDL_TRUE if both components are zero, FDL_FALSE otherwise.

◆ fdl_dimensions_i64_normalize()

fdl_dimensions_f64_t fdl_dimensions_i64_normalize ( fdl_dimensions_i64_t  dims,
double  squeeze 
)

Normalize int64 dimensions by applying anamorphic squeeze to width.

Parameters
dimsInteger dimensions to normalize.
squeezeAnamorphic squeeze factor.
Returns
Float dimensions: width = width * squeeze, height unchanged.

◆ fdl_dimensions_f64_to_i64()

fdl_dimensions_i64_t fdl_dimensions_f64_to_i64 ( fdl_dimensions_f64_t  dims)

Convert float dimensions to int64 by truncation.

Parameters
dimsFloat dimensions to convert.
Returns
Integer dimensions (truncated toward zero).

◆ fdl_dimensions_i64_gt()

int fdl_dimensions_i64_gt ( fdl_dimensions_i64_t  a,
fdl_dimensions_i64_t  b 
)

Check if a > b using OR logic (either width or height is greater).

Parameters
aFirst dimensions.
bSecond dimensions.
Returns
FDL_TRUE if a.width > b.width OR a.height > b.height, FDL_FALSE otherwise.

◆ fdl_dimensions_i64_lt()

int fdl_dimensions_i64_lt ( fdl_dimensions_i64_t  a,
fdl_dimensions_i64_t  b 
)

Check if a < b using OR logic (either width or height is less).

Parameters
aFirst dimensions.
bSecond dimensions.
Returns
FDL_TRUE if a.width < b.width OR a.height < b.height, FDL_FALSE otherwise.

◆ fdl_point_normalize()

fdl_point_f64_t fdl_point_normalize ( fdl_point_f64_t  point,
double  squeeze 
)

Normalize a point by applying anamorphic squeeze to x.

Parameters
pointPoint to normalize.
squeezeAnamorphic squeeze factor.
Returns
Normalized point: x *= squeeze, y unchanged.

◆ fdl_point_scale()

fdl_point_f64_t fdl_point_scale ( fdl_point_f64_t  point,
double  scale_factor,
double  target_squeeze 
)

Scale a normalized point and apply target squeeze.

x = (x * scale_factor) / target_squeeze; y = y * scale_factor.

Parameters
pointNormalized point to scale.
scale_factorScale multiplier.
target_squeezeTarget anamorphic squeeze.
Returns
Scaled point in target coordinate space.

◆ fdl_point_add()

fdl_point_f64_t fdl_point_add ( fdl_point_f64_t  a,
fdl_point_f64_t  b 
)

Add two points: result = a + b.

Parameters
aFirst point.
bSecond point.
Returns
Component-wise sum.

◆ fdl_point_sub()

fdl_point_f64_t fdl_point_sub ( fdl_point_f64_t  a,
fdl_point_f64_t  b 
)

Subtract two points: result = a - b.

Parameters
aMinuend point.
bSubtrahend point.
Returns
Component-wise difference.

◆ fdl_point_mul_scalar()

fdl_point_f64_t fdl_point_mul_scalar ( fdl_point_f64_t  a,
double  scalar 
)

Multiply point by scalar.

Parameters
aPoint to scale.
scalarScalar multiplier applied to both x and y.
Returns
Scaled point.

◆ fdl_point_clamp()

fdl_point_f64_t fdl_point_clamp ( fdl_point_f64_t  point,
double  min_val,
double  max_val,
int  has_min,
int  has_max 
)

Clamp point values to [min_val, max_val].

Each bound is optional — set the corresponding has_* flag to enable it.

Parameters
pointPoint to clamp.
min_valMinimum bound (applied to both x and y).
max_valMaximum bound (applied to both x and y).
has_minFDL_TRUE to apply min_val, FDL_FALSE to skip.
has_maxFDL_TRUE to apply max_val, FDL_FALSE to skip.
Returns
Clamped point.

◆ fdl_point_is_zero()

int fdl_point_is_zero ( fdl_point_f64_t  point)

Check if both x and y are zero.

Parameters
pointPoint to test.
Returns
FDL_TRUE if both components are zero, FDL_FALSE otherwise.

◆ fdl_point_normalize_and_scale()

fdl_point_f64_t fdl_point_normalize_and_scale ( fdl_point_f64_t  point,
double  input_squeeze,
double  scale_factor,
double  target_squeeze 
)

Normalize and scale a point in one step.

Parameters
pointPoint to transform.
input_squeezeSource anamorphic squeeze factor.
scale_factorScale multiplier.
target_squeezeTarget anamorphic squeeze factor.
Returns
Transformed point.

◆ fdl_point_equal()

int fdl_point_equal ( fdl_point_f64_t  a,
fdl_point_f64_t  b 
)

Check approximate equality within FDL tolerances.

Parameters
aFirst point.
bSecond point.
Returns
FDL_TRUE if approximately equal, FDL_FALSE otherwise.

◆ fdl_point_f64_lt()

int fdl_point_f64_lt ( fdl_point_f64_t  a,
fdl_point_f64_t  b 
)

Check if a < b using OR logic (either x or y is less).

Parameters
aFirst point.
bSecond point.
Returns
FDL_TRUE if a.x < b.x OR a.y < b.y, FDL_FALSE otherwise.

◆ fdl_point_f64_gt()

int fdl_point_f64_gt ( fdl_point_f64_t  a,
fdl_point_f64_t  b 
)

Check if a > b using OR logic (either x or y is greater).

Parameters
aFirst point.
bSecond point.
Returns
FDL_TRUE if a.x > b.x OR a.y > b.y, FDL_FALSE otherwise.

◆ fdl_free()

void fdl_free ( void *  ptr)

Free memory allocated by fdl_core functions.

Use this for strings returned by serialization, error messages, and other heap-allocated values. Safe to call with NULL.

Parameters
ptrPointer to free, or NULL (no-op).