百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

iOverlay

> 开发工具
开源

2D 多边形的布尔运算: 支持所有多边形类型的交集、并集、差集、异或和自交集。

196 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

2D 多边形的布尔运算: 支持所有多边形类型的交集、并集、差集、异或和自交集。

iOverlay

iOverlay is a high-performance polygon overlay engine for Rust. It solves robust boolean operations on complex polygons for GIS, CAD, and graphics workflows, built for developers who need reliable geometry at scale across integer and floating-point APIs.

iOverlay powers polygon boolean operations in geo.

For specialized geometry, see iCurve for polygon boolean operations with Bézier curves and xOverlay for high-performance boolean operations on orthogonal (Manhattan) polygons.

Table of Contents

  • Why iOverlay?
  • Features
  • Demo
  • Performance
  • Getting Started
    • Quick Start
  • Boolean Operations
    • Simple Example
    • Flat Shape Hierarchy
    • Overlay Rules
    • Edge Attributes and Provenance
  • Spatial Predicates
  • Custom Point Type Support
  • Slicing & Clipping
    • Slicing a Polygon with a Polyline
    • Clipping a Polyline by a Polygon
  • Buffering
    • Offsetting a Path
    • Offsetting a Polygon
    • LineCap
    • LineJoin
  • Integer Coordinate Limits
  • FAQ
  • License

 

Why iOverlay?

  • Built for robust polygon overlays where precision matters (GIS, CAD, graphics).
  • High performance with predictable results across complex inputs.
  • Supports both integer and floating-point APIs for flexible pipelines.
  • OGC-valid output is available when strict topology is required.
  • Core overlay engine used in geo.

 

Features

  • Boolean Operations: union, intersection, difference, and exclusion.
  • Spatial Predicates: intersects, disjoint, interiors_intersect, touches, within, covers with early-exit optimization.
  • Polyline Operations: clip and slice.
  • Polygons: with holes, self-intersections, and multiple contours.
  • Flat Shape Hierarchy: FFI-friendly shape, hole, and nested-island relationships.
  • Simplification: removes degenerate vertices and merges collinear edges.
  • Buffering: offsets paths and polygons.
  • Fill Rules: even-odd, non-zero, positive and negative.
  • Data Types: supports i16/i32/i64 integer APIs and f32/f64 floating-point APIs.

 

Demo

  • Stars Rotation
  • Boolean Operations
  • Stroke Offset
  • Polygon Offset
  • Overlay Editor

 

Performance

iOverlay supports:

  • i16/i32/i64 integer engines
  • Optional multithreading for large inputs through the allow_multithreading Cargo feature
toml
[dependencies]
i_overlay = { version = "^8.1", features = ["allow_multithreading"] }

For bigger data sets, the math engine and multithreading mode have a larger impact on runtime.

See the detailed reports: Performance Comparison and Rust Solver Benchmarks

 

Getting Started

Add the following to your Cargo.toml:

toml
[dependencies]
i_overlay = "^8.1"

Read full documentation

Quick Start

rust
use i_overlay::core::fill_rule::FillRule;
use i_overlay::core::overlay_rule::OverlayRule;
use i_overlay::float::single::SingleFloatOverlay;

let subj = [[0.0, 0.0], [4.0, 0.0], [4.0, 4.0], [0.0, 4.0]];
let clip = [[2.0, 2.0], [6.0, 2.0], [6.0, 6.0], [2.0, 6.0]];

let result = subj.overlay(&clip, OverlayRule::Intersect, FillRule::EvenOdd);
println!("result: {:?}", result);

 

Boolean Operations

Simple Example

Here's an example of performing a union operation between two polygons:

…

 

The result is a vec of shapes:

[
    // first shape
    [
        // main contour (counterclockwise order)
        [
            [0.0, 3.0], [0.0, 2.0], [1.0, 2.0], [1.0, 0.0], [4.0, 0.0], [4.0, 2.0], [5.0, 2.0], [5.0, 3.0], [4.0, 3.0], [4.0, 5.0], [1.0, 5.0], [1.0, 3.0]
        ],
        // first hole (clockwise order)
        [
            [2.0, 1.0], [2.0, 2.0], [3.0, 2.0], [3.0, 1.0]
        ],
        // second hole (clockwise order)
        [
            [2.0, 3.0], [2.0, 4.0], [3.0, 4.0], [3.0, 3.0]
        ]
    ]
    // ... other shapes if present
]

 

The overlay function returns Shapes , which is an alias for Vec:

  • Shapes : a collection of shapes.
  • Shape : a shape made up of:
    • Vec: a list of contours.
    • The first contour is the outer boundary (counterclockwise), and subsequent contours represent holes (clockwise).
  • Contour : a sequence of points (Vec ) forming a closed contour, where P implements FloatPointCompatible.

Note: By default, outer boundaries are counterclockwise and holes are clockwise—unless main_direction is set. More information about contours.

 

Flat Shape Hierarchy

The regular overlay result groups each outer contour with its holes, but shapes nested inside those holes are separate entries. Use overlay_hierarchy when you also need the immediate parent-hole relationship.

…

 

Overlay Rules

A,B A ∪ B A ∩ B A - B B - A A ⊕ B

 

Edge Attributes and Provenance

Use EdgeOverlay when the result boundary needs to keep data from the original input edges: source ids, layer ids, material ids, constraints, styles, or any other edge provenance. The regular Overlay API remains optimized for plain geometry; this API is opt-in and works with user-defined payloads.

When an input edge is split by intersections, its data is copied by default. When coincident edges are merged, your OverlayEdgeData implementation decides what the resulting data means. A common policy is to keep identical values and mark conflicts as Undefined.

…

This API currently targets integer boolean operations and exports the result as vector shapes. It keeps the same contour structure as the regular polygon API, but each contour item is an edge with propagated data. Collinear edges are simplified only when their data is equal, so attribute boundaries are preserved.

 

Spatial Predicates

When you only need to know whether two shapes have a spatial relationship—not compute their intersection geometry—use spatial predicates for better performance:

…

These methods use early-exit optimization, returning as soon as the predicate can be determined without processing remaining segments.

Fixed-Scale Predicates

For consistent precision across operations, use FixedScaleFloatRelate:

rust
use i_overlay::float::scale::FixedScaleFloatRelate;

let square = vec![[0.0, 0.0], [0.0, 10.0], [10.0, 10.0], [10.0, 0.0]];
let other = vec![[5.0, 5.0], [5.0, 15.0], [15.0, 15.0], [15.0, 5.0]];

let scale = 1000.0;  // or 1.0 / grid_size

let result = square.intersects_with_fixed_scale(&other, scale);
assert!(result.unwrap());

For more control, use FloatPredicateOverlay directly:

rust
use i_overlay::float::relate::FloatPredicateOverlay;

let square = vec![[0.0, 0.0], [0.0, 10.0], [10.0, 10.0], [10.0, 0.0]];
let clip = vec![[5.0, 5.0], [5.0, 15.0], [15.0, 15.0], [15.0, 5.0]];

// Use fixed-scale constructor
let mut overlay = FloatPredicateOverlay::with_subj_and_clip_fixed_scale(
    &square, &clip, 1000.0
).unwrap();

assert!(overlay.intersects());

 

Custom Point Type Support

iOverlay allows users to define custom point types, as long as they implement the FloatPointCompatible trait.

…

 

Slicing & Clipping

Slicing a Polygon with a Polyline

rust
use i_overlay::core::fill_rule::FillRule;
use i_overlay::float::slice::FloatSlice;

let polygon = [
    [1.0, 1.0],
    [1.0, 4.0],
    [4.0, 4.0],
    [4.0, 1.0],
];

let slicing_line = [
    [3.0, 5.0],
    [2.0, 2.0],
    [3.0, 3.0],
    [2.0, 0.0],
];

let result = polygon.slice_by(&slicing_line, FillRule::NonZero);

println!("result: {:?}", result);

 

Clipping a Polyline by a Polygon

rust
use i_overlay::core::fill_rule::FillRule;
use i_overlay::float::clip::FloatClip;
use i_overlay::string::clip::ClipRule;

let polygon = [
    [1.0, 1.0],
    [1.0, 4.0],
    [4.0, 4.0],
    [4.0, 1.0],
];

let string_line = [
    [3.0, 5.0],
    [2.0, 2.0],
    [3.0, 3.0],
    [2.0, 0.0],
];

let clip_rule = ClipRule { invert: false, boundary_included: false };
let result = string_line.clip_by(&polygon, FillRule::NonZero, clip_rule);

println!("result: {:?}", result);

 

Buffering

Offsetting a Path

rust
use i_overlay::mesh::stroke::offset::StrokeOffset;
use i_overlay::mesh::style::{LineCap, LineJoin, StrokeStyle};

let path = [
    [ 2.0, 1.0],
    [ 5.0, 1.0],
    [ 8.0, 4.0],
    [11.0, 4.0],
    [11.0, 1.0],
    [ 8.0, 1.0],
    [ 5.0, 4.0],
    [ 2.0, 4.0],
];

let style = StrokeStyle::new(1.0)
    .line_join(LineJoin::Miter(1.0))
    .start_cap(LineCap::Round(0.1))
    .end_cap(LineCap::Square);

let shapes = path.stroke(style, false);

println!("result: {:?}", shapes);

 

Offsetting a Polygon

…

Note:

  • Offsetting a polygon works reliably only with valid polygons. Ensure that:

    • No self-intersections.
    • Outer boundaries are counterclockwise, holes are clockwise—unless main_direction is set.

    If polygon validity cannot be guaranteed, it is recommended to apply the simplify_shape operation before offsetting.
    More information on contour orientation.

 

LineCap

Butt Square Round Custom

 

LineJoin

Bevel Miter Round

 

Integer Coordinate Limits

For an N-bit engine, keep each input coordinate within -2^(N - 2)..=2^(N - 2) - 1 (inclusive):

Engine Minimum x or y Maximum x or y
i16 -16,384 16,383
i32 -1,073,741,824 1,073,741,823
i64 -4,611,686,018,427,387,904 4,611,686,018,427,387,903

These limits leave room for coordinate differences and their products. They apply to all inputs and solver strategies. Integer APIs do not check them; exceeding these bounds can cause overflow or incorrect results. Use a wider engine or rescale larger inputs. See the range derivation and arithmetic audit for details.

For float APIs, the limits apply after conversion. An explicit conservative budget is FloatPointAdapter::with_coordinate_bits(rect, I::BITS - 3).

FAQ

1. When should I use FloatOverlay, SingleFloatOverlay, or FloatOverlayGraph?

  • Use FloatOverlay when you perform repeated overlay operations:
…
  • Use SingleFloatOverlay trait for one-shot operations.

  • Use FloatOverlayGraph if you need to extract multiple boolean results (e.g. union and intersection) from the **same

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustboolean-operationcadcomputational-geometrygamedev

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具