Vector

Vector structure.

Members

Functions

fill
typeof(this) fill(const(E) value)

Fill elements.

mul
typeof(this) mul(const(Matrix!(D, D, E)) m, const(Vector!(D, E)) v)

Matrix multiply for vector.

opIndex
const(E) opIndex(size_t i)

Get an element.

opIndexAssign
const(E) opIndexAssign(const(E) value, size_t i)

Set an element.

opIndexOpAssign
const(E) opIndexOpAssign(const(E) value, size_t i)

operation and assign an element.

opOpAssign
typeof(this) opOpAssign(const(typeof(this)) value)

Operation and assign other vector.

opSlice
const(E)[] opSlice()

Properties

ptr
const(E)* ptr [@property getter]

Vector pointer.

Parameters

D

dimensions.

E

element type.

Examples

immutable v = Vector!3([1, 2, 3]);
assert(v[0].isClose(1.0));
assert(v[1].isClose(2.0));
assert(v[2].isClose(3.0));
auto v = Vector!3([1, 2, 3]);
v[0] = 2.0f;
v[1] = 3.0f;
v[2] = 4.0f;

assert(v[0].isClose(2.0));
assert(v[1].isClose(3.0));
assert(v[2].isClose(4.0));

v[0] += 1.0f;
v[1] += 1.0f;
v[2] += 1.0f;

assert(v[0].isClose(3.0));
assert(v[1].isClose(4.0));
assert(v[2].isClose(5.0));
auto v = Vector!3([1, 2, 3]);
immutable u = Vector!3([2, 3, 4]);
v += u;

assert(v[0].isClose(3.0));
assert(v[1].isClose(5.0));
assert(v[2].isClose(7.0));
import std.math : isNaN;

Vector!3 v;
assert(v[0].isNaN);
assert(v[1].isNaN);
assert(v[2].isNaN);

immutable u = Vector!3([2, 3, 4]);
foreach (i, e; u[])
{
    v[i] = e;
}

assert(v[0].isClose(2.0));
assert(v[1].isClose(3.0));
assert(v[2].isClose(4.0));
import std.math : isNaN;

Vector!3 v;
v.fill(1.0);
foreach (e; v[])
{
    assert(e.isClose(1.0));
}
immutable v = Vector!3([1, 2, 3]);
assert(isClose(*(v.ptr), 1.0));
import std.math : isClose;

immutable m = Matrix!(4, 4).unit;
immutable v = Vector!4([1, 2, 3, 0]);
auto result = Vector!4();
result.mul(m, v);
assert(result == v);
import karasux.linear_algebra.vector : isClose;

immutable m = Matrix!(4, 4).scale(2.0, 3.0, 4.0);
immutable v = Vector!4([1, 2, 3, 0]);
auto result = Vector!4();
result.mul(m, v);

assert(result.isClose(Vector!4([2, 6, 12, 0])));

Meta