Graphic Base Helpers User Guide¶
Overview¶
The BaseHelpers module provides lightweight inline conversion utilities designed specifically for the BareMetal graphics system. These helpers ensure safe arithmetic between different numeric types used throughout the graphics library.
Key Features¶
- Type-safe conversions between PointBaseType and 32-bit integers
- Automatic range clamping to prevent overflow
- Zero-cost abstraction suitable for embedded systems
- Inline implementation for optimal performance
Usage Patterns¶
// Converting unsigned 16-bit point coordinate to signed for calculations
CFBDGraphic_Point pt = {100, 50};
int32_t signed_x = asInt32_t(pt.x); // 100 -> 100 (signed)
int32_t signed_y = asInt32_t(pt.y); // 50 -> 50 (signed)
// Clamping coordinates after arithmetic operations
int32_t new_x = 100 + 50000; // Might overflow
PointBaseType safe_x = clamp_u16_from_i32(new_x);
// Result: UINT16_MAX (65535)
// Handling negative displacements
int32_t delta = -50;
PointBaseType pos = clamp_u16_from_i32(delta); // Result: 0
Graphics_Module
Updated on 2026-02-03 at 13:21:55 +0000