@countertype/clipper2-ts

中文文档
1.5.4-3.9a869ba发布于 2025/11/17BSL-1.0TypeScriptCommonJS零依赖近 30 天下载 1.9万

TypeScript port of Clipper2 polygon clipping and offsetting library

此软件包已被标记为弃用

Package moved to clipper2-ts (no scope). Please update your dependencies

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. API
  4. Testing
  5. License
  6. Credits

clipper2-ts

npm version license

TypeScript port of Angus Johnson's Clipper2 library for polygon clipping and offsetting

Installation

npm install @countertype/clipper2-ts

Usage

import { Clipper, FillRule, JoinType, EndType } from '@countertype/clipper2-ts';

// Define polygons as arrays of points
const subject = [[
  { x: 0, y: 0 },
  { x: 100, y: 0 },
  { x: 100, y: 100 },
  { x: 0, y: 100 }
]];

const clip = [[
  { x: 50, y: 50 },
  { x: 150, y: 50 },
  { x: 150, y: 150 },
  { x: 50, y: 150 }
]];

// Boolean operations
const intersection = Clipper.intersect(subject, clip, FillRule.NonZero);
const union = Clipper.union(subject, clip, FillRule.NonZero);
const difference = Clipper.difference(subject, clip, FillRule.NonZero);
const xor = Clipper.xor(subject, clip, FillRule.NonZero);

// Polygon offsetting (inflate/deflate)
const offset = Clipper.inflatePaths(subject, 10, JoinType.Round, EndType.Polygon);

API

This port follows the structure and functionality of Clipper2's C# implementation, with method names adapted to JavaScript conventions. Where C# uses PascalCase for methods (AddPath, Execute), this port uses camelCase (addPath, execute). Class names remain unchanged

For detailed API documentation, see the official Clipper2 docs

Testing

The port includes 235 tests validating against Clipper2's reference test suite:

npm test              # Run all 235 tests
npm test:coverage     # Run with coverage report

Test results: 194/195 polygon tests pass (99.5%), matching C# reference implementation exactly. The single failure (Test 16, bow-tie polygon) also fails in C#

License

Boost Software License 1.0 (same as Clipper2)

Credits

Original library by Angus Johnson. TypeScript port by Jeremy Tribby

版本与发布记录

@countertype/clipper2-ts 共发布 5 个版本,首次发布于 2025/11/03;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.5.4-3.9a869balatest2025/11/1711 个月前
1.5.4-2.9a869ba2025/11/1511 个月前
1.5.4-1.9a869ba2025/11/1411 个月前
1.5.4-0.9a869ba2025/11/081 年前
1.5.42025/11/031 年前

关于 @countertype/clipper2-ts 的常见问题

@countertype/clipper2-ts 是什么?

TypeScript port of Clipper2 polygon clipping and offsetting library注意:该包已被作者标记为弃用——Package moved to clipper2-ts (no scope). Please update your dependencies

如何安装 @countertype/clipper2-ts?

在项目目录运行 npm install @countertype/clipper2-ts,或使用 pnpm add / yarn add / bun add。

@countertype/clipper2-ts 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@countertype/clipper2-ts 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@countertype/clipper2-ts 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@countertype/clipper2-ts 可以商用吗?

@countertype/clipper2-ts 使用 BSL-1.0 许可。声明的许可为 BSL-1.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@countertype/clipper2-ts 的下载量有多少?

根据 npm 官方下载统计,@countertype/clipper2-ts 在 2026/10/11 – 2026/11/09 这 30 天内被下载 19,495 次,日均约 650 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@countertype/clipper2-ts 还在维护吗?

最新版本 1.5.4-3.9a869ba 发布于 2025/11/17(11 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/11/03。作者已将其标记为弃用,新项目建议寻找替代方案。