Files
zdwm/src/rect.h
Zedhugh Chen 2fc4b33359 style: 更新 .clang-format 规则并重新格式化所有源文件
- 重构模块使用新的代码风格
- 老代码 (src 目录下的代码) 继续使用之前的代码风格

通过在需要不同代码风格的目录下放对应 .clang-format 配置文件实现
2026-04-14 01:52:53 +08:00

43 lines
1.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <stddef.h>
#include <stdint.h>
typedef struct rect_t {
int32_t x1;
int32_t y1;
int32_t x2;
int32_t y2;
} rect_t;
bool rect_intersection(rect_t a, rect_t b, rect_t *intersection);
size_t rect_subtract(rect_t source, rect_t clip, rect_t remaining[4]);
/**
* @brief 从 source 中按顺序减去 clips 中的多个矩形
* @param source 源矩形
* @param clips 要减去的矩形数组,可为 nullptr
* @param clip_count clips 的长度
* @param remaining 输出剩余矩形数组;若不为
* nullptr则由函数分配内存并由调用方释放
* @return 剩余矩形数量
*
* @code{.c}
* rect_t source = {.x1 = 0, .y1 = 0, .x2 = 100, .y2 = 80};
* rect_t clips[] = {
* {.x1 = 10, .y1 = 10, .x2 = 40, .y2 = 40},
* {.x1 = 30, .y1 = 20, .x2 = 70, .y2 = 60},
* };
*
* rect_t *remaining = nullptr;
* size_t count = rect_subtract_many(source, clips, 2, &remaining);
*
* for (size_t i = 0; i < count; i++) {
* // use remaining[i]
* }
*
* free(remaining);
* @endcode
*/
size_t rect_subtract_many(rect_t source, const rect_t clips[],
size_t clip_count, rect_t **remaining);