{$IF DEFINED(__MATRIX_HELPER_INTERFACE)} type __HELPER = type helper for __MAT public const {$IF __SIZE = 2} Identity: __MAT = ((1, 0), (0, 1)); {$ELSEIF __SIZE = 3} Identity: __MAT = ((1, 0, 0), (0, 1, 0), (0, 0, 1)); {$ELSEIF __SIZE = 4} Identity: __MAT = ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)); {$ELSE} {$ERROR only vectors of size 2, 3 or 4 are supported} {$ENDIF} public function ToString(const aRound: Integer = -3): String; inline; function Transpose: __MAT; inline; function Determinant: Double; inline; function Invert: __MAT; inline; function Multiply(const m: __MAT): __MAT; inline; class function TryFromString(const s: String; out m: __MAT): Boolean; inline; static; class function FromString(const s: String): __MAT; inline; static; {$IF __SIZE = 3} function AxisX: __VEC3; inline; function AxisY: __VEC3; inline; function Position: __VEC3; inline; function Sub(const aCol, aRow: Integer): __IMPL.TMat2; inline; function Adjoint: __MAT; inline; function Translate(const v: __VEC2): __MAT; inline; function Translate(const x, y: __IMPL.TBaseType): __MAT; inline; function Scale(const v: __VEC2): __MAT; inline; function Scale(const v: __IMPL.TBaseType): __MAT; inline; function Shear(const v: __VEC2): __MAT; inline; function Shear(const x, y: __IMPL.TBaseType): __MAT; inline; function Rotate(const a: Double): __MAT; inline; class function Create(const x, y, z: __VEC3): __MAT; inline; static; class function CreateTranslate(const v: __VEC2): __MAT; inline; static; class function CreateTranslate(const x, y: __IMPL.TBaseType): __MAT; inline; static; class function CreateScale(const v: __VEC2): __MAT; inline; static; class function CreateScale(const v: __IMPL.TBaseType): __MAT; inline; static; class function CreateShear(const v: __VEC2): __MAT; inline; static; class function CreateShear(const x, y: __IMPL.TBaseType): __MAT; inline; static; class function CreateRotate(const a: Double): __MAT; inline; static; {$ELSEIF __SIZE = 4} function AxisX: __VEC4; inline; function AxisY: __VEC4; inline; function AxisZ: __VEC4; inline; function Position: __VEC4; inline; function Sub(const aCol, aRow: Integer): __IMPL.TMat3; inline; function Adjoint: __MAT; inline; function Translate(const v: __VEC3): __MAT; inline; function Translate(const x, y, z: __IMPL.TBaseType): __MAT; inline; function Scale(const v: __VEC3): __MAT; inline; function Scale(const v: __IMPL.TBaseType): __MAT; inline; function Rotate(const axis: __VEC3; const a: Double): __MAT; inline; class function Create(const x, y, z, w: __VEC4): __MAT; inline; static; class function CreateTranslate(const v: __VEC3): __MAT; inline; static; class function CreateTranslate(const x, y, z: __IMPL.TBaseType): __MAT; inline; static; class function CreateScale(const v: __VEC3): __MAT; inline; static; class function CreateScale(const v: __IMPL.TBaseType): __MAT; inline; static; class function CreateShear(const x, y, z: __VEC2): __MAT; inline; static; class function CreateShear(const xy, xz, yx, yz, zx, zy: __IMPL.TBaseType): __MAT; inline; static; class function CreateRotate(const axis: __VEC3; const a: Double): __MAT; inline; static; {$ENDIF} end; operator = (const m1, m2: __MAT): Boolean; inline; operator * (const m1, m2: __MAT): __MAT; inline; operator * (const m: __MAT; const v: __VEC): __VEC; inline; operator * (const s: __IMPL.TBaseType; const m: __MAT): __MAT; inline; operator * (const m: __MAT; const s: __IMPL.TBaseType): __MAT; inline; {$ELSEIF DEFINED (__MATRIX_HELPER_IMPL)} operator = (const m1, m2: __MAT): Boolean; begin result := __IMPL.Equals(m1, m2); end; operator * (const m1, m2: __MAT): __MAT; begin result := __IMPL.Multiply(m1, m2); end; operator * (const m: __MAT; const v: __VEC): __VEC; begin result := __IMPL.Multiply(m, v); end; operator * (const s: __IMPL.TBaseType; const m: __MAT): __MAT; begin result := __IMPL.Multiply(m, s); end; operator * (const m: __MAT; const s: __IMPL.TBaseType): __MAT; begin result := __IMPL.Multiply(m, s); end; function __HELPER.ToString(const aRound: Integer = -3): String; begin result := __IMPL.ToString(self, aRound); end; function __HELPER.Transpose: __MAT; begin result := __IMPL.Transpose(self); end; function __HELPER.Determinant: Double; begin result := __IMPL.Determinant(self); end; function __HELPER.Invert: __MAT; begin result := __IMPL.Invert(self); end; function __HELPER.Multiply(const m: __MAT): __MAT; begin result := __IMPL.Multiply(self, m); end; class function __HELPER.TryFromString(const s: String; out m: __MAT): Boolean; begin result := __IMPL.TryFromString(s, m); end; class function __HELPER.FromString(const s: String): __MAT; begin if not __IMPL.TryFromString(s, result) then result := Identity; end; {$IF __SIZE = 3} function __HELPER.AxisX: __VEC3; begin result := self[0]; end; function __HELPER.AxisY: __VEC3; begin result := self[1]; end; function __HELPER.Position: __VEC3; begin result := self[2]; end; function __HELPER.Sub(const aCol, aRow: Integer): __IMPL.TMat2; begin result := __IMPL.Sub(self, aCol, aRow); end; function __HELPER.Adjoint: __MAT; begin result := __IMPL.Adjoint(self); end; function __HELPER.Translate(const v: __VEC2): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateTranslate(v)); end; function __HELPER.Translate(const x, y: __IMPL.TBaseType): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector2(x, y))); end; function __HELPER.Scale(const v: __VEC2): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateScale(v)); end; function __HELPER.Scale(const v: __IMPL.TBaseType): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateScale(__IMPL.TVectorHelper.Vector2(v, v))); end; function __HELPER.Shear(const v: __VEC2): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateShear(v)); end; function __HELPER.Shear(const x, y: __IMPL.TBaseType): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateShear(__IMPL.TVectorHelper.Vector2(x, y))); end; function __HELPER.Rotate(const a: Double): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateRotate(a)); end; class function __HELPER.Create(const x, y, z: __VEC3): __MAT; begin result := __IMPL.Create(x, y, z); end; class function __HELPER.CreateTranslate(const v: __VEC2): __MAT; begin result := __IMPL.CreateTranslate(v); end; class function __HELPER.CreateTranslate(const x, y: __IMPL.TBaseType): __MAT; begin result := __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector2(x, y)); end; class function __HELPER.CreateScale(const v: __VEC2): __MAT; begin result := __IMPL.CreateScale(v); end; class function __HELPER.CreateScale(const v: __IMPL.TBaseType): __MAT; begin result := __IMPL.CreateScale(__IMPL.TVectorHelper.Vector2(v, v)); end; class function __HELPER.CreateShear(const v: __VEC2): __MAT; begin result := __IMPL.CreateShear(v); end; class function __HELPER.CreateShear(const x, y: __IMPL.TBaseType): __MAT; begin result := __IMPL.CreateShear(__IMPL.TVectorHelper.Vector2(x, y)); end; class function __HELPER.CreateRotate(const a: Double): __MAT; begin result := __IMPL.CreateRotate(a); end; {$ELSEIF __SIZE = 4} function __HELPER.AxisX: __VEC4; begin result := self[0]; end; function __HELPER.AxisY: __VEC4; begin result := self[1]; end; function __HELPER.AxisZ: __VEC4; begin result := self[2]; end; function __HELPER.Position: __VEC4; begin result := self[3]; end; function __HELPER.Sub(const aCol, aRow: Integer): __IMPL.TMat3; begin result := __IMPL.Sub(self, aRow, aCol); end; function __HELPER.Adjoint: __MAT; begin result := __IMPL.Adjoint(self); end; function __HELPER.Translate(const v: __VEC3): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateTranslate(v)); end; function __HELPER.Translate(const x, y, z: __IMPL.TBaseType): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector3(x, y, z))); end; function __HELPER.Scale(const v: __VEC3): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateScale(v)); end; function __HELPER.Scale(const v: __IMPL.TBaseType): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateScale(__IMPL.TVectorHelper.Vector3(v, v, v))); end; function __HELPER.Rotate(const axis: __VEC3; const a: Double): __MAT; begin result := __IMPL.Multiply(self, __IMPL.CreateRotate(axis, a)); end; class function __HELPER.Create(const x, y, z, w: __VEC4): __MAT; begin result := __IMPL.Create(x, y, z, w); end; class function __HELPER.CreateTranslate(const v: __VEC3): __MAT; begin result := __IMPL.CreateTranslate(v); end; class function __HELPER.CreateTranslate(const x, y, z: __IMPL.TBaseType): __MAT; begin result := __IMPL.CreateTranslate(__IMPL.TVectorHelper.Vector3(x, y, z)); end; class function __HELPER.CreateScale(const v: __VEC3): __MAT; begin result := __IMPL.CreateScale(v); end; class function __HELPER.CreateScale(const v: __IMPL.TBaseType): __MAT; begin result := __IMPL.CreateScale(__IMPL.TVectorHelper.Vector3(v, v, v)); end; class function __HELPER.CreateShear(const x, y, z: __VEC2): __MAT; begin result := __IMPL.CreateShear(x, y, z); end; class function __HELPER.CreateShear(const xy, xz, yx, yz, zx, zy: __IMPL.TBaseType): __MAT; begin result := __IMPL.CreateShear( __IMPL.TVectorHelper.Vector2(xy, xz), __IMPL.TVectorHelper.Vector2(yx, yz), __IMPL.TVectorHelper.Vector2(zx, zy)); end; class function __HELPER.CreateRotate(const axis: __VEC3; const a: Double): __MAT; begin result := __IMPL.CreateRotate(axis, a); end; {$ENDIF} {$ENDIF} {$UNDEF __IMPL} {$UNDEF __SIZE} {$UNDEF __VEC} {$UNDEF __MAT} {$UNDEF __HELPER}