Improve coords documentation

This commit is contained in:
Joscha 2023-02-17 15:04:56 +01:00
parent b2d87543d7
commit fae12a4b9f

View file

@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign, Neg, Sub, SubAssign}; use std::ops::{Add, AddAssign, Neg, Sub, SubAssign};
/// Size in screen cells.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Size { pub struct Size {
pub width: u16, pub width: u16,
@ -13,6 +14,7 @@ impl Size {
Self { width, height } Self { width, height }
} }
/// Add two [`Size`]s using [`u16::saturating_add`].
pub const fn saturating_add(self, rhs: Self) -> Self { pub const fn saturating_add(self, rhs: Self) -> Self {
Self::new( Self::new(
self.width.saturating_add(rhs.width), self.width.saturating_add(rhs.width),
@ -20,6 +22,7 @@ impl Size {
) )
} }
/// Subtract two [`Size`]s using [`u16::saturating_sub`].
pub const fn saturating_sub(self, rhs: Self) -> Self { pub const fn saturating_sub(self, rhs: Self) -> Self {
Self::new( Self::new(
self.width.saturating_sub(rhs.width), self.width.saturating_sub(rhs.width),
@ -58,6 +61,9 @@ impl SubAssign for Size {
} }
} }
/// Position in screen cell coordinates.
///
/// The x axis points to the right. The y axis points down.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Pos { pub struct Pos {
pub x: i32, pub x: i32,