4 releases

Uses new Rust 2021

0.1.3 Sep 16, 2022
0.1.2 Sep 11, 2022
0.1.1 Sep 10, 2022
0.1.0 Sep 10, 2022

#116 in Graphics APIs

Download history 25/week @ 2022-09-04 80/week @ 2022-09-11 19/week @ 2022-09-18 16/week @ 2022-09-25

140 downloads per month
Used in 2 crates

Custom license

45KB
1K SLoC

Shapes for Graphics

Contains code to make and alter lines, rectangles, circles, triangles and polygons.

Primarily designed to be use with Buffer Graphics and Graphics lib

Usage

Add this line to Cargo.toml

graphics-shapes = "0.1.3"
# or with both features
graphics-shapes = {version = "0.1.3", features = ["mint", "serde"] }

Code

let rect = Rect::new((10,10),(20,20));
assert!(rect.contains((15,15)));
let triangle = Triangle::new((34,5),(12,30),(9,10));
let rotated = triangle.rotate(45);

let start = Coord::new(20,130);
let dist = start.distance((30,130));

Shapes

All shapes have contains, rotate, scale and translate methods.

Each shape also has custom methods, for example, len on Line, union on Rect, angle_type on Triangle, etc

You should use Rect or Triangle over Polygon where possible as their math methods are optimised.

Assertions

This library uses debug assertions for some methods.

Features

Both are off by default

Serde

serde adds serde::{Serialize, Deserialize} to Coord, Line, Rect, Circle, Triangle, Polygon

Mint

mint adds a From impl for Point2<isize> to Coord

Dependencies

~165KB