Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Akirami/polygon-offsetting
https://github.com/Akirami/polygon-offsetting
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/Akirami/polygon-offsetting
- Owner: Akirami
- License: mit
- Created: 2024-06-11T08:57:58.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-15T07:53:55.000Z (5 months ago)
- Last Synced: 2024-07-15T08:46:49.369Z (4 months ago)
- Language: Rust
- Size: 58.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-georust - polygon-offsetting - Offset a polygon (only margin). (Watchlist)
README
# polygon-offsetting
Small crate, no dependencies, to offset a polygon (only margin).
## Features
- very fast
- from a simple Vec of 2D coordinates (f64 tuples), compute its offset contour, its perimeter and area
- the initial polygon must be closed
- you must ensure that your polygon does not intersect itself## Examples
`cargo run --example example_offsetting --release`
```rust
fn example_offsetting() -> Result <(), Box> {
// the initial polygon must be closed
let points: Vec<(f64, f64)> = vec![
(0., 0.),
(100., 0.),
(40., 20.),
(100., 20.),
(100., 60.),
(95., 78.),
(55., 40.),
(0., 60.),
(0.0, 0.0)
];// the size of our margin, if egal to 0 no offsetting will be computed
let offset_size: f64 = 12.25;
// tolerance is the arc segments precision in polygon offsetting (rounded corner)
let tolerance: f64 = 0.1;let mut polygon = Polygon::new(&points, offset_size).map_err(|e| { e })?;
let offset: Offset = polygon.offsetting(tolerance).map_err(|e| { e })?;println!("Initial contour length: {:?}", points.len());
println!("Offset contour length: {:?}", offset.contour.len());
println!("offset area: {:?}", offset.area);
println!("offset perimeter: {:?}", offset.perimeter);
draw_svg_offset(
&points,
&offset,
"/examples/svg/",
"example_offsetting",
).map_err(|e| {
print!("Error on creating offset svg: {:?}", e);
e
})?;Ok(())
}
```## Licence
```
MIT LicenseCopyright (c) 2024 Akirami
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```