12_C++精灵库之polygon_region_filler.h头文件源代码(2026年1月15日版)

// polygon_region_filler.h
#ifndef POLYGON_REGION_FILLER_H
#define POLYGON_REGION_FILLER_H

#include <vector>
#include "polygon_offset.h"  // 你的头文件

struct RegionInfo {
    std::vector<Point> boundary;  // 子区域的边界点(闭合)
    Point centroid;               // 种子点(重心)
    bool is_valid;               // 区域是否有效(面积足够大)
};

class PolygonRegionFiller {
public:
    // 构造函数
    PolygonRegionFiller(const std::vector<Point>& points, double line_width = 4.0);
    
    // 分解多边形并获取所有可填充区域
    std::vector<RegionInfo> getFillableRegions();
    
private:
    // 原始多边形点
    std::vector<Point> original_points_;
    
    // 线宽
    double line_width_;
    
    // 内部辅助函数
    std::vector<Point> findIntersectionPoints();
    std::vector<std::vector<Point>> splitAtIntersections(const std::vector<Point>& points);
    Point calculateCentroid(const std::vector<Point>& polygon);
    double calculateArea(const std::vector<Point>& polygon);
    bool isPointInsidePolygon(const Point& p, const std::vector<Point>& polygon);
    bool isPolygonClockwise(const std::vector<Point>& polygon);
    std::vector<std::vector<Point>> extractSimplePolygons(const std::vector<Point>& points);
    void removeDuplicatePoints(std::vector<Point>& points);
    double distanceBetweenPoints(const Point& a, const Point& b);
};

#endif // POLYGON_REGION_FILLER_H

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在C++分类目录。将固定链接加入收藏夹。

发表回复