glium_types/vectors/
divec2.rsuse derive_cmp_ops::CmpOps;
use glium::uniforms::AsUniformValue;
use super::{divec3::{divec3, DIVec3}, vec2::Vec2, ivec2::IVec2};
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, CmpOps)]
pub struct DIVec2{
pub x: i64,
pub y: i64,
}
impl DIVec2{
pub const ZERO: Self = divec2(0, 0);
pub const ONE: Self = divec2(1, 1);
pub const X: Self = divec2(1, 0);
pub const Y: Self = divec2(0, 1);
pub fn new(x: i64, y: i64) -> Self{
Self { x, y }
}
pub fn extend(self, z: i64) -> DIVec3{
divec3(self.x, self.y, z)
}
pub fn truncate(self) -> i64 {
self.x
}
pub fn splat(value: i64) -> Self{
Self::new(value, value)
}
pub fn length_squared(self) -> i64 {
self.x*self.x + self.y*self.y
}
pub fn distance_squared(self, other: DIVec2) -> i64 {
(self - other).length_squared()
}
pub fn dot(self, other: DIVec2) -> i64 {
self.x * other.x + self.y * other.y
}
pub fn scale(self, scalar: i64) -> DIVec2 {
Self::new(self.x * scalar, self.y * scalar)
}
}
impl AsUniformValue for DIVec2{
fn as_uniform_value(&self) -> glium::uniforms::UniformValue<'_> {
glium::uniforms::UniformValue::Int64Vec2([self.x, self.y])
}
}
pub const fn divec2(x: i64, y: i64) -> DIVec2{
DIVec2 { x, y }
}
impl From<Vec2> for DIVec2 {
fn from (value: Vec2) -> Self {
divec2(value.x as i64, value.y as i64)
}
}
impl From<IVec2> for DIVec2 {
fn from (value: IVec2) -> Self {
divec2(value.x as i64, value.y as i64)
}
}
impl From<[i64; 2]> for DIVec2 {
fn from(value: [i64; 2]) -> Self {
divec2(value[0], value[1])
}
}
impl From<(i64, i64)> for DIVec2 {
fn from(value: (i64, i64)) -> Self {
divec2(value.0, value.1)
}
}