record Vec2

record Vec2(x: double, y: double)

← Index

Vec2 — a 2D vector

An immutable point/vector in the plane. Supports vector addition and scaling, plus the Euclidean length. Because Vec2 is a record, it also gets structural equals, hashCode, and copy for free.

val v = Vec2::of(3.0, 4.0)
v.length()          // 5.0
(v + v).length()    // 10.0

Methods

static def of(x: double, y: double): Vec2

Convenience factory.

def plus(o: Vec2): Vec2

Vector sum. Backs the + operator.

def scale(k: double): Vec2

Scales both components by k.

def dot(o: Vec2): double

The dot product with o.

def length(): double

The Euclidean length sqrt(x^2 + y^2).

Fields

x: double

Vec2 — a 2D vector

An immutable point/vector in the plane. Supports vector addition and scaling, plus the Euclidean length. Because Vec2 is a record, it also gets structural equals, hashCode, and copy for free.

val v = Vec2::of(3.0, 4.0)
v.length()          // 5.0
(v + v).length()    // 10.0
y: double

Vec2 — a 2D vector

An immutable point/vector in the plane. Supports vector addition and scaling, plus the Euclidean length. Because Vec2 is a record, it also gets structural equals, hashCode, and copy for free.

val v = Vec2::of(3.0, 4.0)
v.length()          // 5.0
(v + v).length()    // 10.0