跳转至

point.h

Point and Vector data structures and utility functions for 2D graphics.

Classes

Name
struct CFBDGraphic_Point
Represents a 2D point in the graphics coordinate system.
struct CFBDGraphic_Vec2i
Represents a 2D vector with signed 32-bit integer components.

Source code

#pragma once
#include "cfbd_graphic_define.h"

typedef struct
{
    PointBaseType x; 
    PointBaseType y; 
} CFBDGraphic_Point;

typedef struct
{
    int32_t x; 
    int32_t y; 
} CFBDGraphic_Vec2i;

static inline CFBDGraphic_Point point_add(CFBDGraphic_Point a, CFBDGraphic_Point b)
{
    uint32_t x = (uint32_t) a.x + b.x;
    uint32_t y = (uint32_t) a.y + b.y;

    if (x > UINT16_MAX)
        x = UINT16_MAX;
    if (y > UINT16_MAX)
        y = UINT16_MAX;

    return (CFBDGraphic_Point) {(uint16_t) x, (uint16_t) y};
}

static inline CFBDGraphic_Vec2i point_sub(CFBDGraphic_Point a, CFBDGraphic_Point b)
{
    return (CFBDGraphic_Vec2i) {(int32_t) a.x - (int32_t) b.x, (int32_t) a.y - (int32_t) b.y};
}

 // End of Point_Module group

Updated on 2026-02-03 at 13:21:55 +0000