//| //| ___ __ ______ __________ //| __ | / /_______ /______________(_)_ /_____ __ //| __ | / /_ _ \_ /_ __ \ ___/_ /_ __/_ / / / //| __ |/ / / __/ / / /_/ / /__ _ / / /_ _ /_/ / //| _____/ \___//_/ \____/\___/ /_/ \__/ _\__, / //| __/____/ //| Copyright (c) 2006 Kyle Furlong //| module velocity.math.Vector; /************************************************** A fast vector implementation Examples: --- alias Vector!(int,2) Point; Point origin = Point(0,0); --- **************************************************/ struct Vector(T, int Dim = 4) { private T[Dim] storage; T opIndex(int index) { return storage[index]; } T opIndexAssign(T value, int index) { storage[index] = value; return value; } Vector opAdd(Vector a) { Vector ret; for(int i = 0; i < Dim; i++) { ret[i] = storage[i] + a[i]; } return ret; } Vector opSub(Vector a) { Vector ret; for(int i = 0; i < Dim; i++) { ret[i] = storage[i] - a[i]; } return ret; } Vector opAddAssign(Vector a) { for(int i = 0; i < Dim; i++) { storage[i] += a[i]; } return *this; } Vector opSubAssign(Vector a) { for(int i = 0; i < Dim; i++) { storage[i] -= a[i]; } return *this; } static Vector opCall(...) { Vector v; for (int i = 0; i < Dim; i++) { if (_arguments[i] == typeid(T)) { v[i] = *cast(T *)_argptr; _argptr += T.sizeof; } else assert(0); } return v; } }