From c6ee60de02aa0ef30f24b23b5c8995f0ab6aab78 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 15 Mar 2024 17:19:55 +0900 Subject: [PATCH] Refactor: Define `type`s used by Vertex --- src/math3d.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/math3d.rs b/src/math3d.rs index 3f19a57..54927fe 100644 --- a/src/math3d.rs +++ b/src/math3d.rs @@ -1,10 +1,13 @@ use crate::ffi; +type Vec2f = [f32; 2]; +type Vec3f = [f32; 3]; + #[repr(C)] #[derive(Copy, Clone, PartialEq, Debug)] pub struct Vertex { - pub pos: [f32; 2], - pub color: [f32; 3], + pub pos: Vec2f, + pub color: Vec3f, } impl Default for Vertex { @@ -18,7 +21,7 @@ impl Default for Vertex { #[allow(dead_code)] impl Vertex { - pub fn new(pos: [f32; 2], color: [f32; 3]) -> Self { + pub fn new(pos: Vec2f, color: Vec3f) -> Self { Self { pos, color } } @@ -27,8 +30,8 @@ impl Vertex { } pub const fn color_offset() -> usize { - let mut offset = std::mem::size_of::<[f32; 2]>(); - let alignment = std::mem::align_of::<[f32; 3]>(); + let mut offset = std::mem::size_of::(); + let alignment = std::mem::align_of::(); while offset % alignment != 0 { offset += 1; }