Crates.io | graphics-shapes |
lib.rs | graphics-shapes |
version | 0.4.4 |
source | src |
created_at | 2022-09-10 08:42:40.602083 |
updated_at | 2024-09-30 08:22:04.510623 |
description | Shapes for graphics |
homepage | |
repository | https://github.com/emmabritton/graphics_shapes |
max_upload_size | |
id | 662413 |
size | 147,696 |
Contains code to make and alter various shapes.
Primarily designed to be used with Buffer Graphics and Pixels graphics lib
Add this line to Cargo.toml
graphics-shapes = "0.4.4"
# or with both features (serde is enabled by default)
graphics-shapes = {version = "0.4.4", 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));
Line
Rect
Triangle
Circle
Ellipse
Polygon
contains
(Coord
| Shape
) - Returns true if param is entirely insideintersects
(Shape
) - Returns true if param is partially inside/touchingoutline_pixels
- Returns a list of points that can be used to draw a stroke versionfilled_pixels
- Returns a list of points that can be used to draw a filled versionrotate
, scale
, transform
- Copy and change the shapeAll the shapes have methods to create similar sized shapes of different types, e.g. Circle::to_outer_rect()
, Rect::to_triangles()
Each Shape
is a separate struct so to store them without putting them in a Box
you can use ShapeBox
which implements Shape
and so is fully compatible with other Shape
s and their methods.
This library uses debug assertions for some methods.
Default features: "serde"
serde
adds serde::{Serialize, Deserialize}
to Coord
, Line
, Rect
, Circle
, Triangle
, Ellipse
, Polygon
mint
adds a From
impl for Point2<isize>
to Coord
Ellipse
s don't plot correctly when rotated