tiny.linear.Vec4
Defined in tiny.linear.
API (24)
Actions
Public operations.
absadddotfromArrayfromVec3: A homogeneous vector:w = 1for a point,w = 0for a direction.initlengthlengthSqlerp:aatt = 0andbatt = 1.maxminmul: Lane-wise product.negatenormalized: The unit vector alongv, or null when its length is at mostmin_lengthor is NaN.scalesplatsubtoArrayxyz
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/linear/src/vector.zig:217
zig
pub const Vec4 = extern struct { x: f32 = 0, y: f32 = 0, z: f32 = 0, w: f32 = 0, pub const zero: Vec4 = .{}; pub fn init(x: f32, y: f32, z: f32, w: f32) Vec4 { return .{ .x = x, .y = y, .z = z, .w = w }; } pub fn splat(value: f32) Vec4 { return .{ .x = value, .y = value, .z = value, .w = value }; } /// A homogeneous vector: `w = 1` for a point, `w = 0` for a direction. pub fn fromVec3(v: Vec3, w: f32) Vec4 { return .{ .x = v.x, .y = v.y, .z = v.z, .w = w }; } pub fn fromArray(lanes: [4]f32) Vec4 { return .{ .x = lanes[0], .y = lanes[1], .z = lanes[2], .w = lanes[3] }; } pub fn toArray(v: Vec4) [4]f32 { return .{ v.x, v.y, v.z, v.w }; } pub fn xyz(v: Vec4) Vec3 { return .{ .x = v.x, .y = v.y, .z = v.z }; } pub fn add(a: Vec4, b: Vec4) Vec4 { return .{ .x = a.x + b.x, .y = a.y + b.y, .z = a.z + b.z, .w = a.w + b.w }; } pub fn sub(a: Vec4, b: Vec4) Vec4 { return .{ .x = a.x - b.x, .y = a.y - b.y, .z = a.z - b.z, .w = a.w - b.w }; } /// Lane-wise product. pub fn mul(a: Vec4, b: Vec4) Vec4 { return .{ .x = a.x * b.x, .y = a.y * b.y, .z = a.z * b.z, .w = a.w * b.w }; } pub fn scale(v: Vec4, s: f32) Vec4 { return .{ .x = v.x * s, .y = v.y * s, .z = v.z * s, .w = v.w * s }; } pub fn negate(v: Vec4) Vec4 { return .{ .x = -v.x, .y = -v.y, .z = -v.z, .w = -v.w }; } pub fn dot(a: Vec4, b: Vec4) f32 { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } pub fn lengthSq(v: Vec4) f32 { return v.dot(v); } pub fn length(v: Vec4) f32 { return @sqrt(v.lengthSq()); } /// The unit vector along `v`, or null when its length is at most /// `min_length` or is NaN. pub fn normalized(v: Vec4, min_length: f32) ?Vec4 { assert(min_length >= 0); const len = v.length(); if (!(len > min_length)) return null; return v.scale(1 / len); } /// `a` at `t = 0` and `b` at `t = 1`. pub fn lerp(a: Vec4, b: Vec4, t: f32) Vec4 { return a.add(b.sub(a).scale(t)); } pub fn min(a: Vec4, b: Vec4) Vec4 { return .{ .x = @min(a.x, b.x), .y = @min(a.y, b.y), .z = @min(a.z, b.z), .w = @min(a.w, b.w) }; } pub fn max(a: Vec4, b: Vec4) Vec4 { return .{ .x = @max(a.x, b.x), .y = @max(a.y, b.y), .z = @max(a.z, b.z), .w = @max(a.w, b.w) }; } pub fn abs(v: Vec4) Vec4 { return .{ .x = @abs(v.x), .y = @abs(v.y), .z = @abs(v.z), .w = @abs(v.w) }; }};Source: lib/linear/src/root.zig:10
zig
pub const Vec4 = vector.Vec4;Complete caller list for Vec4.init
10 direct callers.
lib.linear.src.matrix.test_identity_matrices_are_the_default[function] — test source atlib/linear/src/matrix.zig:321in nearest public ownerlib.linear.src.matrixlib.linear.src.matrix.test_inverse_returns_null_for_singular_input[function] — test source atlib/linear/src/matrix.zig:350in nearest public ownerlib.linear.src.matrixlib.linear.src.matrix.test_inverse_undoes_an_invertible_matrix[function] — test source atlib/linear/src/matrix.zig:360in nearest public ownerlib.linear.src.matrixlib.linear.src.matrix.test_look-at_places_the_eye_at_the_origin_facing_down_negative_z[function] — test source atlib/linear/src/matrix.zig:376in nearest public ownerlib.linear.src.matrixlib.linear.src.matrix.test_orthographic_maps_its_box_onto_the_clip_volume[function] — test source atlib/linear/src/matrix.zig:399in nearest public ownerlib.linear.src.matrixlib.linear.src.matrix.test_perspective_maps_near_and_far_planes_to_depth_zero_and_one[function] — test source atlib/linear/src/matrix.zig:388in nearest public ownerlib.linear.src.matrixlib.linear.src.test.arithmeticDigest[function] — private source atlib/linear/src/test.zig:38in nearest public ownerlib.linear.src.testlib.linear.src.test.test_dot_rounds_(1_+_2^-12)^2_to_1_+_2^-11_before_the_sum_where_a_fused_multiply-add_keeps_2^-24[function] — test source atlib/linear/src/test.zig:24in nearest public ownerlib.linear.src.testlib.linear.src.vector.test_homogeneous_vectors_carry_their_w_lane[function] — test source atlib/linear/src/vector.zig:379in nearest public ownerlib.linear.src.vectorlib.linear.src.vector.test_lerp_reaches_both_endpoints[function] — test source atlib/linear/src/vector.zig:371in nearest public ownerlib.linear.src.vector
Audit
| Definitions | 21 |
|---|---|
| Public names | 21 |
| Members | 4 |
| Version | 26.7.0 |
| Revision | daab053ee433 |