rect-lib

Crates.iorect-lib
lib.rsrect-lib
version0.1.1
sourcesrc
created_at2024-04-22 19:10:16.407457
updated_at2024-04-22 19:22:38.590901
descriptionA simple library for working with anything vaguely rectangular
homepagehttps://github.com/5-pebbles/rect-lib
repositoryhttps://github.com/5-pebbles/rect-lib
max_upload_size
id1216435
size134,811
Owen Friedman (5-pebbles)

documentation

README

rect-lib 📐

A simple library for working with anything vaguely rectangular in rust.

Features 📦

  • Rectangle trait: a trait implementing all rectangle operations; see documentation.

  • BasicRectangle: a simple implementation of the Rectangle trait.

Usage 🚀

Add the crate to your Cargo.toml:

[dependencies]
rect-lib = "0.1.1"

or use cargo add:

cargo add rect-lib

Then, you can use the Rectangle trait in your code:

use rect_lib::Rectangle;

#[derive(Clone, Copy)]
pub struct BasicRectangle {
    x: i32,
    y: i32,
    width: i32,
    height: i32,
}

impl Rectangle for BasicRectangle {
    type Unit = i32;

    fn left(&self) -> i32 {
        self.x
    }

    fn right(&self) -> i32 {
        self.x + self.width - 1
    }

    fn top(&self) -> i32 {
        self.y
    }

    fn bottom(&self) -> i32 {
        self.y - self.height + 1
    }

    fn new_from_sides(left: i32, right: i32, top: i32, bottom: i32) -> Self {
        Self {
            x: left,
            y: top,
            width: right - left + 1,
            height: top - bottom + 1,
        }
    }
}

License 📜

This project is licensed under GPL-v3.

Commit count: 43

cargo fmt