Skip to main content

Crate clipper2_sys

Crate clipper2_sys 

Source
Expand description

§Examples cookbook / 示例合集

§Clipper64: union + lazy closed / 布尔并 + 惰性闭合解

use clipper2_sys::{
    ClipType, Clipper64, FillRule, Paths64, Point64,
};

let mut clip = Clipper64::new();
clip.add_subject(&Paths64::new(vec![square_i(0, 0, 100)]));
clip.add_clip(&Paths64::new(vec![square_i(50, 50, 100)]));
let sol = clip.execute(ClipType::Union, FillRule::NonZero);
let (closed, _open) = sol.into_lazy();
assert!(!closed.is_empty());

§Clipper64: iterate closed paths / 逐条遍历闭合路径

use clipper2_sys::{
    ClipType, Clipper64, FillRule, Path64, Paths64, Point64,
};

let mut clip = Clipper64::new();
clip.add_subject(&Paths64::new(vec![square_i(0, 0, 100)]));
clip.add_clip(&Paths64::new(vec![square_i(50, 50, 100)]));
let sol = clip.execute(ClipType::Union, FillRule::NonZero);
let all: Paths64 = sol.iter_closed().chain(sol.iter_open()).collect();
assert!(!all.is_empty());

§Clipper64: execute_tree + preorder on PolyPath / 树形解与前序遍历

use clipper2_sys::{
    ClipType, Clipper64, FillRule, Path64, Paths64, Point64,
};

let mut clip = Clipper64::new();
clip.add_subject(&Paths64::new(vec![square_i(0, 0, 100)]));
clip.add_clip(&Paths64::new(vec![square_i(50, 50, 100)]));
let sol = clip.execute_tree(ClipType::Union, FillRule::NonZero);
let (_open_lazy, preorder) = sol.into_open_and_poly_preorder();
let n = preorder.count();
assert!(n > 0);

§ClipperD: union / 双精度布尔并

use clipper2_sys::{
    ClipType, ClipperD, FillRule, PathD, PathsD, PointD,
};

let mut clip = ClipperD::new(4);
clip.add_subject(&PathsD::new(vec![square_f(0.0, 0.0, 100.0)]));
clip.add_clip(&PathsD::new(vec![square_f(50.0, 50.0, 100.0)]));
let sol = clip.execute(ClipType::Union, FillRule::NonZero);
let (closed, _open) = sol.into_lazy();
assert!(!closed.is_empty());

§ClipperOffset: inflate a square / 方形外扩

use clipper2_sys::{ClipperOffset, EndType, JoinType, Path64, Point64};

let path = Path64::new(vec![
    Point64::new(0, 0),
    Point64::new(100, 0),
    Point64::new(100, 100),
    Point64::new(0, 100),
]);
let mut co = ClipperOffset::new(2.0, 0.0, false, false);
co.add_path(&path, JoinType::MiterJoin, EndType::PolygonEnd);
let out = co.execute(10.0);
assert!(!out.is_empty());

§Path64: area, point-in-polygon, translate, simplify / 面积、点包含、平移、简化

use clipper2_sys::{Path64, Point64, PointInPolygonResult};

let p = Path64::new(vec![
    Point64::new(0, 0),
    Point64::new(10, 0),
    Point64::new(10, 10),
    Point64::new(0, 10),
]);
assert!((p.area().abs() - 100.0).abs() < 1e-3);
assert!(matches!(
    p.point_in_polygon(Point64::new(5, 5)),
    PointInPolygonResult::Inside
));
let t = p.translate(3, -2);
assert_eq!(t.get_point(0).x, 3);
let collinear = Path64::new(vec![
    Point64::new(0, 0),
    Point64::new(5, 0),
    Point64::new(10, 0),
    Point64::new(10, 10),
]);
let simp = collinear.simplify(1.0, false);
assert!(simp.into_first_path().len() <= collinear.len());

§Paths64: inflate (offset helper) / 多路径偏移

use clipper2_sys::{EndType, JoinType, Path64, Paths64, Point64};

let paths = Paths64::new(vec![Path64::new(vec![
    Point64::new(0, 0),
    Point64::new(100, 0),
    Point64::new(100, 100),
    Point64::new(0, 100),
])]);
let grown = paths.inflate(10.0, JoinType::MiterJoin, EndType::PolygonEnd, 2.0);
assert!(!grown.is_empty());

§Path64 / Paths64: Minkowski sum / 闵可夫斯基和

use clipper2_sys::{FillRule, Path64, Paths64, Point64};

let a = square_i(0, 0, 50);
let b = square_i(0, 0, 30);
let ms = a.minkowski_sum(&b, true);
assert!(!ms.is_empty());

let many = Paths64::new(vec![square_i(0, 0, 40)]);
let ms2 = many.minkowski_sum(&b, true, FillRule::NonZero.into());
assert!(!ms2.is_empty());

§PathDPath64: simplify and convert / 双精度简化与转整型

use clipper2_sys::{LazyPaths64, PathD, PointD};

let p = PathD::new(vec![
    PointD::new(0.0, 0.0),
    PointD::new(5.0, 0.0),
    PointD::new(10.0, 0.0),
    PointD::new(10.0, 10.0),
]);
let simplified = p.simplify(1.0, false);
let _: LazyPaths64 = p.to_path64();
assert!(simplified.into_first_path().len() <= p.len());

§ClipSolution: to_closed / 物化全部闭合多边形

use clipper2_sys::{
    ClipType, Clipper64, FillRule, Path64, Paths64, Point64,
};

let mut clip = Clipper64::new();
clip.add_subject(&Paths64::new(vec![square_i(0, 0, 100)]));
clip.add_clip(&Paths64::new(vec![square_i(50, 50, 100)]));
let sol = clip.execute(ClipType::Union, FillRule::NonZero);
let closed: Paths64 = sol.to_closed();
assert!(!closed.is_empty());

§ClipTreeSolution: open-only shortcut / 只要开放解

use clipper2_sys::{
    ClipType, Clipper64, FillRule, Path64, Paths64, Point64,
};

let mut clip = Clipper64::new();
clip.add_subject(&Paths64::new(vec![square_i(0, 0, 100)]));
clip.add_clip(&Paths64::new(vec![square_i(50, 50, 100)]));
let sol = clip.execute_tree(ClipType::Union, FillRule::NonZero);
let _open = sol.into_open_lazy();

§Module map / 模块结构

  • clipper64 (logic in src/clipper64/, types re-exported here) — integer paths and Clipper64. / 整数路径与 Clipper64,实现位于 clipper64 子目录。
  • clipperd — double paths and ClipperD. / 双精度路径与 ClipperD
  • ClipperOffset — path offset (inflate/deflate). / 路径偏移。

Structs§

ClipSolution64
Result of Clipper64::execute: closed and open solutions as C++ blobs.
ClipSolutionD
Result of ClipperD::execute. / ClipperD::execute 的返回值。
ClipTreeSolution64
Result of Clipper64::execute_tree: optional PolyPath64 root + open paths.
ClipTreeSolutionD
Result of ClipperD::execute_tree. / ClipperD::execute_tree 的返回值。
Clipper64
Integer-coordinate Clipper2 boolean engine (Clipper64).
ClipperD
Double-precision Clipper2 engine (ClipperD); precision controls decimal places.
ClipperOffset
Clipper2 path offsetter: inflate or deflate polygons/polylines (integer Path64).
LazyPaths64
Lazy view of multiple Path64 from a C++ PathsBlob64 (one path per next()).
LazyPathsD
Lazy iterators over PathD entries from a PathsBlobD.
Path64
Integer grid polyline / polygon ring (Path64), backed by Vec<Point64>.
PathD
Double-precision polyline / polygon (PathD).
Paths64
Owned collection of closed/open paths in integer space.
PathsBlob64Iter
Iterator over each path inside a PathsBlob64 (allocates one Path64 per step).
PathsBlobDIter
Iterator over paths in a PathsBlobD. / 遍历 PathsBlobD 中的路径。
PathsD
Collection of double-precision paths.
PolyCxxNode64
One node while traversing a C++ PolyPath64 in preorder.
PolyCxxNodeD
Node during preorder on PolyPathD. / PolyPathD 前序结点。
PolyCxxPreorderIter64
Owns a native root; yields PolyCxxNode64 in preorder; frees via cxx_poly64_delete on drop.
PolyCxxPreorderIterD
Preorder iterator with cxx_polyd_delete on drop. / 前序迭代,Dropcxx_polyd_delete

Enums§

ClipType
Boolean clip operation between subject and clip paths.
EndType
End cap / polygon closure mode for open paths in offsetting.
FillRule
Polygon fill rule (non-zero, even-odd, …), maps to Clipper2 FillRule.
JoinType
Vertex join style for offsets and offset-like operations.
PointInPolygonResult
Point-in-polygon classification result.

Type Aliases§

Point64
Single point on the integer Clipper2 grid (Point64); same layout as cxx P64.
PointD
Double-precision point (PointD); same layout as cxx PD.