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

Add mut variants for vector fields #42

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
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
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
Loading