Skip to documentation
SLOP

tiny.linear.Vec2

Reference tiny.linear Vec2

Defined in tiny.linear.

API (22)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

No direct callersNo direct callstiny.linearVec2
Static calls · unresolved targets: unknown · external targets: unknown.

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;
Called byCallsNo direct callstest sourcelib.linear.src.vectortest: normalized returns null at or b...Vec2init
Static calls · unresolved targets: 0 · external targets: 0.

Audit

Definitions21
Public names21
Members2
Version26.7.0
Revisiondaab053ee433