9 个版本
0.1.9 | 2024 年 6 月 15 日 |
---|---|
0.1.8 | 2024 年 6 月 11 日 |
#313 in 数学
每月 305 次下载
31KB
619 行
多边形偏移
小型包,无依赖项,用于偏移多边形(仅边缘)。
特性
- 非常快
- 从一个简单的二维坐标 Vec (f64 元组) 计算其偏移轮廓、周长和面积
- 初始多边形必须是闭合的
- 您必须确保您的多边形不会相交
示例
cargo运行 --示例example_offsetting --发布
fn example_offsetting() -> Result <(), Box<dyn std::error::Error>> {
// 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(())
}
许可证
MIT License
Copyright (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.