Vector Scalar Operations

Example

import slash.vector.*

val v1 = Vec[2](1.5, 2.5)
// v1: Vec[2] = Array(1.5, 2.5)
v1 + 2.0
// res0: Vec[2] = Array(3.5, 4.5)
v1 - 2.0
// res1: Vec[2] = Array(-0.5, 0.5)
v1 * 2.0
// res2: Vec[2] = Array(3.0, 5.0)
v1 / 2.0
// res3: Vec[2] = Array(0.75, 1.25)

v1.unary_-
// res4: Vec[2] = Array(-1.5, -2.5)

// mutating (no copy) methods
val v2A = Vec[2](1.5, 2.5); v2A += 2.5; v2A
// v2A: Vec[2] = Array(4.0, 5.0); v2A += 2.5; v2A; v2A
// res6: Vec[2] = Array(4.0, 5.0)
val v2B = Vec[2](1.5, 2.5); v2B -= 2.5; v2B
// v2B: Vec[2] = Array(-1.0, 0.0); v2B -= 2.5; v2B; v2B
// res8: Vec[2] = Array(-1.0, 0.0)
val v2C = Vec[2](1.5, 2.5); v2C *= 2.5; v2C
// v2C: Vec[2] = Array(3.75, 6.25); v2C *= 2.5; v2C; v2C
// res10: Vec[2] = Array(3.75, 6.25)
val v2D = Vec[2](1.5, 2.5); v2D /= 2.5; v2D 
// v2D: Vec[2] = Array(0.6000000000000001, 1.0); v2D /= 2.5; v2D ; v2D 
// res12: Vec[2] = Array(0.6000000000000001, 1.0) 

v1.clampedMin(2.0)
// res13: Vec[2] = Array(2.0, 2.5)
v1.clampedMAX(2.0)
// res14: Vec[2] = Array(1.5, 2.0)

val v2 = Vec[3](1.5, 2.5, 3.5)
// v2: Vec[3] = Array(1.5, 2.5, 3.5)
v2.clamped(2.0, 3.0)
// res15: Vec[3] = Array(2.0, 2.5, 3.0)

// mutating (no copy) versions
val v2E = Vec[2](1.5, 2.5); v2E.min(2.0); v2E
// v2E: Vec[2] = Array(2.0, 2.5); v2E.min(2.0); v2E; v2E
// res17: Vec[2] = Array(2.0, 2.5)
val v2F = Vec[2](1.5, 2.5); v2F.MAX(2.0); v2F
// v2F: Vec[2] = Array(1.5, 2.0); v2F.MAX(2.0); v2F; v2F
// res19: Vec[2] = Array(1.5, 2.0)
v2.copy.clamp(2.0, 3.0)