Files

54 lines
1.5 KiB
C++
Raw Permalink 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.
/**
* @file polygon_offset.h
* @brief 多边形等距偏移 (Polygon Offset / Inset)
*
* 基于直骨架 (Straight Skeleton) 近似的多边形
* 膨胀/收缩操作。用于 2D 轮廓生成、刀具路径补偿等。
*
* @ingroup boolean
*/
#pragma once
#include "vde/core/polygon.h"
#include <vector>
namespace vde::boolean {
using core::Point2D;
using core::Polygon2D;
/**
* @brief 多边形等距偏移
*
* 将多边形的每条边沿其法线方向平移指定距离,
* 在转角处自动生成圆弧/斜角连接。
*
* 算法:
* 1. 对每条边计算单位外法线
* 2. 沿法线平移 distance 距离
* 3. 相邻偏移边求交形成新的顶点
* 4. 检测自交并移除退化区域
*
* - 正距离 = 外扩(膨胀/Inflation
* - 负距离 = 内缩(偏置/Deflation
*
* @param poly 原始多边形
* @param distance 偏移距离(正=外扩,负=内缩)
* @return 偏移后的多边形列表(内缩或自交可能产生多个碎片)
*
* @note 使用直骨架近似而非精确圆弧偏移,转角处为斜角连接。
* 大距离负偏移可能导致多边形完全消失(返回空列表)。
*
* @code{.cpp}
* Polygon2D rect = {{0,0}, {10,0}, {10,5}, {0,5}};
* // 外扩 2 单位
* auto inflated = polygon_offset(rect, 2.0);
* // 内缩 1 单位(生成工具路径)
* auto toolpath = polygon_offset(rect, -1.0);
* @endcode
*
* @see boolean_2d
*/
std::vector<Polygon2D> polygon_offset(const Polygon2D& poly, double distance);
} // namespace vde::boolean