Crate iron_shapes_booleanop[][src]

Expand description

Library for boolean operations on polygons.

Example

use iron_shapes::prelude::*;
use iron_shapes_booleanop::BooleanOp;

// Create two polygons.
let p1 = Polygon::from(vec![(0., 0.), (2., 0.), (2., 1.), (0., 1.)]);
let p2 = p1.translate((1., 0.).into()); // Shift p1 by (1, 0).

// Compute the boolean intersection of the two squares.
let intersection = p1.intersection(&p2);
assert_eq!(intersection.polygons.len(), 1);
assert_eq!(intersection.polygons[0], Polygon::from(vec![(1., 0.), (2., 0.), (2., 1.), (1., 1.)]));

// Compute the boolean exclusive-or of the two squares.
// This results in two unconnected polygons. This demonstrates why boolean operations return always
// a `MultiPolygon`.
let intersection = p1.xor(&p2);
assert_eq!(intersection.polygons.len(), 2);

Enums

Operation

Type of boolean operation.

PolygonSemantics

Define the ‘inside’ of a polygon. Significant for self-overlapping polygons.

Traits

BooleanOp

Trait for geometric primitives that support boolean operations.

Functions

boolean_op

Perform boolean operation.

edge_intersection_float

Compute approximate intersection point of two edges in floating point coordinates.

edge_intersection_integer

Compute intersection of edges in integer coordinates. For edges that are parallel to the x or y axis the intersection can be computed exactly. For others it will be rounded.

edge_intersection_rational

Compute the intersection of edges with rational coordinates. In rational coordinates intersections can be computed exactly.