tiny.linear.Vec2
Defined in tiny.linear.
API (22)
Actions
Public operations.
absadddistancedistanceSqdotfromArrayinitlengthlengthSqlerp:aatt = 0andbatt = 1.maxminmul: Lane-wise product.negatenormalized: The unit vector alongv, or null when its length is at mostmin_lengthor is NaN.scalesplatsubtoArray
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/linear/src/vector.zig:12
zig
pub const Vec2 = extern struct { x: f32 = 0, y: f32 = 0, pub const zero: Vec2 = .{}; pub fn init(x: f32, y: f32) Vec2 { return .{ .x = x, .y = y }; } pub fn splat(value: f32) Vec2 { return .{ .x = value, .y = value }; } pub fn fromArray(lanes: [2]f32) Vec2 { return .{ .x = lanes[0], .y = lanes[1] }; } pub fn toArray(v: Vec2) [2]f32 { return .{ v.x, v.y }; } pub fn add(a: Vec2, b: Vec2) Vec2 { return .{ .x = a.x + b.x, .y = a.y + b.y }; } pub fn sub(a: Vec2, b: Vec2) Vec2 { return .{ .x = a.x - b.x, .y = a.y - b.y }; } /// Lane-wise product. pub fn mul(a: Vec2, b: Vec2) Vec2 { return .{ .x = a.x * b.x, .y = a.y * b.y }; } pub fn scale(v: Vec2, s: f32) Vec2 { return .{ .x = v.x * s, .y = v.y * s }; } pub fn negate(v: Vec2) Vec2 { return .{ .x = -v.x, .y = -v.y }; } pub fn dot(a: Vec2, b: Vec2) f32 { return a.x * b.x + a.y * b.y; } pub fn lengthSq(v: Vec2) f32 { return v.dot(v); } pub fn length(v: Vec2) f32 { return @sqrt(v.lengthSq()); } pub fn distanceSq(a: Vec2, b: Vec2) f32 { return a.sub(b).lengthSq(); } pub fn distance(a: Vec2, b: Vec2) f32 { return @sqrt(a.distanceSq(b)); } /// The unit vector along `v`, or null when its length is at most /// `min_length` or is NaN. pub fn normalized(v: Vec2, min_length: f32) ?Vec2 { 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: Vec2, b: Vec2, t: f32) Vec2 { return a.add(b.sub(a).scale(t)); } pub fn min(a: Vec2, b: Vec2) Vec2 { return .{ .x = @min(a.x, b.x), .y = @min(a.y, b.y) }; } pub fn max(a: Vec2, b: Vec2) Vec2 { return .{ .x = @max(a.x, b.x), .y = @max(a.y, b.y) }; } pub fn abs(v: Vec2) Vec2 { return .{ .x = @abs(v.x), .y = @abs(v.y) }; }};Source: lib/linear/src/root.zig:8
zig
pub const Vec2 = vector.Vec2;Audit
| Definitions | 21 |
|---|---|
| Public names | 21 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |