chore: renamed the structs Vec2, Vec3, Vec4, Mat2, Mat3, Mat4, Point2, Point3 to v2, v3, v4, m2, m3, m4, p2, p3

This commit is contained in:
lisk77 2025-04-17 00:54:09 +02:00
parent 982323f671
commit fd8cf1f278
22 changed files with 430 additions and 430 deletions

View file

@ -15,7 +15,7 @@ use winit::{
window::{Icon, Window}, window::{Icon, Window},
}; };
use comet_colors::LinearRgba; use comet_colors::LinearRgba;
use comet_ecs::math::Point3; use comet_ecs::math::p3;
use comet_log::*; use comet_log::*;
use winit::dpi::{LogicalSize, PhysicalSize}; use winit::dpi::{LogicalSize, PhysicalSize};
use winit::event_loop::ControlFlow; use winit::event_loop::ControlFlow;

View file

@ -1,4 +1,4 @@
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza}; use crate::{sRgba, Color, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -106,11 +106,11 @@ impl Color for Hsla {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.hue, self.saturation, self.lightness, self.alpha) v4::new(self.hue, self.saturation, self.lightness, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -1,4 +1,4 @@
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsla, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza}; use crate::{sRgba, Color, Hsla, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -104,11 +104,11 @@ impl Color for Hsva {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.hue, self.saturation, self.value, self.alpha) v4::new(self.hue, self.saturation, self.value, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -1,4 +1,4 @@
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsla, Hsva, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza}; use crate::{sRgba, Color, Hsla, Hsva, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -167,11 +167,11 @@ impl Color for Hwba {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.hue, self.whiteness, self.blackness, self.alpha) v4::new(self.hue, self.whiteness, self.blackness, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -1,4 +1,4 @@
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza}; use crate::{sRgba, Color, Hsla, Hsva, Hwba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -148,11 +148,11 @@ impl Color for Laba {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.lightness, self.a, self.b, self.alpha) v4::new(self.lightness, self.a, self.b, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -1,4 +1,4 @@
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, LinearRgba, Oklaba, Oklcha, Xyza}; use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, LinearRgba, Oklaba, Oklcha, Xyza};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -98,11 +98,11 @@ impl Color for Lcha {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.lightness, self.chroma, self.hue, self.alpha) v4::new(self.lightness, self.chroma, self.hue, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -1,5 +1,5 @@
pub use comet_math as math; pub use comet_math as math;
use comet_math::Vec4; use comet_math::v4;
pub use linear_rgba::*; pub use linear_rgba::*;
pub use rgba::*; pub use rgba::*;
pub use hwba::*; pub use hwba::*;
@ -24,6 +24,6 @@ mod oklcha;
pub trait Color: Copy { pub trait Color: Copy {
fn to_wgpu(&self) -> wgpu::Color; fn to_wgpu(&self) -> wgpu::Color;
fn to_vec(&self) -> Vec4; fn to_vec(&self) -> v4;
fn from_vec(color: Vec4) -> Self; fn from_vec(color: v4) -> Self;
} }

View file

@ -1,5 +1,5 @@
use wgpu; use wgpu;
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, Oklaba, Oklcha, Xyza}; use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, Oklaba, Oklcha, Xyza};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -136,11 +136,11 @@ impl Color for LinearRgba {
} }
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.red, self.green, self.blue, self.alpha) v4::new(self.red, self.green, self.blue, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -1,4 +1,4 @@
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklcha, Xyza}; use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklcha, Xyza};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -118,11 +118,11 @@ impl Color for Oklaba {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.lightness, self.a, self.b, self.alpha) v4::new(self.lightness, self.a, self.b, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -1,4 +1,4 @@
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Xyza}; use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Xyza};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -97,11 +97,11 @@ impl Color for Oklcha {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.lightness, self.chroma, self.hue, self.alpha) v4::new(self.lightness, self.chroma, self.hue, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -1,4 +1,4 @@
use crate::{math::Vec4, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza}; use crate::{math::v4, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Xyza};
/// sRGB representation of color /// sRGB representation of color
/// There are two variants: `sRgba<u8>` and `sRgba<f32>` /// There are two variants: `sRgba<u8>` and `sRgba<f32>`
@ -139,8 +139,8 @@ impl sRgba<u8> {
self.to_linear().to_oklaba() self.to_linear().to_oklaba()
} }
pub fn to_vec(&self) -> Vec4 { pub fn to_vec(&self) -> v4 {
Vec4::new( v4::new(
self.red as f32, self.red as f32,
self.green as f32, self.green as f32,
self.blue as f32, self.blue as f32,
@ -334,8 +334,8 @@ impl sRgba<f32> {
self.to_hsva().to_hsla() self.to_hsva().to_hsla()
} }
pub fn to_vec(&self) -> Vec4 { pub fn to_vec(&self) -> v4 {
Vec4::new( v4::new(
self.red, self.red,
self.green, self.green,
self.blue, self.blue,
@ -349,11 +349,11 @@ impl Color for sRgba<f32> {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.red, self.green, self.blue, self.alpha) v4::new(self.red, self.green, self.blue, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }
@ -363,8 +363,8 @@ impl Color for sRgba<u8> {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new( v4::new(
self.red as f32, self.red as f32,
self.green as f32, self.green as f32,
self.blue as f32, self.blue as f32,
@ -372,7 +372,7 @@ impl Color for sRgba<u8> {
) )
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x() as u8, color.y() as u8, color.z() as u8, color.w() as u8) Self::new(color.x() as u8, color.y() as u8, color.z() as u8, color.w() as u8)
} }
} }

View file

@ -1,4 +1,4 @@
use comet_math::Vec4; use comet_math::v4;
use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha}; use crate::{sRgba, Color, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha};
#[derive(Debug, Clone, PartialEq, Copy)] #[derive(Debug, Clone, PartialEq, Copy)]
@ -114,11 +114,11 @@ impl Color for Xyza {
self.to_linear().to_wgpu() self.to_linear().to_wgpu()
} }
fn to_vec(&self) -> Vec4 { fn to_vec(&self) -> v4 {
Vec4::new(self.x, self.y, self.z, self.alpha) v4::new(self.x, self.y, self.z, self.alpha)
} }
fn from_vec(color: Vec4) -> Self { fn from_vec(color: v4) -> Self {
Self::new(color.x(), color.y(), color.z(), color.w()) Self::new(color.x(), color.y(), color.z(), color.w())
} }
} }

View file

@ -3,10 +3,10 @@
// Also just as a nomenclature: bundles are a component made up of multiple components, // Also just as a nomenclature: bundles are a component made up of multiple components,
// so it's a collection of components bundled together (like Transform2D) // so it's a collection of components bundled together (like Transform2D)
use comet_math::Mat4; use comet_math::m4;
use crate::math::{ use crate::math::{
Vec2, v2,
Vec3 v3
}; };
use comet_colors::Color as ColorTrait; use comet_colors::Color as ColorTrait;
use component_derive::Component; use component_derive::Component;
@ -18,12 +18,12 @@ use crate::{Entity, Scene};
#[derive(Component)] #[derive(Component)]
pub struct Position2D { pub struct Position2D {
position: Vec2 position: v2
} }
#[derive(Component)] #[derive(Component)]
pub struct Position3D { pub struct Position3D {
position: Vec3 position: v3
} }
#[derive(Component)] #[derive(Component)]
@ -41,20 +41,20 @@ pub struct Rotation3D {
#[derive(Component)] #[derive(Component)]
pub struct Rectangle2D{ pub struct Rectangle2D{
position: Position2D, position: Position2D,
size: Vec2 size: v2
} }
#[derive(Component)] #[derive(Component)]
pub struct Render2D { pub struct Render2D {
is_visible: bool, is_visible: bool,
texture_name: &'static str, texture_name: &'static str,
scale: Vec2 scale: v2
} }
#[derive(Component)] #[derive(Component)]
pub struct Camera2D { pub struct Camera2D {
zoom: f32, zoom: f32,
dimensions: Vec2, dimensions: v2,
priority: u8 priority: u8
} }
@ -120,7 +120,7 @@ pub trait Render {
pub trait Camera { pub trait Camera {
fn get_visible_entities(&self, camera_position: Position2D, scene: Scene) -> Vec<Entity>; fn get_visible_entities(&self, camera_position: Position2D, scene: Scene) -> Vec<Entity>;
fn get_projection_matrix(&self) -> Mat4; fn get_projection_matrix(&self) -> m4;
} }
// ################################################## // ##################################################
@ -128,13 +128,13 @@ pub trait Camera {
// ################################################## // ##################################################
impl Position2D { impl Position2D {
pub fn from_vec(vec: Vec2) -> Self { pub fn from_vec(vec: v2) -> Self {
Self { Self {
position: vec position: vec
} }
} }
pub fn as_vec(&self) -> Vec2 { pub fn as_vec(&self) -> v2 {
self.position self.position
} }
@ -156,13 +156,13 @@ impl Position2D {
} }
impl Position3D { impl Position3D {
pub fn from_vec(vec: Vec3) -> Self { pub fn from_vec(vec: v3) -> Self {
Self { Self {
position: vec position: vec
} }
} }
pub fn as_vec(&self) -> Vec3 { pub fn as_vec(&self) -> v3 {
self.position self.position
} }
@ -192,7 +192,7 @@ impl Position3D {
} }
impl Rectangle2D { impl Rectangle2D {
pub fn new(position: Position2D, size: Vec2) -> Self { pub fn new(position: Position2D, size: v2) -> Self {
Self { Self {
position, position,
size size
@ -205,7 +205,7 @@ impl Rectangle2D {
pub fn set_position(&mut self, position: Position2D) { pub fn set_position(&mut self, position: Position2D) {
self.position = position; self.position = position;
} }
pub fn size(&self) -> Vec2 { pub fn size(&self) -> v2 {
self.size self.size
} }
} }
@ -267,7 +267,7 @@ impl Transform2D {
&mut self.rotation &mut self.rotation
} }
pub fn translate(&mut self, displacement: Vec2) { pub fn translate(&mut self, displacement: v2) {
let x = self.position().x() + displacement.x(); let x = self.position().x() + displacement.x();
let y = self.position().y() + displacement.y(); let y = self.position().y() + displacement.y();
self.position_mut().set_x(x); self.position_mut().set_x(x);
@ -294,7 +294,7 @@ impl Transform3D {
} }
impl Camera2D { impl Camera2D {
pub fn new(dimensions: Vec2, zoom: f32, priority: u8) -> Self { pub fn new(dimensions: v2, zoom: f32, priority: u8) -> Self {
Self { Self {
dimensions, dimensions,
zoom, zoom,
@ -310,11 +310,11 @@ impl Camera2D {
self.zoom = zoom; self.zoom = zoom;
} }
pub fn dimensions(&self) -> Vec2 { pub fn dimensions(&self) -> v2 {
self.dimensions self.dimensions
} }
pub fn set_dimensions(&mut self, dimensions: Vec2) { pub fn set_dimensions(&mut self, dimensions: v2) {
self.dimensions = dimensions; self.dimensions = dimensions;
} }
@ -348,13 +348,13 @@ impl Camera for Camera2D {
visible_entities visible_entities
} }
fn get_projection_matrix(&self) -> Mat4 { fn get_projection_matrix(&self) -> m4 {
let left = -self.dimensions.x() / 2.0; let left = -self.dimensions.x() / 2.0;
let right = self.dimensions.x() / 2.0; let right = self.dimensions.x() / 2.0;
let bottom = -self.dimensions.y() / 2.0; let bottom = -self.dimensions.y() / 2.0;
let top = self.dimensions.y() / 2.0; let top = self.dimensions.y() / 2.0;
Mat4::OPENGL_CONV * Mat4::orthographic_projection(left, right, bottom, top, 1.0, 0.0) m4::OPENGL_CONV * m4::orthographic_projection(left, right, bottom, top, 1.0, 0.0)
} }
} }

View file

@ -1,5 +1,5 @@
use std::ops::*; use std::ops::*;
use crate::vector::{Vec2, Vec3, Vec4}; use crate::vector::{v2, v3, v4};
trait LinearTransformation { trait LinearTransformation {
fn det(&self) -> f32; fn det(&self) -> f32;
@ -11,14 +11,14 @@ trait LinearTransformation {
#[repr(C)] #[repr(C)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Mat2 { pub struct m2 {
x00: f32, x00: f32,
x01: f32, x01: f32,
x10: f32, x10: f32,
x11: f32, x11: f32,
} }
impl Mat2 { impl m2 {
pub const ZERO: Self = Self { pub const ZERO: Self = Self {
x00: 0.0, x01: 0.0, x00: 0.0, x01: 0.0,
@ -39,14 +39,14 @@ impl Mat2 {
} }
} }
pub fn from_cols(col1: Vec2, col2: Vec2) -> Self { pub fn from_cols(col1: v2, col2: v2) -> Self {
Self { Self {
x00: col1.x(), x01: col1.y(), x00: col1.x(), x01: col1.y(),
x10: col2.x(), x11: col2.y(), x10: col2.x(), x11: col2.y(),
} }
} }
pub fn from_rows(row1: Vec2, row2: Vec2) -> Self { pub fn from_rows(row1: v2, row2: v2) -> Self {
Self { Self {
x00: row1.x(), x01: row2.x(), x00: row1.x(), x01: row2.x(),
x10: row1.y(), x11: row2.y(), x10: row1.y(), x11: row2.y(),
@ -73,18 +73,18 @@ impl Mat2 {
} }
} }
pub fn col(&self, index: usize) -> Option<Vec2> { pub fn col(&self, index: usize) -> Option<v2> {
match index { match index {
0 => Some(Vec2::new(self.x00, self.x01)), 0 => Some(v2::new(self.x00, self.x01)),
1 => Some(Vec2::new(self.x10, self.x11)), 1 => Some(v2::new(self.x10, self.x11)),
_ => None _ => None
} }
} }
pub fn row(&self, index: usize) -> Option<Vec2> { pub fn row(&self, index: usize) -> Option<v2> {
match index { match index {
0 => Some(Vec2::new(self.x00, self.x10)), 0 => Some(v2::new(self.x00, self.x10)),
1 => Some(Vec2::new(self.x01, self.x11)), 1 => Some(v2::new(self.x01, self.x11)),
_ => None _ => None
} }
} }
@ -101,7 +101,7 @@ impl Mat2 {
} }
} }
impl Add for Mat2 { impl Add for m2 {
type Output = Self; type Output = Self;
fn add(self, rhs: Self) -> Self { fn add(self, rhs: Self) -> Self {
@ -114,7 +114,7 @@ impl Add for Mat2 {
} }
} }
impl Sub for Mat2 { impl Sub for m2 {
type Output = Self; type Output = Self;
fn sub(self, rhs: Self) -> Self { fn sub(self, rhs: Self) -> Self {
@ -127,7 +127,7 @@ impl Sub for Mat2 {
} }
} }
impl Mul<f32> for Mat2 { impl Mul<f32> for m2 {
type Output = Self; type Output = Self;
fn mul(self, rhs: f32) -> Self { fn mul(self, rhs: f32) -> Self {
@ -140,18 +140,18 @@ impl Mul<f32> for Mat2 {
} }
} }
impl Mul<Vec2> for Mat2 { impl Mul<v2> for m2 {
type Output = Vec2; type Output = v2;
fn mul(self, rhs: Vec2) -> Vec2 { fn mul(self, rhs: v2) -> v2 {
Vec2::new( v2::new(
self.x00 * rhs.x() + self.x01 * rhs.y(), self.x00 * rhs.x() + self.x01 * rhs.y(),
self.x10 * rhs.x() + self.x11 * rhs.y() self.x10 * rhs.x() + self.x11 * rhs.y()
) )
} }
} }
impl Mul<Mat2> for Mat2 { impl Mul<m2> for m2 {
type Output = Self; type Output = Self;
fn mul(self, rhs: Self) -> Self { fn mul(self, rhs: Self) -> Self {
@ -164,7 +164,7 @@ impl Mul<Mat2> for Mat2 {
} }
} }
impl Div<f32> for Mat2 { impl Div<f32> for m2 {
type Output = Self; type Output = Self;
fn div(self, rhs: f32) -> Self { fn div(self, rhs: f32) -> Self {
@ -177,7 +177,7 @@ impl Div<f32> for Mat2 {
} }
} }
impl Into<[[f32;2];2]> for Mat2 { impl Into<[[f32;2];2]> for m2 {
fn into(self) -> [[f32;2];2] { fn into(self) -> [[f32;2];2] {
[ [
[self.x00, self.x01], [self.x00, self.x01],
@ -192,13 +192,13 @@ impl Into<[[f32;2];2]> for Mat2 {
#[repr(C)] #[repr(C)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Mat3 { pub struct m3 {
x00: f32, x01: f32, x02: f32, x00: f32, x01: f32, x02: f32,
x10: f32, x11: f32, x12: f32, x10: f32, x11: f32, x12: f32,
x20: f32, x21: f32, x22: f32, x20: f32, x21: f32, x22: f32,
} }
impl Mat3 { impl m3 {
pub const ZERO: Self = Self { pub const ZERO: Self = Self {
x00: 0.0, x01: 0.0, x02: 0.0, x00: 0.0, x01: 0.0, x02: 0.0,
x10: 0.0, x11: 0.0, x12: 0.0, x10: 0.0, x11: 0.0, x12: 0.0,
@ -223,7 +223,7 @@ impl Mat3 {
} }
} }
pub fn from_cols(col1: Vec3, col2: Vec3, col3: Vec3) -> Self { pub fn from_cols(col1: v3, col2: v3, col3: v3) -> Self {
Self { Self {
x00: col1.x(), x01: col1.y(), x02: col1.z(), x00: col1.x(), x01: col1.y(), x02: col1.z(),
x10: col2.x(), x11: col2.y(), x12: col2.z(), x10: col2.x(), x11: col2.y(), x12: col2.z(),
@ -231,7 +231,7 @@ impl Mat3 {
} }
} }
pub fn from_rows(row1: Vec3, row2: Vec3, row3: Vec3) -> Self { pub fn from_rows(row1: v3, row2: v3, row3: v3) -> Self {
Self { Self {
x00: row1.x(), x01: row2.x(), x02: row3.x(), x00: row1.x(), x01: row2.x(), x02: row3.x(),
x10: row1.y(), x11: row2.y(), x12: row3.y(), x10: row1.y(), x11: row2.y(), x12: row3.y(),
@ -269,20 +269,20 @@ impl Mat3 {
} }
} }
pub fn col(&self, index: usize) -> Option<Vec3> { pub fn col(&self, index: usize) -> Option<v3> {
match index { match index {
0 => Some(Vec3::new(self.x00, self.x01, self.x02)), 0 => Some(v3::new(self.x00, self.x01, self.x02)),
1 => Some(Vec3::new(self.x10, self.x11, self.x12)), 1 => Some(v3::new(self.x10, self.x11, self.x12)),
2 => Some(Vec3::new(self.x20, self.x21, self.x22)), 2 => Some(v3::new(self.x20, self.x21, self.x22)),
_ => None _ => None
} }
} }
pub fn row(&self, index: usize) -> Option<Vec3> { pub fn row(&self, index: usize) -> Option<v3> {
match index { match index {
0 => Some(Vec3::new(self.x00, self.x10, self.x20)), 0 => Some(v3::new(self.x00, self.x10, self.x20)),
1 => Some(Vec3::new(self.x01, self.x11, self.x21)), 1 => Some(v3::new(self.x01, self.x11, self.x21)),
2 => Some(Vec3::new(self.x02, self.x12, self.x22)), 2 => Some(v3::new(self.x02, self.x12, self.x22)),
_ => None _ => None
} }
} }
@ -302,7 +302,7 @@ impl Mat3 {
} }
} }
impl Add for Mat3 { impl Add for m3 {
type Output = Self; type Output = Self;
fn add(self, rhs: Self) -> Self { fn add(self, rhs: Self) -> Self {
@ -314,7 +314,7 @@ impl Add for Mat3 {
} }
} }
impl Sub for Mat3 { impl Sub for m3 {
type Output = Self; type Output = Self;
fn sub(self, rhs: Self) -> Self { fn sub(self, rhs: Self) -> Self {
@ -326,7 +326,7 @@ impl Sub for Mat3 {
} }
} }
impl Mul<f32> for Mat3 { impl Mul<f32> for m3 {
type Output = Self; type Output = Self;
fn mul(self, rhs: f32) -> Self { fn mul(self, rhs: f32) -> Self {
@ -338,11 +338,11 @@ impl Mul<f32> for Mat3 {
} }
} }
impl Mul<Vec3> for Mat3 { impl Mul<v3> for m3 {
type Output = Vec3; type Output = v3;
fn mul(self, rhs: Vec3) -> Vec3 { fn mul(self, rhs: v3) -> v3 {
Vec3::new( v3::new(
self.x00 * rhs.x() + self.x01 * rhs.y() + self.x02 * rhs.z(), self.x00 * rhs.x() + self.x01 * rhs.y() + self.x02 * rhs.z(),
self.x10 * rhs.x() + self.x11 * rhs.y() + self.x12 * rhs.z(), self.x10 * rhs.x() + self.x11 * rhs.y() + self.x12 * rhs.z(),
self.x20 * rhs.x() + self.x21 * rhs.y() + self.x22 * rhs.z() self.x20 * rhs.x() + self.x21 * rhs.y() + self.x22 * rhs.z()
@ -350,7 +350,7 @@ impl Mul<Vec3> for Mat3 {
} }
} }
impl Mul<Mat3> for Mat3 { impl Mul<m3> for m3 {
type Output = Self; type Output = Self;
fn mul(self, rhs: Self) -> Self { fn mul(self, rhs: Self) -> Self {
@ -368,7 +368,7 @@ impl Mul<Mat3> for Mat3 {
} }
} }
impl Div<f32> for Mat3 { impl Div<f32> for m3 {
type Output = Self; type Output = Self;
fn div(self, rhs: f32) -> Self { fn div(self, rhs: f32) -> Self {
@ -380,7 +380,7 @@ impl Div<f32> for Mat3 {
} }
} }
impl Into<[[f32;3];3]> for Mat3 { impl Into<[[f32;3];3]> for m3 {
fn into(self) -> [[f32;3];3] { fn into(self) -> [[f32;3];3] {
[ [
[self.x00, self.x01, self.x02], [self.x00, self.x01, self.x02],
@ -396,14 +396,14 @@ impl Into<[[f32;3];3]> for Mat3 {
#[repr(C)] #[repr(C)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Mat4 { pub struct m4 {
x00: f32, x01: f32, x02: f32, x03: f32, x00: f32, x01: f32, x02: f32, x03: f32,
x10: f32, x11: f32, x12: f32, x13: f32, x10: f32, x11: f32, x12: f32, x13: f32,
x20: f32, x21: f32, x22: f32, x23: f32, x20: f32, x21: f32, x22: f32, x23: f32,
x30: f32, x31: f32, x32: f32, x33: f32, x30: f32, x31: f32, x32: f32, x33: f32,
} }
impl Mat4 { impl m4 {
pub const ZERO: Self = Self { pub const ZERO: Self = Self {
x00: 0.0, x01: 0.0, x02: 0.0, x03: 0.0, x00: 0.0, x01: 0.0, x02: 0.0, x03: 0.0,
x10: 0.0, x11: 0.0, x12: 0.0, x13: 0.0, x10: 0.0, x11: 0.0, x12: 0.0, x13: 0.0,
@ -439,7 +439,7 @@ impl Mat4 {
} }
} }
pub fn from_cols(col1: Vec4, col2: Vec4, col3: Vec4, col4: Vec4) -> Self { pub fn from_cols(col1: v4, col2: v4, col3: v4, col4: v4) -> Self {
Self { Self {
x00: col1.x(), x01: col1.y(), x02: col1.z(), x03: col1.w(), x00: col1.x(), x01: col1.y(), x02: col1.z(), x03: col1.w(),
x10: col2.x(), x11: col2.y(), x12: col2.z(), x13: col2.w(), x10: col2.x(), x11: col2.y(), x12: col2.z(), x13: col2.w(),
@ -448,7 +448,7 @@ impl Mat4 {
} }
} }
pub fn from_rows(row1: Vec4, row2: Vec4, row3: Vec4, row4: Vec4) -> Self { pub fn from_rows(row1: v4, row2: v4, row3: v4, row4: v4) -> Self {
Self { Self {
x00: row1.x(), x01: row2.x(), x02: row3.x(), x03: row4.x(), x00: row1.x(), x01: row2.x(), x02: row3.x(), x03: row4.x(),
x10: row1.y(), x11: row2.y(), x12: row3.y(), x13: row4.y(), x10: row1.y(), x11: row2.y(), x12: row3.y(), x13: row4.y(),
@ -501,22 +501,22 @@ impl Mat4 {
} }
} }
pub fn col(&self, index: usize) -> Option<Vec4> { pub fn col(&self, index: usize) -> Option<v4> {
match index { match index {
0 => Some(Vec4::new(self.x00, self.x01, self.x02, self.x03)), 0 => Some(v4::new(self.x00, self.x01, self.x02, self.x03)),
1 => Some(Vec4::new(self.x10, self.x11, self.x12, self.x13)), 1 => Some(v4::new(self.x10, self.x11, self.x12, self.x13)),
2 => Some(Vec4::new(self.x20, self.x21, self.x22, self.x23)), 2 => Some(v4::new(self.x20, self.x21, self.x22, self.x23)),
3 => Some(Vec4::new(self.x30, self.x31, self.x32, self.x33)), 3 => Some(v4::new(self.x30, self.x31, self.x32, self.x33)),
_ => None _ => None
} }
} }
pub fn row(&self, index: usize) -> Option<Vec4> { pub fn row(&self, index: usize) -> Option<v4> {
match index { match index {
0 => Some(Vec4::new(self.x00, self.x10, self.x20, self.x30)), 0 => Some(v4::new(self.x00, self.x10, self.x20, self.x30)),
1 => Some(Vec4::new(self.x01, self.x11, self.x21, self.x31)), 1 => Some(v4::new(self.x01, self.x11, self.x21, self.x31)),
2 => Some(Vec4::new(self.x02, self.x12, self.x22, self.x32)), 2 => Some(v4::new(self.x02, self.x12, self.x22, self.x32)),
3 => Some(Vec4::new(self.x03, self.x13, self.x23, self.x33)), 3 => Some(v4::new(self.x03, self.x13, self.x23, self.x33)),
_ => None _ => None
} }
} }
@ -571,7 +571,7 @@ impl Mat4 {
} }
} }
impl Add for Mat4 { impl Add for m4 {
type Output = Self; type Output = Self;
fn add(self, rhs: Self) -> Self { fn add(self, rhs: Self) -> Self {
@ -584,7 +584,7 @@ impl Add for Mat4 {
} }
} }
impl Sub for Mat4 { impl Sub for m4 {
type Output = Self; type Output = Self;
fn sub(self, rhs: Self) -> Self { fn sub(self, rhs: Self) -> Self {
@ -597,7 +597,7 @@ impl Sub for Mat4 {
} }
} }
impl Mul<f32> for Mat4 { impl Mul<f32> for m4 {
type Output = Self; type Output = Self;
fn mul(self, rhs: f32) -> Self { fn mul(self, rhs: f32) -> Self {
@ -610,11 +610,11 @@ impl Mul<f32> for Mat4 {
} }
} }
impl Mul<Vec4> for Mat4 { impl Mul<v4> for m4 {
type Output = Vec4; type Output = v4;
fn mul(self, rhs: Vec4) -> Vec4 { fn mul(self, rhs: v4) -> v4 {
Vec4::new( v4::new(
self.x00 * rhs.x() + self.x01 * rhs.y() + self.x02 * rhs.z() + self.x03 * rhs.w(), self.x00 * rhs.x() + self.x01 * rhs.y() + self.x02 * rhs.z() + self.x03 * rhs.w(),
self.x10 * rhs.x() + self.x11 * rhs.y() + self.x12 * rhs.z() + self.x13 * rhs.w(), self.x10 * rhs.x() + self.x11 * rhs.y() + self.x12 * rhs.z() + self.x13 * rhs.w(),
self.x20 * rhs.x() + self.x21 * rhs.y() + self.x22 * rhs.z() + self.x23 * rhs.w(), self.x20 * rhs.x() + self.x21 * rhs.y() + self.x22 * rhs.z() + self.x23 * rhs.w(),
@ -623,7 +623,7 @@ impl Mul<Vec4> for Mat4 {
} }
} }
impl Mul<Mat4> for Mat4 { impl Mul<m4> for m4 {
type Output = Self; type Output = Self;
fn mul(self, rhs: Self) -> Self { fn mul(self, rhs: Self) -> Self {
@ -648,7 +648,7 @@ impl Mul<Mat4> for Mat4 {
} }
} }
impl Div<f32> for Mat4 { impl Div<f32> for m4 {
type Output = Self; type Output = Self;
fn div(self, rhs: f32) -> Self { fn div(self, rhs: f32) -> Self {
@ -661,7 +661,7 @@ impl Div<f32> for Mat4 {
} }
} }
impl Into<[[f32;4];4]> for Mat4 { impl Into<[[f32;4];4]> for m4 {
fn into(self) -> [[f32;4];4] { fn into(self) -> [[f32;4];4] {
[ [
[self.x00, self.x01, self.x02, self.x03], [self.x00, self.x01, self.x02, self.x03],

View file

@ -1,7 +1,7 @@
use image::{DynamicImage, GenericImage, GenericImageView, Rgba}; use image::{DynamicImage, GenericImage, GenericImageView, Rgba};
use rand::Rng; use rand::Rng;
use comet_log::debug; use comet_log::debug;
use crate::Vec2; use crate::v2;
use crate::lerp; use crate::lerp;
// TODO // TODO

View file

@ -1,5 +1,5 @@
use crate::InnerSpace; use crate::InnerSpace;
use crate::vector::{Vec2, Vec3}; use crate::vector::{v2, v3};
pub trait Point { pub trait Point {
fn lerp(&self, other: &Self, t: f32) -> Self; fn lerp(&self, other: &Self, t: f32) -> Self;
@ -7,24 +7,17 @@ pub trait Point {
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct Point2 { pub struct p2 {
x: f32, x: f32,
y: f32 y: f32
} }
#[derive(Debug, Clone, Copy, PartialEq)] impl p2 {
pub struct Point3 {
x: f32,
y: f32,
z: f32
}
impl Point2 {
pub fn new(x: f32, y: f32) -> Self { pub fn new(x: f32, y: f32) -> Self {
Point2 { x, y } p2 { x, y }
} }
pub fn from_vec(v: Vec2) -> Self { pub fn from_vec(v: v2) -> Self {
Self { x: v.x(), y: v.y() } Self { x: v.x(), y: v.y() }
} }
@ -37,12 +30,19 @@ impl Point2 {
} }
} }
impl Point3 { #[derive(Debug, Clone, Copy, PartialEq)]
pub struct p3 {
x: f32,
y: f32,
z: f32
}
impl p3 {
pub fn new(x: f32, y: f32, z: f32) -> Self { pub fn new(x: f32, y: f32, z: f32) -> Self {
Point3 { x, y, z } p3 { x, y, z }
} }
pub fn from_vec(v: Vec3) -> Self { pub fn from_vec(v: v3) -> Self {
Self { x: v.x(), y: v.y(), z: v.z() } Self { x: v.x(), y: v.y(), z: v.z() }
} }
@ -59,18 +59,18 @@ impl Point3 {
} }
} }
impl Point for Point2 { impl Point for p2 {
fn lerp(&self, other: &Self, t: f32) -> Self { fn lerp(&self, other: &Self, t: f32) -> Self {
let x = self.x + (other.x - self.x) * t; let x = self.x + (other.x - self.x) * t;
let y = self.y + (other.y - self.y) * t; let y = self.y + (other.y - self.y) * t;
Self { x, y } Self { x, y }
} }
fn to_vec(&self) -> Vec2 { fn to_vec(&self) -> v2 {
Vec2::new(self.x, self.y) v2::new(self.x, self.y)
} }
} }
impl Point for Point3 { impl Point for p3 {
fn lerp(&self, other: &Self, t: f32) -> Self { fn lerp(&self, other: &Self, t: f32) -> Self {
let x = self.x + (other.x - self.x) * t; let x = self.x + (other.x - self.x) * t;
let y = self.y + (other.y - self.y) * t; let y = self.y + (other.y - self.y) * t;
@ -78,31 +78,31 @@ impl Point for Point3 {
Self { x, y, z } Self { x, y, z }
} }
fn to_vec(&self) -> Vec3 { fn to_vec(&self) -> v3 {
Vec3::new(self.x, self.y, self.z) v3::new(self.x, self.y, self.z)
} }
} }
impl Into<Vec2> for Point2 { impl Into<v2> for p2 {
fn into(self) -> Vec2 { fn into(self) -> v2 {
self.to_vec() self.to_vec()
} }
} }
impl Into<Vec3> for Point3 { impl Into<v3> for p3 {
fn into(self) -> Vec3 { fn into(self) -> v3 {
self.to_vec() self.to_vec()
} }
} }
impl From<Vec2> for Point2 { impl From<v2> for p2 {
fn from(v: Vec2) -> Self { fn from(v: v2) -> Self {
Self::from_vec(v) Self::from_vec(v)
} }
} }
impl From<Vec3> for Point3 { impl From<v3> for p3 {
fn from(v: Vec3) -> Self { fn from(v: v3) -> Self {
Self::from_vec(v) Self::from_vec(v)
} }
} }

View file

@ -1,26 +1,26 @@
use std::ops::*; use std::ops::*;
use std::ops::Mul; use std::ops::Mul;
use crate::vector::Vec3; use crate::vector::v3;
/// Representation of a quaternion in scalar/vector form /// Representation of a quaternion in scalar/vector form
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct Quat { pub struct Quat {
pub s: f32, pub s: f32,
pub v: Vec3, pub v: v3,
} }
impl Quat { impl Quat {
pub const fn zero() -> Self { pub const fn zero() -> Self {
Self { Self {
s: 0.0, s: 0.0,
v: Vec3 { v: v3 {
x: 0.0, x: 0.0,
y: 0.0, y: 0.0,
z: 0.0, z: 0.0,
}, },
} }
} }
pub const fn new(s: f32, v: Vec3) -> Self { pub const fn new(s: f32, v: v3) -> Self {
Self { s, v } Self { s, v }
} }
@ -36,8 +36,8 @@ impl Quat {
Self::new(self.s*inverse_squareroot, self.v*inverse_squareroot) Self::new(self.s*inverse_squareroot, self.v*inverse_squareroot)
} }
pub fn into_vec(&self) -> Vec3 { pub fn into_vec(&self) -> v3 {
Vec3 { v3 {
x: self.v.x, x: self.v.x,
y: self.v.y, y: self.v.y,
z: self.v.z, z: self.v.z,
@ -117,7 +117,7 @@ impl Mul<Quat> for Quat {
fn mul(self, other: Quat) -> Quat { fn mul(self, other: Quat) -> Quat {
Quat { Quat {
s: self.s*other.s - self.v.x*other.v.x - self.v.y*other.v.y - self.v.z*other.v.z, s: self.s*other.s - self.v.x*other.v.x - self.v.y*other.v.y - self.v.z*other.v.z,
v: Vec3 { v: v3 {
x: self.s*other.v.x + self.v.x*other.s + self.v.y*other.v.z - self.v.z*other.v.y, x: self.s*other.v.x + self.v.x*other.s + self.v.y*other.v.z - self.v.z*other.v.y,
y: self.s*other.v.y + self.v.y*other.s + self.v.z*other.v.x - self.v.x*other.v.z, y: self.s*other.v.y + self.v.y*other.s + self.v.z*other.v.x - self.v.x*other.v.z,
z: self.s*other.v.z + self.v.z*other.s + self.v.x*other.v.y - self.v.y*other.v.x, z: self.s*other.v.z + self.v.z*other.s + self.v.x*other.v.y - self.v.y*other.v.x,

View file

@ -1,4 +1,4 @@
use crate::point::{Point2, Point3}; use crate::point::{p2, p3};
use crate::quaternion::Quat; use crate::quaternion::Quat;
use std::ops::*; use std::ops::*;
@ -31,21 +31,21 @@ pub trait InnerSpace:
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Vec2 { pub struct v2 {
x: f32, x: f32,
y: f32, y: f32,
} }
impl Vec2 { impl v2 {
pub const X: Vec2 = Vec2 { x: 1.0, y: 0.0 }; pub const X: v2 = v2 { x: 1.0, y: 0.0 };
pub const Y: Vec2 = Vec2 { x: 0.0, y: 1.0 }; pub const Y: v2 = v2 { x: 0.0, y: 1.0 };
pub const ZERO: Vec2 = Vec2 { x: 0.0, y: 0.0 }; pub const ZERO: v2 = v2 { x: 0.0, y: 0.0 };
pub const fn new(x: f32, y: f32) -> Self { pub const fn new(x: f32, y: f32) -> Self {
Vec2 { x, y } v2 { x, y }
} }
pub fn from_point(p: Point2) -> Self { pub fn from_point(p: p2) -> Self {
Self { x: p.x(), y: p.y() } Self { x: p.x(), y: p.y() }
} }
@ -66,43 +66,43 @@ impl Vec2 {
} }
} }
impl Add<Vec2> for Vec2 { impl Add<v2> for v2 {
type Output = Vec2; type Output = v2;
fn add(self, other: Vec2) -> Vec2 { fn add(self, other: v2) -> v2 {
Vec2 { v2 {
x: self.x + other.x, x: self.x + other.x,
y: self.y + other.y, y: self.y + other.y,
} }
} }
} }
impl AddAssign for Vec2 { impl AddAssign for v2 {
fn add_assign(&mut self, other: Vec2) { fn add_assign(&mut self, other: v2) {
self.x += other.x; self.x += other.x;
self.y += other.y; self.y += other.y;
} }
} }
impl Sub<Vec2> for Vec2 { impl Sub<v2> for v2 {
type Output = Vec2; type Output = v2;
fn sub(self, other: Vec2) -> Vec2 { fn sub(self, other: v2) -> v2 {
Vec2 { v2 {
x: self.x - other.x, x: self.x - other.x,
y: self.y - other.y, y: self.y - other.y,
} }
} }
} }
impl SubAssign for Vec2 { impl SubAssign for v2 {
fn sub_assign(&mut self, other: Vec2) { fn sub_assign(&mut self, other: v2) {
self.x -= other.x; self.x -= other.x;
self.y -= other.y; self.y -= other.y;
} }
} }
impl Neg for Vec2 { impl Neg for v2 {
type Output = Self; type Output = Self;
fn neg(self) -> Self::Output { fn neg(self) -> Self::Output {
@ -113,48 +113,48 @@ impl Neg for Vec2 {
} }
} }
impl Mul<f32> for Vec2 { impl Mul<f32> for v2 {
type Output = Vec2; type Output = v2;
fn mul(self, other: f32) -> Vec2 { fn mul(self, other: f32) -> v2 {
Vec2 { v2 {
x: self.x * other, x: self.x * other,
y: self.y * other, y: self.y * other,
} }
} }
} }
impl Mul<Vec2> for f32 { impl Mul<v2> for f32 {
type Output = Vec2; type Output = v2;
fn mul(self, other: Vec2) -> Vec2 { fn mul(self, other: v2) -> v2 {
Vec2 { v2 {
x: self * other.x, x: self * other.x,
y: self * other.y, y: self * other.y,
} }
} }
} }
impl Div<f32> for Vec2 { impl Div<f32> for v2 {
type Output = Vec2; type Output = v2;
fn div(self, other: f32) -> Vec2 { fn div(self, other: f32) -> v2 {
Vec2 { v2 {
x: self.x / other, x: self.x / other,
y: self.y / other, y: self.y / other,
} }
} }
} }
impl Into<[f32;2]> for Vec2 { impl Into<[f32;2]> for v2 {
fn into(self) -> [f32;2] { fn into(self) -> [f32;2] {
[self.x, self.y] [self.x, self.y]
} }
} }
impl Into<Vec2> for [f32;2] { impl Into<v2> for [f32;2] {
fn into(self) -> Vec2 { fn into(self) -> v2 {
Vec2 { v2 {
x: self[0], x: self[0],
y: self[1], y: self[1],
} }
@ -165,26 +165,26 @@ impl Into<Vec2> for [f32;2] {
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct IVec2 { pub struct v2i {
x: i64, x: i64,
y: i64, y: i64,
} }
impl IVec2 { impl v2i {
pub const X: IVec2 = IVec2 { x: 1, y: 0 }; pub const X: v2i = v2i { x: 1, y: 0 };
pub const Y: IVec2 = IVec2 { x: 0, y: 1 }; pub const Y: v2i = v2i { x: 0, y: 1 };
pub const ZERO: IVec2 = IVec2 { x: 0, y: 0 }; pub const ZERO: v2i = v2i { x: 0, y: 0 };
pub const fn new(x: i64, y: i64) -> Self { pub const fn new(x: i64, y: i64) -> Self {
IVec2 { x, y } v2i { x, y }
} }
pub fn from_point(p: Point2) -> Self { pub fn from_point(p: p2) -> Self {
Self { x: p.x() as i64, y: p.y() as i64 } Self { x: p.x() as i64, y: p.y() as i64 }
} }
pub fn as_vec2(&self) -> Vec2 { pub fn as_vec2(&self) -> v2 {
Vec2 { v2 {
x: self.x as f32, x: self.x as f32,
y: self.y as f32, y: self.y as f32,
} }
@ -212,7 +212,7 @@ impl IVec2 {
pub fn normalize(&self) -> Self { pub fn normalize(&self) -> Self {
let factor = 1.0 / self.length() as f32; let factor = 1.0 / self.length() as f32;
IVec2 { v2i {
x: (factor * self.x as f32) as i64, x: (factor * self.x as f32) as i64,
y: (factor * self.y as f32) as i64, y: (factor * self.y as f32) as i64,
} }
@ -247,122 +247,122 @@ impl IVec2 {
} }
} }
impl Add<IVec2> for IVec2 { impl Add<v2i> for v2i {
type Output = IVec2; type Output = v2i;
fn add(self, other: IVec2) -> IVec2 { fn add(self, other: v2i) -> v2i {
IVec2 { v2i {
x: self.x + other.x, x: self.x + other.x,
y: self.y + other.y, y: self.y + other.y,
} }
} }
} }
impl Add<IVec2> for Vec2 { impl Add<v2i> for v2 {
type Output = Vec2; type Output = v2;
fn add(self, other: IVec2) -> Vec2 { fn add(self, other: v2i) -> v2 {
Vec2 { v2 {
x: self.x + other.x as f32, x: self.x + other.x as f32,
y: self.y + other.y as f32, y: self.y + other.y as f32,
} }
} }
} }
impl Add<Vec2> for IVec2 { impl Add<v2> for v2i {
type Output = Vec2; type Output = v2;
fn add(self, other: Vec2) -> Vec2 { fn add(self, other: v2) -> v2 {
Vec2 { v2 {
x: self.x as f32 + other.x, x: self.x as f32 + other.x,
y: self.y as f32 + other.y, y: self.y as f32 + other.y,
} }
} }
} }
impl AddAssign for IVec2 { impl AddAssign for v2i {
fn add_assign(&mut self, other: IVec2) { fn add_assign(&mut self, other: v2i) {
self.x += other.x; self.x += other.x;
self.y += other.y; self.y += other.y;
} }
} }
impl Sub<IVec2> for IVec2 { impl Sub<v2i> for v2i {
type Output = IVec2; type Output = v2i;
fn sub(self, other: IVec2) -> IVec2 { fn sub(self, other: v2i) -> v2i {
IVec2 { v2i {
x: self.x - other.x, x: self.x - other.x,
y: self.y - other.y, y: self.y - other.y,
} }
} }
} }
impl Sub<IVec2> for Vec2 { impl Sub<v2i> for v2 {
type Output = Vec2; type Output = v2;
fn sub(self, other: IVec2) -> Vec2 { fn sub(self, other: v2i) -> v2 {
Vec2 { v2 {
x: self.x - other.x as f32, x: self.x - other.x as f32,
y: self.y - other.y as f32, y: self.y - other.y as f32,
} }
} }
} }
impl Sub<Vec2> for IVec2 { impl Sub<v2> for v2i {
type Output = Vec2; type Output = v2;
fn sub(self, other: Vec2) -> Vec2 { fn sub(self, other: v2) -> v2 {
Vec2 { v2 {
x: self.x as f32 - other.x, x: self.x as f32 - other.x,
y: self.y as f32 - other.y, y: self.y as f32 - other.y,
} }
} }
} }
impl SubAssign for IVec2 { impl SubAssign for v2i {
fn sub_assign(&mut self, other: IVec2) { fn sub_assign(&mut self, other: v2i) {
self.x -= other.x; self.x -= other.x;
self.y -= other.y; self.y -= other.y;
} }
} }
impl Mul<f32> for IVec2 { impl Mul<f32> for v2i {
type Output = IVec2; type Output = v2i;
fn mul(self, other: f32) -> IVec2 { fn mul(self, other: f32) -> v2i {
IVec2 { v2i {
x: self.x * other as i64, x: self.x * other as i64,
y: self.y * other as i64, y: self.y * other as i64,
} }
} }
} }
impl From<IVec2> for Vec2 { impl From<v2i> for v2 {
fn from(v: IVec2) -> Vec2 { fn from(v: v2i) -> v2 {
Vec2 { v2 {
x: v.x as f32, x: v.x as f32,
y: v.y as f32, y: v.y as f32,
} }
} }
} }
impl From<Vec2> for IVec2 { impl From<v2> for v2i {
fn from(v: Vec2) -> IVec2 { fn from(v: v2) -> v2i {
IVec2 { v2i {
x: v.x as i64, x: v.x as i64,
y: v.y as i64, y: v.y as i64,
} }
} }
} }
impl Into<[i64;2]> for IVec2 { impl Into<[i64;2]> for v2i {
fn into(self) -> [i64;2] { fn into(self) -> [i64;2] {
[self.x, self.y] [self.x, self.y]
} }
} }
impl Into<[f32;2]> for IVec2 { impl Into<[f32;2]> for v2i {
fn into(self) -> [f32;2] { fn into(self) -> [f32;2] {
[self.x as f32, self.y as f32] [self.x as f32, self.y as f32]
} }
@ -376,23 +376,23 @@ impl Into<[f32;2]> for IVec2 {
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Vec3 { pub struct v3 {
pub x: f32, pub x: f32,
pub y: f32, pub y: f32,
pub z: f32, pub z: f32,
} }
impl Vec3 { impl v3 {
pub const X: Vec3 = Vec3 { x: 1.0, y: 0.0, z: 0.0 }; pub const X: v3 = v3 { x: 1.0, y: 0.0, z: 0.0 };
pub const Y: Vec3 = Vec3 { x: 0.0, y: 1.0, z: 0.0 }; pub const Y: v3 = v3 { x: 0.0, y: 1.0, z: 0.0 };
pub const Z: Vec3 = Vec3 { x: 0.0, y: 0.0, z: 1.0 }; pub const Z: v3 = v3 { x: 0.0, y: 0.0, z: 1.0 };
pub const ZERO: Vec3 = Vec3 { x: 0.0, y: 0.0, z: 0.0 }; pub const ZERO: v3 = v3 { x: 0.0, y: 0.0, z: 0.0 };
pub const fn new(x: f32, y: f32, z: f32) -> Self { pub const fn new(x: f32, y: f32, z: f32) -> Self {
Vec3 { x, y, z } v3 { x, y, z }
} }
pub fn from_point(p: Point3) -> Self { pub fn from_point(p: p3) -> Self {
Self { Self {
x: p.x(), x: p.x(),
y: p.y(), y: p.y(),
@ -425,11 +425,11 @@ impl Vec3 {
} }
} }
impl Add<Vec3> for Vec3 { impl Add<v3> for v3 {
type Output = Vec3; type Output = v3;
fn add(self, other: Vec3) -> Vec3 { fn add(self, other: v3) -> v3 {
Vec3 { v3 {
x: self.x + other.x, x: self.x + other.x,
y: self.y + other.y, y: self.y + other.y,
z: self.z + other.z, z: self.z + other.z,
@ -437,19 +437,19 @@ impl Add<Vec3> for Vec3 {
} }
} }
impl AddAssign for Vec3 { impl AddAssign for v3 {
fn add_assign(&mut self, other: Vec3) { fn add_assign(&mut self, other: v3) {
self.x += other.x; self.x += other.x;
self.y += other.y; self.y += other.y;
self.z += other.z; self.z += other.z;
} }
} }
impl Sub<Vec3> for Vec3 { impl Sub<v3> for v3 {
type Output = Vec3; type Output = v3;
fn sub(self, other: Vec3) -> Vec3 { fn sub(self, other: v3) -> v3 {
Vec3 { v3 {
x: self.x - other.x, x: self.x - other.x,
y: self.y - other.y, y: self.y - other.y,
z: self.z - other.z, z: self.z - other.z,
@ -457,19 +457,19 @@ impl Sub<Vec3> for Vec3 {
} }
} }
impl SubAssign for Vec3 { impl SubAssign for v3 {
fn sub_assign(&mut self, other: Vec3) { fn sub_assign(&mut self, other: v3) {
self.x -= other.x; self.x -= other.x;
self.y -= other.y; self.y -= other.y;
self.z -= other.z; self.z -= other.z;
} }
} }
impl Neg for Vec3 { impl Neg for v3 {
type Output = Vec3; type Output = v3;
fn neg(self) -> Vec3 { fn neg(self) -> v3 {
Vec3 { v3 {
x: -self.x, x: -self.x,
y: -self.y, y: -self.y,
z: -self.z, z: -self.z,
@ -477,11 +477,11 @@ impl Neg for Vec3 {
} }
} }
impl Mul<f32> for Vec3 { impl Mul<f32> for v3 {
type Output = Vec3; type Output = v3;
fn mul(self, other: f32) -> Vec3 { fn mul(self, other: f32) -> v3 {
Vec3 { v3 {
x: self.x * other, x: self.x * other,
y: self.y * other, y: self.y * other,
z: self.z * other, z: self.z * other,
@ -489,11 +489,11 @@ impl Mul<f32> for Vec3 {
} }
} }
impl Mul<Vec3> for f32 { impl Mul<v3> for f32 {
type Output = Vec3; type Output = v3;
fn mul(self, other: Vec3) -> Vec3 { fn mul(self, other: v3) -> v3 {
Vec3 { v3 {
x: self * other.x, x: self * other.x,
y: self * other.y, y: self * other.y,
z: self * other.z, z: self * other.z,
@ -501,11 +501,11 @@ impl Mul<Vec3> for f32 {
} }
} }
impl Div<f32> for Vec3 { impl Div<f32> for v3 {
type Output = Vec3; type Output = v3;
fn div(self, other: f32) -> Vec3 { fn div(self, other: f32) -> v3 {
Vec3 { v3 {
x: self.x / other, x: self.x / other,
y: self.y / other, y: self.y / other,
z: self.z / other, z: self.z / other,
@ -513,21 +513,21 @@ impl Div<f32> for Vec3 {
} }
} }
impl Into<Quat> for Vec3 { impl Into<Quat> for v3 {
fn into(self) -> Quat { fn into(self) -> Quat {
Quat::new(0.0, self) Quat::new(0.0, self)
} }
} }
impl Into<[f32;3]> for Vec3 { impl Into<[f32;3]> for v3 {
fn into(self) -> [f32;3] { fn into(self) -> [f32;3] {
[self.x, self.y, self.z] [self.x, self.y, self.z]
} }
} }
impl Into<Vec3> for [f32;3] { impl Into<v3> for [f32;3] {
fn into(self) -> Vec3 { fn into(self) -> v3 {
Vec3 { v3 {
x: self[0], x: self[0],
y: self[1], y: self[1],
z: self[2], z: self[2],
@ -539,23 +539,23 @@ impl Into<Vec3> for [f32;3] {
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct IVec3 { pub struct v3i {
pub x: i64, pub x: i64,
pub y: i64, pub y: i64,
pub z: i64, pub z: i64,
} }
impl IVec3 { impl v3i {
pub const X: IVec3 = IVec3 { x: 1, y: 0, z: 0 }; pub const X: v3i = v3i { x: 1, y: 0, z: 0 };
pub const Y: IVec3 = IVec3 { x: 0, y: 1, z: 0 }; pub const Y: v3i = v3i { x: 0, y: 1, z: 0 };
pub const Z: IVec3 = IVec3 { x: 0, y: 0, z: 1 }; pub const Z: v3i = v3i { x: 0, y: 0, z: 1 };
pub const ZERO: IVec3 = IVec3 { x: 0, y: 0, z: 0 }; pub const ZERO: v3i = v3i { x: 0, y: 0, z: 0 };
pub const fn new(x: i64, y: i64, z: i64) -> Self { pub const fn new(x: i64, y: i64, z: i64) -> Self {
IVec3 { x, y, z } v3i { x, y, z }
} }
pub fn from_point(p: Point3) -> Self { pub fn from_point(p: p3) -> Self {
Self { Self {
x: p.x() as i64, x: p.x() as i64,
y: p.y() as i64, y: p.y() as i64,
@ -593,7 +593,7 @@ impl IVec3 {
pub fn normalize(&self) -> Self { pub fn normalize(&self) -> Self {
let factor = 1 / self.length(); let factor = 1 / self.length();
IVec3 { v3i {
x: factor * self.x, x: factor * self.x,
y: factor * self.y, y: factor * self.y,
z: factor * self.z, z: factor * self.z,
@ -601,11 +601,11 @@ impl IVec3 {
} }
} }
impl Add<IVec3> for IVec3 { impl Add<v3i> for v3i {
type Output = IVec3; type Output = v3i;
fn add(self, other: IVec3) -> IVec3 { fn add(self, other: v3i) -> v3i {
IVec3 { v3i {
x: self.x + other.x, x: self.x + other.x,
y: self.y + other.y, y: self.y + other.y,
z: self.z + other.z, z: self.z + other.z,
@ -613,11 +613,11 @@ impl Add<IVec3> for IVec3 {
} }
} }
impl Add<IVec3> for Vec3 { impl Add<v3i> for v3 {
type Output = Vec3; type Output = v3;
fn add(self, other: IVec3) -> Vec3 { fn add(self, other: v3i) -> v3 {
Vec3 { v3 {
x: self.x + other.x as f32, x: self.x + other.x as f32,
y: self.y + other.y as f32, y: self.y + other.y as f32,
z: self.z + other.z as f32, z: self.z + other.z as f32,
@ -625,11 +625,11 @@ impl Add<IVec3> for Vec3 {
} }
} }
impl Add<Vec3> for IVec3 { impl Add<v3> for v3i {
type Output = Vec3; type Output = v3;
fn add(self, other: Vec3) -> Vec3 { fn add(self, other: v3) -> v3 {
Vec3 { v3 {
x: self.x as f32 + other.x, x: self.x as f32 + other.x,
y: self.y as f32 + other.y, y: self.y as f32 + other.y,
z: self.z as f32 + other.z, z: self.z as f32 + other.z,
@ -637,19 +637,19 @@ impl Add<Vec3> for IVec3 {
} }
} }
impl AddAssign for IVec3 { impl AddAssign for v3i {
fn add_assign(&mut self, other: IVec3) { fn add_assign(&mut self, other: v3i) {
self.x += other.x; self.x += other.x;
self.y += other.y; self.y += other.y;
self.z += other.z; self.z += other.z;
} }
} }
impl Sub<IVec3> for IVec3 { impl Sub<v3i> for v3i {
type Output = IVec3; type Output = v3i;
fn sub(self, other: IVec3) -> IVec3 { fn sub(self, other: v3i) -> v3i {
IVec3 { v3i {
x: self.x - other.x, x: self.x - other.x,
y: self.y - other.y, y: self.y - other.y,
z: self.z - other.z, z: self.z - other.z,
@ -657,11 +657,11 @@ impl Sub<IVec3> for IVec3 {
} }
} }
impl Sub<IVec3> for Vec3 { impl Sub<v3i> for v3 {
type Output = Vec3; type Output = v3;
fn sub(self, other: IVec3) -> Vec3 { fn sub(self, other: v3i) -> v3 {
Vec3 { v3 {
x: self.x - other.x as f32, x: self.x - other.x as f32,
y: self.y - other.y as f32, y: self.y - other.y as f32,
z: self.z - other.z as f32, z: self.z - other.z as f32,
@ -669,11 +669,11 @@ impl Sub<IVec3> for Vec3 {
} }
} }
impl Sub<Vec3> for IVec3 { impl Sub<v3> for v3i {
type Output = Vec3; type Output = v3;
fn sub(self, other: Vec3) -> Vec3 { fn sub(self, other: v3) -> v3 {
Vec3 { v3 {
x: self.x as f32 - other.x, x: self.x as f32 - other.x,
y: self.y as f32 - other.y, y: self.y as f32 - other.y,
z: self.z as f32 - other.z, z: self.z as f32 - other.z,
@ -681,18 +681,18 @@ impl Sub<Vec3> for IVec3 {
} }
} }
impl SubAssign for IVec3 { impl SubAssign for v3i {
fn sub_assign(&mut self, other: IVec3) { fn sub_assign(&mut self, other: v3i) {
self.x -= other.x; self.x -= other.x;
self.y -= other.y; self.y -= other.y;
} }
} }
impl Mul<f32> for IVec3 { impl Mul<f32> for v3i {
type Output = IVec3; type Output = v3i;
fn mul(self, other: f32) -> IVec3 { fn mul(self, other: f32) -> v3i {
IVec3 { v3i {
x: self.x * other as i64, x: self.x * other as i64,
y: self.y * other as i64, y: self.y * other as i64,
z: self.z * other as i64, z: self.z * other as i64,
@ -700,9 +700,9 @@ impl Mul<f32> for IVec3 {
} }
} }
impl From<IVec3> for Vec3 { impl From<v3i> for v3 {
fn from(v: IVec3) -> Vec3 { fn from(v: v3i) -> v3 {
Vec3 { v3 {
x: v.x as f32, x: v.x as f32,
y: v.y as f32, y: v.y as f32,
z: v.z as f32, z: v.z as f32,
@ -710,9 +710,9 @@ impl From<IVec3> for Vec3 {
} }
} }
impl From<Vec3> for IVec3 { impl From<v3> for v3i {
fn from(v: Vec3) -> IVec3 { fn from(v: v3) -> v3i {
IVec3 { v3i {
x: v.x as i64, x: v.x as i64,
y: v.y as i64, y: v.y as i64,
z: v.z as i64, z: v.z as i64,
@ -728,23 +728,23 @@ impl From<Vec3> for IVec3 {
#[repr(C)] #[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default)] #[derive(Debug, Clone, Copy, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Vec4 { pub struct v4 {
x: f32, x: f32,
y: f32, y: f32,
z: f32, z: f32,
w: f32, w: f32,
} }
impl Vec4 { impl v4 {
pub const X: Vec4 = Vec4 { x: 1.0, y: 0.0, z: 0.0, w: 0.0 }; pub const X: v4 = v4 { x: 1.0, y: 0.0, z: 0.0, w: 0.0 };
pub const Y: Vec4 = Vec4 { x: 0.0, y: 1.0, z: 0.0, w: 0.0 }; pub const Y: v4 = v4 { x: 0.0, y: 1.0, z: 0.0, w: 0.0 };
pub const Z: Vec4 = Vec4 { x: 0.0, y: 0.0, z: 1.0, w: 0.0 }; pub const Z: v4 = v4 { x: 0.0, y: 0.0, z: 1.0, w: 0.0 };
pub const W: Vec4 = Vec4 { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }; pub const W: v4 = v4 { x: 0.0, y: 0.0, z: 0.0, w: 1.0 };
pub const ZERO: Vec4 = Vec4 { x: 0.0, y: 0.0, z: 0.0, w: 0.0 }; pub const ZERO: v4 = v4 { x: 0.0, y: 0.0, z: 0.0, w: 0.0 };
pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self { pub const fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
Vec4 { x, y, z, w } v4 { x, y, z, w }
} }
pub fn x(&self) -> f32 { pub fn x(&self) -> f32 {
@ -780,11 +780,11 @@ impl Vec4 {
} }
} }
impl Add<Vec4> for Vec4 { impl Add<v4> for v4 {
type Output = Vec4; type Output = v4;
fn add(self, other: Vec4) -> Vec4 { fn add(self, other: v4) -> v4 {
Vec4 { v4 {
x: self.x + other.x, x: self.x + other.x,
y: self.y + other.y, y: self.y + other.y,
z: self.z + other.z, z: self.z + other.z,
@ -793,8 +793,8 @@ impl Add<Vec4> for Vec4 {
} }
} }
impl AddAssign for Vec4 { impl AddAssign for v4 {
fn add_assign(&mut self, other: Vec4) { fn add_assign(&mut self, other: v4) {
self.x += other.x; self.x += other.x;
self.y += other.y; self.y += other.y;
self.z += other.z; self.z += other.z;
@ -802,11 +802,11 @@ impl AddAssign for Vec4 {
} }
} }
impl Sub<Vec4> for Vec4 { impl Sub<v4> for v4 {
type Output = Vec4; type Output = v4;
fn sub(self, other: Vec4) -> Vec4 { fn sub(self, other: v4) -> v4 {
Vec4 { v4 {
x: self.x - other.x, x: self.x - other.x,
y: self.y - other.y, y: self.y - other.y,
z: self.z - other.z, z: self.z - other.z,
@ -815,8 +815,8 @@ impl Sub<Vec4> for Vec4 {
} }
} }
impl SubAssign for Vec4 { impl SubAssign for v4 {
fn sub_assign(&mut self, other: Vec4) { fn sub_assign(&mut self, other: v4) {
self.x -= other.x; self.x -= other.x;
self.y -= other.y; self.y -= other.y;
self.z -= other.z; self.z -= other.z;
@ -824,7 +824,7 @@ impl SubAssign for Vec4 {
} }
} }
impl Neg for Vec4 { impl Neg for v4 {
type Output = Self; type Output = Self;
fn neg(self) -> Self::Output { fn neg(self) -> Self::Output {
@ -837,11 +837,11 @@ impl Neg for Vec4 {
} }
} }
impl Mul<f32> for Vec4 { impl Mul<f32> for v4 {
type Output = Vec4; type Output = v4;
fn mul(self, other: f32) -> Vec4 { fn mul(self, other: f32) -> v4 {
Vec4 { v4 {
x: self.x * other, x: self.x * other,
y: self.y * other, y: self.y * other,
z: self.z * other, z: self.z * other,
@ -850,11 +850,11 @@ impl Mul<f32> for Vec4 {
} }
} }
impl Mul<Vec4> for f32 { impl Mul<v4> for f32 {
type Output = Vec4; type Output = v4;
fn mul(self, other: Vec4) -> Vec4 { fn mul(self, other: v4) -> v4 {
Vec4 { v4 {
x: self * other.x, x: self * other.x,
y: self * other.y, y: self * other.y,
z: self * other.z, z: self * other.z,
@ -863,7 +863,7 @@ impl Mul<Vec4> for f32 {
} }
} }
impl MulAssign<f32> for Vec4 { impl MulAssign<f32> for v4 {
fn mul_assign(&mut self, other: f32) { fn mul_assign(&mut self, other: f32) {
self.x *= other; self.x *= other;
self.y *= other; self.y *= other;
@ -872,11 +872,11 @@ impl MulAssign<f32> for Vec4 {
} }
} }
impl Div<f32> for Vec4 { impl Div<f32> for v4 {
type Output = Vec4; type Output = v4;
fn div(self, other: f32) -> Vec4 { fn div(self, other: f32) -> v4 {
Vec4 { v4 {
x: self.x / other, x: self.x / other,
y: self.y / other, y: self.y / other,
z: self.z / other, z: self.z / other,
@ -885,19 +885,19 @@ impl Div<f32> for Vec4 {
} }
} }
impl Into<[f32;4]> for Vec4 { impl Into<[f32;4]> for v4 {
fn into(self) -> [f32;4] { fn into(self) -> [f32;4] {
[self.x, self.y, self.z, self.w] [self.x, self.y, self.z, self.w]
} }
} }
impl InnerSpace for Vec2 { impl InnerSpace for v2 {
fn dot(&self, other: &Self) -> f32 { fn dot(&self, other: &Self) -> f32 {
self.x * other.x + self.y * other.y self.x * other.x + self.y * other.y
} }
fn dist(&self, other: &Self) -> f32 { fn dist(&self, other: &Self) -> f32 {
Vec2 { v2 {
x: other.x - self.x, x: other.x - self.x,
y: other.y - self.y, y: other.y - self.y,
} }
@ -914,7 +914,7 @@ impl InnerSpace for Vec2 {
fn normalize(&self) -> Self { fn normalize(&self) -> Self {
let factor = 1.0 / self.length(); let factor = 1.0 / self.length();
Vec2 { v2 {
x: factor * self.x, x: factor * self.x,
y: factor * self.y, y: factor * self.y,
} }
@ -940,13 +940,13 @@ impl InnerSpace for Vec2 {
} }
} }
impl InnerSpace for Vec3 { impl InnerSpace for v3 {
fn dot(&self, other: &Self) -> f32 { fn dot(&self, other: &Self) -> f32 {
self.x * other.x + self.y * other.y + self.z * other.z self.x * other.x + self.y * other.y + self.z * other.z
} }
fn dist(&self, other: &Self) -> f32 { fn dist(&self, other: &Self) -> f32 {
Vec3 { v3 {
x: other.x - self.x, x: other.x - self.x,
y: other.y - self.y, y: other.y - self.y,
z: other.z - self.z, z: other.z - self.z,
@ -964,7 +964,7 @@ impl InnerSpace for Vec3 {
fn normalize(&self) -> Self { fn normalize(&self) -> Self {
let factor = 1.0 / self.length(); let factor = 1.0 / self.length();
Vec3 { v3 {
x: factor * self.x, x: factor * self.x,
y: factor * self.y, y: factor * self.y,
z: factor * self.z, z: factor * self.z,
@ -992,13 +992,13 @@ impl InnerSpace for Vec3 {
} }
} }
impl InnerSpace for Vec4 { impl InnerSpace for v4 {
fn dot(&self, other: &Self) -> f32 { fn dot(&self, other: &Self) -> f32 {
self.x * other.x + self.y * other.y + self.z * other.z + self.w * other.w self.x * other.x + self.y * other.y + self.z * other.z + self.w * other.w
} }
fn dist(&self, other: &Self) -> f32 { fn dist(&self, other: &Self) -> f32 {
Vec4 { v4 {
x: other.x - self.x, x: other.x - self.x,
y: other.y - self.y, y: other.y - self.y,
z: other.z - self.z, z: other.z - self.z,
@ -1017,7 +1017,7 @@ impl InnerSpace for Vec4 {
fn normalize(&self) -> Self { fn normalize(&self) -> Self {
let factor = 1.0 / self.length(); let factor = 1.0 / self.length();
Vec4 { v4 {
x: factor * self.x, x: factor * self.x,
y: factor * self.y, y: factor * self.y,
z: factor * self.z, z: factor * self.z,
@ -1095,12 +1095,12 @@ macro_rules! generate_swizzles4 {
}; };
} }
generate_swizzles2!(Vec2, generate_swizzles2!(v2,
xx => (x, x), xy => (x, y), xx => (x, x), xy => (x, y),
yx => (y, x), yy => (y, y) yx => (y, x), yy => (y, y)
); );
generate_swizzles3!(Vec3, generate_swizzles3!(v3,
xxx => (x, x, x), xxy => (x, x, y), xxz => (x, x, z), xxx => (x, x, x), xxy => (x, x, y), xxz => (x, x, z),
xyx => (x, y, x), xyy => (x, y, y), xyz => (x, y, z), xyx => (x, y, x), xyy => (x, y, y), xyz => (x, y, z),
xzx => (x, z, x), xzy => (x, z, y), xzz => (x, z, z), xzx => (x, z, x), xzy => (x, z, y), xzz => (x, z, z),
@ -1112,7 +1112,7 @@ generate_swizzles3!(Vec3,
zzx => (z, z, x), zzy => (z, z, y), zzz => (z, z, z) zzx => (z, z, x), zzy => (z, z, y), zzz => (z, z, z)
); );
generate_swizzles4!(Vec4, generate_swizzles4!(v4,
xxxx => (x, x, x, x), xxxy => (x, x, x, y), xxxz => (x, x, x, z), xxxw => (x, x, x, w), xxxx => (x, x, x, x), xxxy => (x, x, x, y), xxxz => (x, x, x, z), xxxw => (x, x, x, w),
xxyx => (x, x, y, x), xxyy => (x, x, y, y), xxyz => (x, x, y, z), xxyw => (x, x, y, w), xxyx => (x, x, y, x), xxyy => (x, x, y, y), xxyz => (x, x, y, z), xxyw => (x, x, y, w),
xxzx => (x, x, z, x), xxzy => (x, x, z, y), xxzz => (x, x, z, z), xxzw => (x, x, z, w), xxzx => (x, x, z, x), xxzy => (x, x, z, y), xxzz => (x, x, z, z), xxzw => (x, x, z, w),

View file

@ -1,4 +1,4 @@
use comet_math::{Mat4, Point3, Vec2, Vec3}; use comet_math::{m4, p3, v2, v3};
#[rustfmt::skip] #[rustfmt::skip]
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new( pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
@ -12,15 +12,15 @@ const SAFE_FRAC_PI_2: f32 = std::f32::consts::FRAC_PI_2 - 0.0001;
pub struct RenderCamera { pub struct RenderCamera {
zoom: f32, zoom: f32,
dimension: Vec2, dimension: v2,
position: Vec3 position: v3
} }
impl RenderCamera { impl RenderCamera {
pub fn new( pub fn new(
zoom: f32, zoom: f32,
dimension: Vec2, dimension: v2,
position: Vec3 position: v3
) -> Self { ) -> Self {
Self { Self {
zoom, zoom,
@ -29,16 +29,16 @@ impl RenderCamera {
} }
} }
pub fn build_view_projection_matrix(&self) -> Mat4 { pub fn build_view_projection_matrix(&self) -> m4 {
let zoomed_width = self.dimension.x() / self.zoom; let zoomed_width = self.dimension.x() / self.zoom;
let zoomed_height = self.dimension.y() / self.zoom; let zoomed_height = self.dimension.y() / self.zoom;
Mat4::OPENGL_CONV * Mat4::orthographic_projection(self.position.x() - zoomed_width / 2.0, m4::OPENGL_CONV * m4::orthographic_projection(self.position.x() - zoomed_width / 2.0,
self.position.x() + zoomed_width / 2.0, self.position.x() + zoomed_width / 2.0,
self.position.y() - zoomed_height / 2.0, self.position.y() - zoomed_height / 2.0,
self.position.y() + zoomed_height / 2.0, self.position.y() + zoomed_height / 2.0,
1.0, 1.0,
0.0) 0.0)
/*OPENGL_TO_WGPU_MATRIX * cgmath::ortho(self.position.x() - zoomed_width / 2.0, /*OPENGL_TO_WGPU_MATRIX * cgmath::ortho(self.position.x() - zoomed_width / 2.0,
self.position.x() + zoomed_width / 2.0, self.position.x() + zoomed_width / 2.0,

View file

@ -12,7 +12,7 @@ use winit::window::Window;
use comet_colors::{ Color, LinearRgba }; use comet_colors::{ Color, LinearRgba };
use comet_ecs::{Camera, Camera2D, Component, Position2D, Render, Render2D, Transform2D, Scene}; use comet_ecs::{Camera, Camera2D, Component, Position2D, Render, Render2D, Transform2D, Scene};
use comet_log::{debug, error, info}; use comet_log::{debug, error, info};
use comet_math::{Point2, Point3, Vec2, Vec3}; use comet_math::{p2, p3, v2, v3};
use comet_resources::{texture, graphic_resource_manager::GraphicResourceManager, Texture, Vertex}; use comet_resources::{texture, graphic_resource_manager::GraphicResourceManager, Texture, Vertex};
use comet_resources::texture_atlas::TextureRegion; use comet_resources::texture_atlas::TextureRegion;
use comet_structs::ComponentSet; use comet_structs::ComponentSet;
@ -127,7 +127,7 @@ impl<'a> Renderer2D<'a> {
label: Some("texture_bind_group_layout"), label: Some("texture_bind_group_layout"),
}); });
let camera = RenderCamera::new(1.0, Vec2::new(2.0, 2.0), Vec3::new(0.0, 0.0, 0.0)); let camera = RenderCamera::new(1.0, v2::new(2.0, 2.0), v3::new(0.0, 0.0, 0.0));
let mut camera_uniform = CameraUniform::new(); let mut camera_uniform = CameraUniform::new();
camera_uniform.update_view_proj(&camera); camera_uniform.update_view_proj(&camera);
@ -471,7 +471,7 @@ impl<'a> Renderer2D<'a> {
} }
/// A function to just draw a textured quad at a given position. /// A function to just draw a textured quad at a given position.
pub fn draw_texture_at(&mut self, texture_path: String, position: Point3) { pub fn draw_texture_at(&mut self, texture_path: String, position: p3) {
let region = self.graphic_resource_manager.texture_locations().get(&texture_path).unwrap(); let region = self.graphic_resource_manager.texture_locations().get(&texture_path).unwrap();
let (dim_x, dim_y) = region.dimensions(); let (dim_x, dim_y) = region.dimensions();
@ -496,13 +496,13 @@ impl<'a> Renderer2D<'a> {
} }
/// A function to draw text at a given position. /// A function to draw text at a given position.
pub fn draw_text_at(&mut self, text: &str, font: String, size: f32, position: Point2, color: impl Color) { pub fn draw_text_at(&mut self, text: &str, font: String, size: f32, position: p2, color: impl Color) {
//self.set_font_atlas(font.clone()); //self.set_font_atlas(font.clone());
let wgpu_color = color.to_wgpu(); let wgpu_color = color.to_wgpu();
let vert_color = [wgpu_color.r as f32, wgpu_color.g as f32, wgpu_color.b as f32, wgpu_color.a as f32]; let vert_color = [wgpu_color.r as f32, wgpu_color.g as f32, wgpu_color.b as f32, wgpu_color.a as f32];
let screen_position = Point2::new(position.x()/self.config.width as f32, position.y()/self.config.height as f32); let screen_position = p2::new(position.x()/self.config.width as f32, position.y()/self.config.height as f32);
let scale_factor = size / self.graphic_resource_manager.fonts().iter().find(|f| f.name() == font).unwrap().size(); let scale_factor = size / self.graphic_resource_manager.fonts().iter().find(|f| f.name() == font).unwrap().size();
let line_height = (self.graphic_resource_manager.fonts().iter().find(|f| f.name() == font).unwrap().line_height() / self.config.height as f32) * scale_factor; let line_height = (self.graphic_resource_manager.fonts().iter().find(|f| f.name() == font).unwrap().line_height() / self.config.height as f32) * scale_factor;
@ -550,10 +550,10 @@ impl<'a> Renderer2D<'a> {
} }
} }
fn add_text_to_buffers(&self, text: String, font: String, size: f32, position: Point2, color: wgpu::Color) -> (Vec<Vertex>, Vec<u16>) { fn add_text_to_buffers(&self, text: String, font: String, size: f32, position: p2, color: wgpu::Color) -> (Vec<Vertex>, Vec<u16>) {
let vert_color = [color.r as f32, color.g as f32, color.b as f32, color.a as f32]; let vert_color = [color.r as f32, color.g as f32, color.b as f32, color.a as f32];
let screen_position = Point2::new(position.x()/self.config.width as f32, position.y()/self.config.height as f32); let screen_position = p2::new(position.x()/self.config.width as f32, position.y()/self.config.height as f32);
let scale_factor = size / self.graphic_resource_manager.fonts().iter().find(|f| f.name() == font).unwrap().size(); let scale_factor = size / self.graphic_resource_manager.fonts().iter().find(|f| f.name() == font).unwrap().size();
let line_height = (self.graphic_resource_manager.fonts().iter().find(|f| f.name() == font).unwrap().line_height() / self.config.height as f32) * scale_factor; let line_height = (self.graphic_resource_manager.fonts().iter().find(|f| f.name() == font).unwrap().line_height() / self.config.height as f32) * scale_factor;
@ -632,9 +632,9 @@ impl<'a> Renderer2D<'a> {
let camera = RenderCamera::new( let camera = RenderCamera::new(
camera_component.zoom(), camera_component.zoom(),
camera_component.dimensions(), camera_component.dimensions(),
Vec3::new(camera_position.as_vec().x(), v3::new(camera_position.as_vec().x(),
camera_position.as_vec().y(), camera_position.as_vec().y(),
0.0)); 0.0));
let mut camera_uniform = CameraUniform::new(); let mut camera_uniform = CameraUniform::new();
camera_uniform.update_view_proj(&camera); camera_uniform.update_view_proj(&camera);

View file

@ -8,7 +8,7 @@ fn setup(app: &mut App, renderer: &mut Renderer2D) {
let camera = app.new_entity(); let camera = app.new_entity();
app.add_component(camera, Transform2D::new()); app.add_component(camera, Transform2D::new());
app.add_component(camera, Camera2D::new(Vec2::new(2.0, 2.0), 1.0, 1)); app.add_component(camera, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
let e1 = app.new_entity(); let e1 = app.new_entity();
@ -42,23 +42,23 @@ fn handle_input(app: &mut App, dt: f32) {
} }
fn update_position(input: WinitInputHelper, transform: &mut Transform2D, dt: f32) { fn update_position(input: WinitInputHelper, transform: &mut Transform2D, dt: f32) {
let mut direction = Vec2::ZERO; let mut direction = v2::ZERO;
if input.key_held(Key::KeyW) { if input.key_held(Key::KeyW) {
direction += Vec2::Y; direction += v2::Y;
} }
if input.key_held(Key::KeyA) { if input.key_held(Key::KeyA) {
direction -= Vec2::X; direction -= v2::X;
} }
if input.key_held(Key::KeyS) { if input.key_held(Key::KeyS) {
direction -= Vec2::Y; direction -= v2::Y;
} }
if input.key_held(Key::KeyD) { if input.key_held(Key::KeyD) {
direction += Vec2::X; direction += v2::X;
} }
// If check to prevent division by zero and the comet to fly off into infinity... // If check to prevent division by zero and the comet to fly off into infinity...
if direction != Vec2::ZERO { if direction != v2::ZERO {
let normalized_dir = direction.normalize(); let normalized_dir = direction.normalize();
let displacement = normalized_dir * 777.7 * dt; let displacement = normalized_dir * 777.7 * dt;
transform.translate(displacement); transform.translate(displacement);

View file

@ -2,12 +2,12 @@ use comet::prelude::*;
fn setup(app: &mut App, renderer: &mut Renderer2D) { fn setup(app: &mut App, renderer: &mut Renderer2D) {
// Creating a texture atlas from the provided textures in the vector // Creating a texture atlas from the provided textures in the vector
renderer.set_texture_atlas(vec!["./resources/textures/comet_icon.png".to_string()]); renderer.set_texture_atlas_by_paths(vec!["./resources/textures/comet_icon.png".to_string()]);
// Creating a camera entity // Creating a camera entity
let cam = app.new_entity(); let cam = app.new_entity();
app.add_component(cam, Transform2D::new()); app.add_component(cam, Transform2D::new());
app.add_component(cam, Camera2D::new(Vec2::new(2.0, 2.0), 1.0, 1)); app.add_component(cam, Camera2D::new(v2::new(2.0, 2.0), 1.0, 1));
// Creating a textured entity // Creating a textured entity
let e0 = app.new_entity(); let e0 = app.new_entity();