Clipper1 标志

Clipper1

社区
znlgis
clipper1

Use when maintaining legacy code on the Clipper 1.x API — IntPoint integer paths with a scale factor, Clipper.AddPath/Execute for ctUnion/ctIntersection/ctDifference/ctXor, ClipperOffset for jtRound/jtMiter buffering, PolyTree hole hierarchy, and the pyclipper (1.4.0) / js-clipper bindings. Clipper1 V6 (6.4.2) is frozen; new projects should use Clipper2. Also for lost hole structure in flat List<List<IntPoint>> results, self-intersections after offsetting, and scale overflow.

概览

发布者znlgis
代码仓库opengis-skills
技能名称clipper1
星标数
76
复刻数
12
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 znlgis 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Clipper1 AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/znlgis/opengis-skills/tree/main/cad/clipper1
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/znlgis/opengis-skills.git /tmp/opengis-skills
mkdir -p .claude/skills
cp -r /tmp/opengis-skills/cad/clipper1 .claude/skills/clipper1
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Clipper1,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Clipper1。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Clipper1 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

项目地址(V6 官方主页): https://sourceforge.net/p/polyclipping/

官方文档: https://sourceforge.net/p/polyclipping/wiki/Home/

版本: V6 末版 6.4.2(pyclipper 1.4.0 内嵌的即为该版)。原 GitHub 仓库 github.com/AngusJohnson/Clipper 已重定向到 Clipper2,V6 不再新增功能

包管理器: NuGet Clipper 6.4.0(Angus Johnson 发布)| PyPI pyclipper 1.4.0(封装 Clipper 6.4.2)| npm js-clipper 1.0.1(截至 2026-10)

许可证: Boost Software License 1.0

概述

Clipper1 主要特征:

  • 整数算法(IntPoint),通过 scale 系数模拟浮点
  • 核心 API:Clipper、ClipperOffset、ClipperBase
  • 支持:布尔运算 + 偏移 + 多边形简化
  • 多语言移植:C++(含 Header-only)、C#、Delphi/Pascal、JS、Python

新项目优先使用 Clipper2,其性能与 API 均优于 Clipper1。本 SKILL 主要用于维护遗留代码。


安装

bash
# C#(NuGet 包作者为 Angus Johnson,最新 6.4.0,略旧于 C++ V6 末版 6.4.2)
dotnet add package Clipper

# JavaScript
npm install js-clipper          # 1.0.1,或 clipper-lib

# Python
pip install pyclipper           # 1.4.0,内嵌 Clipper 6.4.2

验证:

bash
python -c "import pyclipper; print(pyclipper.__version__)"

C++ 通常直接拷贝 clipper.hpp/.cpp 到工程。


核心 API

核心数据结构

csharp
using ClipperLib;
using IntPoint = ClipperLib.IntPoint;

const long Scale = 1000000;     // 浮点 → 整数缩放因子

List<IntPoint> path = new() {
    new IntPoint(0, 0),
    new IntPoint(100 * Scale, 0),
    new IntPoint(100 * Scale, 100 * Scale),
    new IntPoint(0, 100 * Scale),
};
List<List<IntPoint>> paths = new() { path };

布尔运算

csharp
var clipper = new Clipper();
clipper.AddPath(subject, PolyType.ptSubject, true);   // true = 闭合
clipper.AddPath(clip,    PolyType.ptClip,    true);

var solution = new List<List<IntPoint>>();
clipper.Execute(ClipType.ctUnion, solution,
    PolyFillType.pftNonZero, PolyFillType.pftNonZero);

ClipType:ctIntersection、ctUnion、ctDifference、ctXor PolyFillType:pftEvenOdd、pftNonZero、pftPositive、pftNegative


多边形偏移(ClipperOffset)

csharp
var co = new ClipperOffset();
co.AddPaths(paths, JoinType.jtRound, EndType.etClosedPolygon);

var solution = new List<List<IntPoint>>();
co.Execute(ref solution, 10 * Scale);     // 正:外扩;负:内缩

JoinType:jtSquare、jtMiter、jtRound EndType:etClosedPolygon、etClosedLine、etOpenButt、etOpenSquare、etOpenRound


PolyTree(保留环层级)

csharp
var tree = new PolyTree();
clipper.Execute(ClipType.ctUnion, tree,
    PolyFillType.pftNonZero, PolyFillType.pftNonZero);

foreach (var node in tree.Childs)        // 顶层是外环
    foreach (var hole in node.Childs)    // 子节点是孔
        Console.WriteLine(hole.Contour.Count);

实用方法

csharp
double area    = Clipper.Area(path);
bool   ccw     = Clipper.Orientation(path);
var    cleaned = Clipper.CleanPolygon(path, 1.415);    // 去重/共线
var    simp    = Clipper.SimplifyPolygon(path, PolyFillType.pftNonZero);
var    reverse = Clipper.ReversePath(path);

Python(pyclipper)

python
import pyclipper

scale = 1_000_000
subj  = [[(0,0),(100,0),(100,100),(0,100)]]
clip  = [[(50,50),(150,50),(150,150),(50,150)]]

pc = pyclipper.Pyclipper()
pc.AddPaths(pyclipper.scale_to_clipper(subj, scale),
            pyclipper.PT_SUBJECT, True)
pc.AddPaths(pyclipper.scale_to_clipper(clip, scale),
            pyclipper.PT_CLIP, True)
sol = pc.Execute(pyclipper.CT_UNION,
                 pyclipper.PFT_NONZERO,
                 pyclipper.PFT_NONZERO)
sol = pyclipper.scale_from_clipper(sol, scale)

# 偏移
pco = pyclipper.PyclipperOffset()
pco.AddPaths(pyclipper.scale_to_clipper(subj, scale),
             pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
sol = pco.Execute(10 * scale)

C++ 用法

cpp
#include "clipper.hpp"
using namespace ClipperLib;

Paths subj{{ {0,0},{1000,0},{1000,1000},{0,1000} }};
Paths clip{{ {500,500},{1500,500},{1500,1500},{500,1500} }};
Clipper c;
c.AddPaths(subj, ptSubject, true);
c.AddPaths(clip, ptClip, true);
Paths solution;
c.Execute(ctUnion, solution, pftNonZero, pftNonZero);

典型工作流

工作流一:CAD/GIS 中多边形布尔运算

  1. 确定浮点精度需求,选定 scale 系数(如 1,000,000 表示微米精度)
  2. 将输入几何(Polygon/MultiLine 等)转换为 List<IntPoint> 格式,乘以 scale 取整
  3. 创建 Clipper 实例,AddPath 添加 Subject 和 Clip
  4. 调用 Execute 执行布尔运算(Union/Intersect/Difference/Xor)
  5. 将结果坐标除以 scale 还原为浮点坐标
  6. 如需保留孔洞关系,使用 PolyTree 替代 List<List<IntPoint>>

工作流二:多边形轮廓偏移(生成安全区/缓冲区)

  1. 构建多边形路径(闭合路径用 etClosedPolygon,开放用 etOpenButt 等)
  2. 创建 ClipperOffset,通过 AddPaths 添加输入
  3. 调用 Execute,正值为外扩(膨胀),负值为内缩(侵蚀)
  4. 检查结果是否自交——偏移前可先用 SimplifyPolygon 清理输入
  5. 输出偏移后的多边形用于刀路生成、安全距离计算等

与 Clipper2 主要差异

维度Clipper1Clipper2
数值类型整数 + scale整数 / 浮点双模式
性能较慢显著更快
APIClipper 类顶层 Union/Intersect/...
简化SimplifyPolygonSimplifyPaths 更准确
维护已停止新功能活跃维护

迁移要点:

  • IntPoint → Point64
  • 移除 scale,使用 PathsD 或保留 Paths64
  • API 改为静态函数

常见问题

问题解决
浮点 → 整数舍入失真增大 scale
偏移产生自相交偏移前 SimplifyPolygon
闭合 path 多余首尾点Clipper 不需要重复首点
Mac/Linux 编译失败启用 use_int32/use_xyz 对应宏
布尔结果丢了孔洞层级Execute 的出参换成 PolyTree(顶层 Childs 为外环、其子节点为孔),不要用扁平的 List<List<IntPoint>>
外扩后尖角被削平或出现毛刺按形状选 JoinType:尖角用 jtMiter(配合 MiterLimit)、圆弧用 jtRound、平角用 jtSquare;内缩毛刺先 CleanPolygon
开放线偏移结果不是预期条带EndType 必须是 etOpenButt/etOpenSquare/etOpenRound,误用 etClosedPolygon 会把线首尾闭合
面积正负号看不懂Clipper.Area 的符号就是朝向:正为外环、负为孔;需要翻转用 ReversePath,判断用 Orientation

AI 使用建议

  • 推荐工作流模式:AI 助手应将几何数据统一转换为 Clipper 的整数坐标格式(选择恰当的 scale),然后按「创建 Clipper → 添加路径 → 执行运算 → 还原坐标」的流程处理。对于带孔多边形,优先使用 PolyTree 保留层级关系。
  • 关键注意事项:① scale 选择需权衡精度与整数溢出——常用 1e6(微米级);② Clipper1 的闭合路径不需要重复首点;③ PolyFillType 需 Subject 和 Clip 各指定一次,非零环绕(NonZero)是最常用的填充规则;④ Clipper1 为非线程安全,多线程需各自持有实例。
  • 常用代码模式:new Clipper() → AddPath(subject, ptSubject, true) → AddPath(clip, ptClip, true) → Execute(ctUnion, solution, pftNonZero, pftNonZero)。

相关技能


参考资源

常见问题

Clipper1 AI 技能有什么作用?

Use when maintaining legacy code on the Clipper 1.x API — IntPoint integer paths with a scale factor, Clipper.AddPath/Execute for ctUnion/ctIntersection/ctDifference/ctXor, ClipperOffset for jtRound/jtMiter buffering, PolyTree hole hierarchy, and the pyclipper (1.4.0) / js-clipper bindings. Clipper1 V6 (6.4.2) is frozen; new projects should use Clipper2. Also for lost hole structure in flat List<List<IntPoint>> results, self-intersections after offsetting, and scale overflow.

为什么在 TypingMind 中使用 Clipper1?

因为您只需安装一次,就能搭配任何模型使用。Clipper1 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Clipper1?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/znlgis/opengis-skills/tree/main/cad/clipper1。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Clipper1?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Clipper1 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Clipper1 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Clipper1 AI 技能免费吗?

是的。znlgis 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇