#polygon #primitive #skeleton #buffer #geometric #straight #ecosystem

geo-buffer

This crate provides methods to buffer (to inflate or deflate) certain primitive geometric types in the GeoRust ecosystem via a straight skeleton

3 unstable releases

0.2.0 Jun 2, 2023
0.1.1 May 23, 2023
0.1.0 May 23, 2023

#2007 in Algorithms

Download history 20/week @ 2024-07-22 4/week @ 2024-08-05 15/week @ 2024-08-26 13/week @ 2024-09-02 23/week @ 2024-09-09 10/week @ 2024-09-16 57/week @ 2024-09-23 37/week @ 2024-09-30 51/week @ 2024-10-07 20/week @ 2024-10-14 56/week @ 2024-10-21 25/week @ 2024-10-28

153 downloads per month

Apache-2.0

88KB
1K SLoC

geo-buffer

geo-buffer on crates.io Rust 1.68+ Cargo 1.68+ Documentation

The geo-buffer crate provides methods to buffer (to enlarge or reduce) certain primitive geometric types in the GeoRust ecosystem via a straight skeleton.

This crate can handle simple polygons properly as well as non-convex polygons, (valid) sets of polygons, and polygons with one or more holes. Note that each method assumes valid primitives as a parameter, but Polygon/MultiPolygon modules do not enforce this validity automatically nor does this crate. (See more details on 'Validity' in Polygon/MultiPolygon and OGC standards.)

This crate uses a straight skeleton to buffer (multi-)polygons. You can also compute a straight skeleton separately by proper methods.

For now, the only viable geometric primitives are Polygon and MultiPolygon (the rest of the primitives will be added as well).

You can choose a style of convex corners with either options; mitter-joined or round-joined. (See more details on the document.)

Quick Guide

The buffer_polygon() function (resp. buffer_multi_polygon() function) produces a MultiPolygon after applying an buffer operation to the given Polygon (resp. MultiPolygon). The absolute value of the argument passed with determines the distance between each edge of the result multi-polygon and the original input. The sign determines the direction where the result expands. Positive values mean it goes outward &#8212 that is, it inflates, &#8212 and negative values mean goes inward &#8212 it deflates &#8212.

Code snippets below is a brief guide to use this crate. Click 'Result' to expand the visualized result. (The red polygon designates the input, and the orange one designates the results.)

Example

use geo_buffer::buffer_polygon;
use geo::{Polygon, MultiPolygon, LineString};

let p1 = Polygon::new(
    LineString::from(vec![(0., 0.), (1., 0.), (1., 1.), (0., 1.)]), vec![],
);
let p2: MultiPolygon = buffer_polygon(&p1, -0.2);

let expected_exterior = LineString::from(vec![(0.2, 0.2), (0.8, 0.2), (0.8, 0.8), (0.2, 0.8), (0.2, 0.2)]);
assert_eq!(&expected_exterior, p2.0[0].exterior())

Result

Usage

[dependencies]
geo-buffer = "0.1.0"

Dependencies

[dependencies]
geo-types = "0.7.9"
geo = "0.24.1"

Main Contributor

License

The geo-buffer crate is licensed under the Apache License (Version 2.0)

Contact

Dependencies

~3.5MB
~67K SLoC