diff options
| author | Arne Dußin | 2020-12-21 01:22:15 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-12-21 21:15:55 +0100 |
| commit | d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4 (patch) | |
| tree | e5633f4d3b18472922c943d759e9f58722ba4405 /src/math/vec2.rs | |
| parent | 48f321a80970ebeb8374072b1d2e0a4d297aa348 (diff) | |
| download | graf_karto-d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4.tar.gz graf_karto-d7e9c3cc46d616c2fcd1a6e9f73adbb79c6570b4.zip | |
Add previously missing docs where appropriate
Diffstat (limited to 'src/math/vec2.rs')
| -rw-r--r-- | src/math/vec2.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/math/vec2.rs b/src/math/vec2.rs index b9e3215..b5706a0 100644 --- a/src/math/vec2.rs +++ b/src/math/vec2.rs @@ -1,5 +1,8 @@ +//! Two-dimensional vectors and useful operations on them. + use crate::math::Rect; use alga::general::{ClosedAdd, ClosedSub}; +use nalgebra::Point2; use nalgebra::{RealField, Scalar}; use num_traits::{NumCast, One, ToPrimitive}; use serde::{Deserialize, Serialize}; @@ -7,8 +10,9 @@ use std::cmp::Ordering; use std::convert::{From, Into}; use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; use std::{fmt, mem}; -use nalgebra::Point2; +/// Describes a vector, which may be a point or a directed length, depending on the interpretation. +#[allow(missing_docs)] #[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)] pub struct Vec2<T: Scalar + Copy> { pub x: T, @@ -16,10 +20,12 @@ pub struct Vec2<T: Scalar + Copy> { } impl<T: Scalar + Copy> Vec2<T> { + /// Create a new vector from its internal values. pub fn new(x: T, y: T) -> Self { Self { x, y } } + /// Finds the euclidian length and returns it. pub fn length(&self) -> T where T: RealField, @@ -27,6 +33,9 @@ impl<T: Scalar + Copy> Vec2<T> { (self.x * self.x + self.y * self.y).sqrt() } + /// Consumes the vector and returns a vector that is rotated by Pi/2 in clockwise direction. + /// This is a special case of rotation and the function is faster than using the nonspecific + /// rotation function. pub fn rotated_90_clockwise(mut self) -> Vec2<T> where T: One + Neg<Output = T> + MulAssign, @@ -36,6 +45,9 @@ impl<T: Scalar + Copy> Vec2<T> { self } + /// Consumes the vector and returns a vector that is rotated by Pi/2 in counterclockwise direction. + /// This is a special case of rotation and the function is faster than using the nonspecific + /// rotation function. pub fn rotated_90_counterclockwise(mut self) -> Vec2<T> where T: One + Neg<Output = T> + MulAssign, |
