Skip to content

Commit

Permalink
Merge pull request #42 from sergeypdev/main
Browse files Browse the repository at this point in the history
Add mut variants for vector fields
  • Loading branch information
kooparse authored Feb 16, 2024
2 parents 27013ef + 232ff76 commit 01785b0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/generic_vector.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub fn GenericVector(comptime dimensions: comptime_int, comptime T: type) type {
return self.data[2];
}

pub fn zMut(self: *Self) *T {
return &self.data[2];
}

/// Shorthand for (0, 0, 1).
pub fn forward() Self {
return new(0, 0, 1);
Expand Down Expand Up @@ -112,6 +116,14 @@ pub fn GenericVector(comptime dimensions: comptime_int, comptime T: type) type {
pub fn w(self: Self) T {
return self.data[3];
}

pub fn zMut(self: *Self) *T {
return &self.data[2];
}

pub fn wMut(self: *Self) *T {
return &self.data[3];
}
},
else => unreachable,
};
Expand All @@ -124,6 +136,14 @@ pub fn GenericVector(comptime dimensions: comptime_int, comptime T: type) type {
return self.data[1];
}

pub fn xMut(self: *Self) *T {
return &self.data[0];
}

pub fn yMut(self: *Self) *T {
return &self.data[1];
}

/// Set all components to the same given value.
pub fn set(val: T) Self {
const result: Data = @splat(val);
Expand Down

0 comments on commit 01785b0

Please sign in to comment.