25个版本
| 0.4.1 | 2024年3月20日 |
|---|---|
| 0.3.0 | 2023年12月27日 |
| 0.2.2 | 2023年5月20日 |
| 0.1.11 | 2023年2月5日 |
| 0.1.4 | 2022年11月6日 |
#185 in 数学
每月21次下载
在2个包中使用(通过buffer-graphics-lib)
135KB
3.5K SLoC
图形形状
包含创建和修改各种形状的代码。
主要设计为与Buffer Graphics和Pixels graphics lib一起使用
使用方法
将此行添加到Cargo.toml
graphics-shapes = "0.4.0"
# or with both features (serde is enabled by default)
graphics-shapes = {version = "0.4.0", features = ["mint"] }
示例
let rect = Rect::new((10,10),(20,20));
assert!(rect.contains(coord!(15,15)));
let triangle = Triangle::new((34,5),(12,30),(9,10));
let rotated = triangle.rotate(45);
let start = coord!(20,130);
let dist = start.distance((30,130));
形状
线矩形三角形圆形椭圆形多边形
共享方法
contains(Coord|Shape) - 如果参数完全在内部则返回trueintersects(Shape) - 如果参数部分在内部或接触则返回trueoutline_pixels- 返回可以用来绘制轮廓版本的点的列表filled_pixels- 返回可以用来绘制填充版本的点的列表rotate、scale、transform- 复制并更改形状
每个形状的方法
所有形状都有创建不同类型、相似大小形状的方法,例如 Circle::to_outer_rect()、Rect::to_triangles()
处理多个形状
每个Shape都是一个独立的struct,因此为了存储它们而不用将它们放入Box中,可以使用ShapeBox,它实现了Shape,因此与其他Shape及其方法完全兼容。
断言
此库在有些方法中使用调试断言。
特性
默认特性:"serde"
Serde
serde 将 serde::{Serialize, Deserialize} 添加到 Coord、Line、Rect、Circle、Triangle、Ellipse、Polygon
Mint
mint 为 From 实现了 Point2<isize> 到 Coord
已知问题
Ellipse在旋转时渲染不正确
依赖关系
~0.4–1MB
~23K SLoC