Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to master #218

Merged
merged 46 commits into from
Dec 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9b6fe7f
Improve buf doc comments and correctness
jdahlstrom Aug 10, 2024
2ceea2e
Add SDL2 frontend
jdahlstrom Jun 13, 2024
51a6c04
Improve frontend error handling
jdahlstrom Jul 21, 2024
6917fe1
Add dedicated error type to sdl2
jdahlstrom Jul 31, 2024
8b08363
Change crates demo to use sdl2
jdahlstrom Oct 9, 2024
4614b99
Add clear method to Frame
jdahlstrom Oct 9, 2024
c7cb7de
Fixup sdl2 feature for crates
jdahlstrom Dec 4, 2024
0b2f0e1
Move Debug impl for Real to correct module
jdahlstrom Dec 3, 2024
338360d
Tweak vector implementation details
jdahlstrom Dec 3, 2024
ef15a62
Add Point type
jdahlstrom Dec 3, 2024
017a57c
Impl Debug, Add, Sub, ApproxEq for Point
jdahlstrom Dec 4, 2024
b2eaf3d
Add alias, methods to Point
jdahlstrom Dec 4, 2024
2d9a345
Add Vertex2, Vertex3 type aliases
jdahlstrom Dec 4, 2024
d8c01f9
Add point-to-vec and vec-to-point conversion methods
jdahlstrom Dec 4, 2024
e4b0e2d
Index Buf with points rather than vecs
jdahlstrom Dec 4, 2024
fe8b9c0
Move lerping to its own trait Lerp
jdahlstrom Dec 7, 2024
4a089de
Add support for Bezier curves of affine types
jdahlstrom Dec 7, 2024
7f6fb60
Add preliminary matrix-point transform method
jdahlstrom Dec 4, 2024
f8bdf2f
Migrate to using points as vertex coordinates
jdahlstrom Dec 4, 2024
4b10f58
Add trait ZDiv for optional perspective correction
jdahlstrom Dec 5, 2024
557f876
Improve assert message
jdahlstrom Dec 7, 2024
0187910
Change pnm header to use Dims
jdahlstrom Dec 7, 2024
668f729
Remove lerp from Vary
jdahlstrom Dec 8, 2024
e62ad14
Use points as screen space positions
jdahlstrom Dec 4, 2024
728e77a
Use points as orthographic and viewport bounds
jdahlstrom Dec 4, 2024
a6626d5
Refactor clipping somewhat
jdahlstrom Dec 7, 2024
2930cb2
Add random distributions of points
jdahlstrom Dec 8, 2024
6a037a6
Remove RNG type parameter from Distrib for now
jdahlstrom Dec 8, 2024
3ae1785
Improve rand comments and doctests
jdahlstrom Dec 8, 2024
7ee0b1b
Add re-exports to render.rs root
jdahlstrom Dec 16, 2024
6094832
Impl Error trait unconditionally now that it's in core
jdahlstrom Dec 18, 2024
c0e0060
Rename read_from to read_obj for consistency
jdahlstrom Dec 18, 2024
36feadc
Improve obj comments and tests
jdahlstrom Dec 18, 2024
0a95bda
Add parse_pnm for consistency with OBJ loading
jdahlstrom Dec 18, 2024
1c7e9b3
Add P2 (text graymap) read support
jdahlstrom May 14, 2024
bff13e3
Fix edge case in read_pnm, improve pnm test coverage
jdahlstrom Jun 17, 2024
9bff5e4
Revamp math.rs re-exports
jdahlstrom Dec 19, 2024
4834d2b
Factor solids.rs to submodules
jdahlstrom Dec 16, 2024
b9fd2b0
Take IntoIterator rather than Vec in Lathe::new
jdahlstrom Dec 17, 2024
4ae5ecc
Add shortcut alias for run-demo
jdahlstrom Dec 20, 2024
d4a6356
Add segments parameter to Cylinder, Cone, and Capsule
jdahlstrom Dec 17, 2024
3d5f9b3
Add some missing operators and doc comments to Point
jdahlstrom Dec 22, 2024
4f8b65c
Change Distrib::samples to borrow the RNG
jdahlstrom Dec 22, 2024
e536a36
Add BezierSpline constructor from rays (point, dir pairs)
jdahlstrom Dec 8, 2024
718c4e1
Fix bug in github action
jdahlstrom Dec 23, 2024
3a31ab7
Fix embarrassing bug in Matrix::from_basis(), add tests
jdahlstrom Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tweak vector implementation details
jdahlstrom committed Dec 7, 2024
commit 338360d0727afb2c1c1c81026dc1436576a575f5
32 changes: 16 additions & 16 deletions core/src/math/vec.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
use core::array;
use core::fmt::{Debug, Formatter};
use core::iter::Sum;
use core::marker::PhantomData;
use core::marker::PhantomData as Pd;
use core::ops::{Add, Div, Index, IndexMut, Mul, Neg, Sub};
use core::ops::{AddAssign, DivAssign, MulAssign, SubAssign};

@@ -30,11 +30,11 @@ use crate::math::space::{Affine, Linear, Proj4, Real};
/// # Examples
/// TODO
#[repr(transparent)]
pub struct Vector<Repr, Space = ()>(pub Repr, PhantomData<Space>);
pub struct Vector<Repr, Space = ()>(pub Repr, Pd<Space>);

/// A 2-vector with `f32` components.
pub type Vec2<Basis = ()> = Vector<[f32; 2], Real<2, Basis>>;
/// A 2-vector with `f32` components.
/// A 3-vector with `f32` components.
pub type Vec3<Basis = ()> = Vector<[f32; 3], Real<3, Basis>>;
/// A `f32` 4-vector in the projective 3-space over ℝ, aka P<sub>3</sub>(ℝ).
pub type ProjVec4 = Vector<[f32; 4], Proj4>;
@@ -54,12 +54,12 @@ pub type Vec2u<Basis = ()> = Vector<[u32; 2], Real<2, Basis>>;

/// Returns a real 2-vector with components `x` and `y`.
pub const fn vec2<Sc, B>(x: Sc, y: Sc) -> Vector<[Sc; 2], Real<2, B>> {
Vector([x, y], PhantomData)
Vector([x, y], Pd)
}

/// Returns a real 3-vector with components `x`, `y`, and `z`.
pub const fn vec3<Sc, B>(x: Sc, y: Sc, z: Sc) -> Vector<[Sc; 3], Real<3, B>> {
Vector([x, y, z], PhantomData)
Vector([x, y, z], Pd)
}

/// Returns a vector with all components equal to a scalar.
@@ -74,7 +74,7 @@ pub const fn vec3<Sc, B>(x: Sc, y: Sc, z: Sc) -> Vector<[Sc; 3], Real<3, B>> {
/// assert_eq!(v, vec3(1.23, 1.23, 1.23));
#[inline]
pub fn splat<Sp, Sc: Clone, const DIM: usize>(s: Sc) -> Vector<[Sc; DIM], Sp> {
s.into()
array::from_fn(|_| s.clone()).into()
}

//
@@ -85,7 +85,7 @@ impl<R, Sp> Vector<R, Sp> {
/// Returns a new vector with representation `repr`.
#[inline]
pub const fn new(repr: R) -> Self {
Self(repr, PhantomData)
Self(repr, Pd)
}

/// Returns a vector with value equal to `self` but in space `S`.
@@ -337,11 +337,11 @@ where
#[inline]
fn add(&self, other: &Self::Diff) -> Self {
// TODO Profile performance of array::from_fn
array::from_fn(|i| self.0[i].add(&other.0[i])).into()
Self(array::from_fn(|i| self.0[i].add(&other.0[i])), Pd)
}
#[inline]
fn sub(&self, other: &Self) -> Self::Diff {
array::from_fn(|i| self.0[i].sub(&other.0[i])).into()
Vector(array::from_fn(|i| self.0[i].sub(&other.0[i])), Pd)
}
}

@@ -359,11 +359,11 @@ where
}
#[inline]
fn neg(&self) -> Self {
array::from_fn(|i| self.0[i].neg()).into()
Self(array::from_fn(|i| self.0[i].neg()), Pd)
}
#[inline]
fn mul(&self, scalar: Self::Scalar) -> Self {
array::from_fn(|i| self.0[i].mul(scalar)).into()
Self(array::from_fn(|i| self.0[i].mul(scalar)), Pd)
}
}

@@ -389,13 +389,13 @@ impl<R: Copy, S> Copy for Vector<R, S> {}

impl<R: Clone, S> Clone for Vector<R, S> {
fn clone(&self) -> Self {
Self(self.0.clone(), PhantomData)
Self(self.0.clone(), Pd)
}
}

impl<R: Default, S> Default for Vector<R, S> {
fn default() -> Self {
Self(R::default(), PhantomData)
Self(R::default(), Pd)
}
}

@@ -416,8 +416,8 @@ impl<R: Debug, Sp: Debug + Default> Debug for Vector<R, Sp> {

impl<R, Sp> From<R> for Vector<R, Sp> {
#[inline]
fn from(els: R) -> Self {
Self(els, PhantomData)
fn from(repr: R) -> Self {
Self(repr, Pd)
}
}

@@ -427,7 +427,7 @@ impl<Sp, Sc: Clone, const DIM: usize> From<Sc> for Vector<[Sc; DIM], Sp> {
/// This operation is also called "splat" or "broadcast".
#[inline]
fn from(scalar: Sc) -> Self {
array::from_fn(|_| scalar.clone()).into()
splat(scalar)
}
}