diff --git a/ugluVectorEx.inc b/ugluVectorEx.inc new file mode 100644 index 0000000..57def86 --- /dev/null +++ b/ugluVectorEx.inc @@ -0,0 +1,994 @@ +{$IF DEFINED(__VECTOR_HELPER_INTERFACE)} + {$IFDEF __HELPER} + type __HELPER = type helper for __VEC + public + {$IF __SIZE = 2} + class function Create(const x, y: __IMPL.TBaseType): __IMPL.TVector2; static; inline; + {$ELSEIF __SIZE = 3} + class function Create(const x, y, z: __IMPL.TBaseType): __IMPL.TVector3; static; inline; + {$ELSEIF __SIZE = 4} + class function Create(const x, y, z, w: __IMPL.TBaseType): __IMPL.TVector4; static; inline; + {$ELSE} + {$ERROR only vectors of size 2, 3 or 4 are supported} + {$ENDIF} + + function ToString(const aRound: Integer = -3): String; inline; + class function FromString(const s: String): __VEC; static; inline; + class function TryFromString(const s: String; out v: __VEC): Boolean; static; inline; + class function Zero: __VEC; static; inline; + + {$IF __SIZE = 2} + function x: __IMPL.TBaseType; inline; + function y: __IMPL.TBaseType; inline; + function yx: __IMPL.TVector2; inline; + {$ENDIF} + + {$IF __SIZE = 3} + function x: __IMPL.TBaseType; inline; + function y: __IMPL.TBaseType; inline; + function z: __IMPL.TBaseType; inline; + + function xx: __IMPL.TVector2; inline; + function xy: __IMPL.TVector2; inline; + function xz: __IMPL.TVector2; inline; + function yx: __IMPL.TVector2; inline; + function yy: __IMPL.TVector2; inline; + function yz: __IMPL.TVector2; inline; + function zx: __IMPL.TVector2; inline; + function zy: __IMPL.TVector2; inline; + function zz: __IMPL.TVector2; inline; + + function xxx: __IMPL.TVector3; inline; + function xxy: __IMPL.TVector3; inline; + function xxz: __IMPL.TVector3; inline; + function xyx: __IMPL.TVector3; inline; + function xyy: __IMPL.TVector3; inline; + function xyz: __IMPL.TVector3; inline; + function xzx: __IMPL.TVector3; inline; + function xzy: __IMPL.TVector3; inline; + function xzz: __IMPL.TVector3; inline; + + function yxx: __IMPL.TVector3; inline; + function yxy: __IMPL.TVector3; inline; + function yxz: __IMPL.TVector3; inline; + function yyx: __IMPL.TVector3; inline; + function yyy: __IMPL.TVector3; inline; + function yyz: __IMPL.TVector3; inline; + function yzx: __IMPL.TVector3; inline; + function yzy: __IMPL.TVector3; inline; + function yzz: __IMPL.TVector3; inline; + + function zxx: __IMPL.TVector3; inline; + function zxy: __IMPL.TVector3; inline; + function zxz: __IMPL.TVector3; inline; + function zyx: __IMPL.TVector3; inline; + function zyy: __IMPL.TVector3; inline; + function zyz: __IMPL.TVector3; inline; + function zzx: __IMPL.TVector3; inline; + function zzy: __IMPL.TVector3; inline; + function zzz: __IMPL.TVector3; inline; + {$ENDIF} + + {$IF __SIZE = 4} + function x: __IMPL.TBaseType; inline; + function y: __IMPL.TBaseType; inline; + function z: __IMPL.TBaseType; inline; + function w: __IMPL.TBaseType; inline; + + function xx: __IMPL.TVector2; inline; + function xy: __IMPL.TVector2; inline; + function xz: __IMPL.TVector2; inline; + function xw: __IMPL.TVector2; inline; + function yx: __IMPL.TVector2; inline; + function yy: __IMPL.TVector2; inline; + function yz: __IMPL.TVector2; inline; + function yw: __IMPL.TVector2; inline; + function zx: __IMPL.TVector2; inline; + function zy: __IMPL.TVector2; inline; + function zz: __IMPL.TVector2; inline; + function zw: __IMPL.TVector2; inline; + function wx: __IMPL.TVector2; inline; + function wy: __IMPL.TVector2; inline; + function wz: __IMPL.TVector2; inline; + function ww: __IMPL.TVector2; inline; + + function xxx: __IMPL.TVector3; inline; + function xxy: __IMPL.TVector3; inline; + function xxz: __IMPL.TVector3; inline; + function xxw: __IMPL.TVector3; inline; + function xyx: __IMPL.TVector3; inline; + function xyy: __IMPL.TVector3; inline; + function xyz: __IMPL.TVector3; inline; + function xyw: __IMPL.TVector3; inline; + function xzx: __IMPL.TVector3; inline; + function xzy: __IMPL.TVector3; inline; + function xzz: __IMPL.TVector3; inline; + function xzw: __IMPL.TVector3; inline; + function xwx: __IMPL.TVector3; inline; + function xwy: __IMPL.TVector3; inline; + function xwz: __IMPL.TVector3; inline; + function xww: __IMPL.TVector3; inline; + function yxx: __IMPL.TVector3; inline; + function yxy: __IMPL.TVector3; inline; + function yxz: __IMPL.TVector3; inline; + function yxw: __IMPL.TVector3; inline; + function yyx: __IMPL.TVector3; inline; + function yyy: __IMPL.TVector3; inline; + function yyz: __IMPL.TVector3; inline; + function yyw: __IMPL.TVector3; inline; + function yzx: __IMPL.TVector3; inline; + function yzy: __IMPL.TVector3; inline; + function yzz: __IMPL.TVector3; inline; + function yzw: __IMPL.TVector3; inline; + function ywx: __IMPL.TVector3; inline; + function ywy: __IMPL.TVector3; inline; + function ywz: __IMPL.TVector3; inline; + function yww: __IMPL.TVector3; inline; + function zxx: __IMPL.TVector3; inline; + function zxy: __IMPL.TVector3; inline; + function zxz: __IMPL.TVector3; inline; + function zxw: __IMPL.TVector3; inline; + function zyx: __IMPL.TVector3; inline; + function zyy: __IMPL.TVector3; inline; + function zyz: __IMPL.TVector3; inline; + function zyw: __IMPL.TVector3; inline; + function zzx: __IMPL.TVector3; inline; + function zzy: __IMPL.TVector3; inline; + function zzz: __IMPL.TVector3; inline; + function zzw: __IMPL.TVector3; inline; + function zwx: __IMPL.TVector3; inline; + function zwy: __IMPL.TVector3; inline; + function zwz: __IMPL.TVector3; inline; + function zww: __IMPL.TVector3; inline; + function wxx: __IMPL.TVector3; inline; + function wxy: __IMPL.TVector3; inline; + function wxz: __IMPL.TVector3; inline; + function wxw: __IMPL.TVector3; inline; + function wyx: __IMPL.TVector3; inline; + function wyy: __IMPL.TVector3; inline; + function wyz: __IMPL.TVector3; inline; + function wyw: __IMPL.TVector3; inline; + function wzx: __IMPL.TVector3; inline; + function wzy: __IMPL.TVector3; inline; + function wzz: __IMPL.TVector3; inline; + function wzw: __IMPL.TVector3; inline; + function wwx: __IMPL.TVector3; inline; + function wwy: __IMPL.TVector3; inline; + function wwz: __IMPL.TVector3; inline; + function www: __IMPL.TVector3; inline; + + function xxxx: __IMPL.TVector4; inline; + function xxxy: __IMPL.TVector4; inline; + function xxxz: __IMPL.TVector4; inline; + function xxxw: __IMPL.TVector4; inline; + function xxyx: __IMPL.TVector4; inline; + function xxyy: __IMPL.TVector4; inline; + function xxyz: __IMPL.TVector4; inline; + function xxyw: __IMPL.TVector4; inline; + function xxzx: __IMPL.TVector4; inline; + function xxzy: __IMPL.TVector4; inline; + function xxzz: __IMPL.TVector4; inline; + function xxzw: __IMPL.TVector4; inline; + function xxwx: __IMPL.TVector4; inline; + function xxwy: __IMPL.TVector4; inline; + function xxwz: __IMPL.TVector4; inline; + function xxww: __IMPL.TVector4; inline; + function xyxx: __IMPL.TVector4; inline; + function xyxy: __IMPL.TVector4; inline; + function xyxz: __IMPL.TVector4; inline; + function xyxw: __IMPL.TVector4; inline; + function xyyx: __IMPL.TVector4; inline; + function xyyy: __IMPL.TVector4; inline; + function xyyz: __IMPL.TVector4; inline; + function xyyw: __IMPL.TVector4; inline; + function xyzx: __IMPL.TVector4; inline; + function xyzy: __IMPL.TVector4; inline; + function xyzz: __IMPL.TVector4; inline; + function xyzw: __IMPL.TVector4; inline; + function xywx: __IMPL.TVector4; inline; + function xywy: __IMPL.TVector4; inline; + function xywz: __IMPL.TVector4; inline; + function xyww: __IMPL.TVector4; inline; + function xzxx: __IMPL.TVector4; inline; + function xzxy: __IMPL.TVector4; inline; + function xzxz: __IMPL.TVector4; inline; + function xzxw: __IMPL.TVector4; inline; + function xzyx: __IMPL.TVector4; inline; + function xzyy: __IMPL.TVector4; inline; + function xzyz: __IMPL.TVector4; inline; + function xzyw: __IMPL.TVector4; inline; + function xzzx: __IMPL.TVector4; inline; + function xzzy: __IMPL.TVector4; inline; + function xzzz: __IMPL.TVector4; inline; + function xzzw: __IMPL.TVector4; inline; + function xzwx: __IMPL.TVector4; inline; + function xzwy: __IMPL.TVector4; inline; + function xzwz: __IMPL.TVector4; inline; + function xzww: __IMPL.TVector4; inline; + function xwxx: __IMPL.TVector4; inline; + function xwxy: __IMPL.TVector4; inline; + function xwxz: __IMPL.TVector4; inline; + function xwxw: __IMPL.TVector4; inline; + function xwyx: __IMPL.TVector4; inline; + function xwyy: __IMPL.TVector4; inline; + function xwyz: __IMPL.TVector4; inline; + function xwyw: __IMPL.TVector4; inline; + function xwzx: __IMPL.TVector4; inline; + function xwzy: __IMPL.TVector4; inline; + function xwzz: __IMPL.TVector4; inline; + function xwzw: __IMPL.TVector4; inline; + function xwwx: __IMPL.TVector4; inline; + function xwwy: __IMPL.TVector4; inline; + function xwwz: __IMPL.TVector4; inline; + function xwww: __IMPL.TVector4; inline; + function yxxx: __IMPL.TVector4; inline; + function yxxy: __IMPL.TVector4; inline; + function yxxz: __IMPL.TVector4; inline; + function yxxw: __IMPL.TVector4; inline; + function yxyx: __IMPL.TVector4; inline; + function yxyy: __IMPL.TVector4; inline; + function yxyz: __IMPL.TVector4; inline; + function yxyw: __IMPL.TVector4; inline; + function yxzx: __IMPL.TVector4; inline; + function yxzy: __IMPL.TVector4; inline; + function yxzz: __IMPL.TVector4; inline; + function yxzw: __IMPL.TVector4; inline; + function yxwx: __IMPL.TVector4; inline; + function yxwy: __IMPL.TVector4; inline; + function yxwz: __IMPL.TVector4; inline; + function yxww: __IMPL.TVector4; inline; + function yyxx: __IMPL.TVector4; inline; + function yyxy: __IMPL.TVector4; inline; + function yyxz: __IMPL.TVector4; inline; + function yyxw: __IMPL.TVector4; inline; + function yyyx: __IMPL.TVector4; inline; + function yyyy: __IMPL.TVector4; inline; + function yyyz: __IMPL.TVector4; inline; + function yyyw: __IMPL.TVector4; inline; + function yyzx: __IMPL.TVector4; inline; + function yyzy: __IMPL.TVector4; inline; + function yyzz: __IMPL.TVector4; inline; + function yyzw: __IMPL.TVector4; inline; + function yywx: __IMPL.TVector4; inline; + function yywy: __IMPL.TVector4; inline; + function yywz: __IMPL.TVector4; inline; + function yyww: __IMPL.TVector4; inline; + function yzxx: __IMPL.TVector4; inline; + function yzxy: __IMPL.TVector4; inline; + function yzxz: __IMPL.TVector4; inline; + function yzxw: __IMPL.TVector4; inline; + function yzyx: __IMPL.TVector4; inline; + function yzyy: __IMPL.TVector4; inline; + function yzyz: __IMPL.TVector4; inline; + function yzyw: __IMPL.TVector4; inline; + function yzzx: __IMPL.TVector4; inline; + function yzzy: __IMPL.TVector4; inline; + function yzzz: __IMPL.TVector4; inline; + function yzzw: __IMPL.TVector4; inline; + function yzwx: __IMPL.TVector4; inline; + function yzwy: __IMPL.TVector4; inline; + function yzwz: __IMPL.TVector4; inline; + function yzww: __IMPL.TVector4; inline; + function ywxx: __IMPL.TVector4; inline; + function ywxy: __IMPL.TVector4; inline; + function ywxz: __IMPL.TVector4; inline; + function ywxw: __IMPL.TVector4; inline; + function ywyx: __IMPL.TVector4; inline; + function ywyy: __IMPL.TVector4; inline; + function ywyz: __IMPL.TVector4; inline; + function ywyw: __IMPL.TVector4; inline; + function ywzx: __IMPL.TVector4; inline; + function ywzy: __IMPL.TVector4; inline; + function ywzz: __IMPL.TVector4; inline; + function ywzw: __IMPL.TVector4; inline; + function ywwx: __IMPL.TVector4; inline; + function ywwy: __IMPL.TVector4; inline; + function ywwz: __IMPL.TVector4; inline; + function ywww: __IMPL.TVector4; inline; + function zxxx: __IMPL.TVector4; inline; + function zxxy: __IMPL.TVector4; inline; + function zxxz: __IMPL.TVector4; inline; + function zxxw: __IMPL.TVector4; inline; + function zxyx: __IMPL.TVector4; inline; + function zxyy: __IMPL.TVector4; inline; + function zxyz: __IMPL.TVector4; inline; + function zxyw: __IMPL.TVector4; inline; + function zxzx: __IMPL.TVector4; inline; + function zxzy: __IMPL.TVector4; inline; + function zxzz: __IMPL.TVector4; inline; + function zxzw: __IMPL.TVector4; inline; + function zxwx: __IMPL.TVector4; inline; + function zxwy: __IMPL.TVector4; inline; + function zxwz: __IMPL.TVector4; inline; + function zxww: __IMPL.TVector4; inline; + function zyxx: __IMPL.TVector4; inline; + function zyxy: __IMPL.TVector4; inline; + function zyxz: __IMPL.TVector4; inline; + function zyxw: __IMPL.TVector4; inline; + function zyyx: __IMPL.TVector4; inline; + function zyyy: __IMPL.TVector4; inline; + function zyyz: __IMPL.TVector4; inline; + function zyyw: __IMPL.TVector4; inline; + function zyzx: __IMPL.TVector4; inline; + function zyzy: __IMPL.TVector4; inline; + function zyzz: __IMPL.TVector4; inline; + function zyzw: __IMPL.TVector4; inline; + function zywx: __IMPL.TVector4; inline; + function zywy: __IMPL.TVector4; inline; + function zywz: __IMPL.TVector4; inline; + function zyww: __IMPL.TVector4; inline; + function zzxx: __IMPL.TVector4; inline; + function zzxy: __IMPL.TVector4; inline; + function zzxz: __IMPL.TVector4; inline; + function zzxw: __IMPL.TVector4; inline; + function zzyx: __IMPL.TVector4; inline; + function zzyy: __IMPL.TVector4; inline; + function zzyz: __IMPL.TVector4; inline; + function zzyw: __IMPL.TVector4; inline; + function zzzx: __IMPL.TVector4; inline; + function zzzy: __IMPL.TVector4; inline; + function zzzz: __IMPL.TVector4; inline; + function zzzw: __IMPL.TVector4; inline; + function zzwx: __IMPL.TVector4; inline; + function zzwy: __IMPL.TVector4; inline; + function zzwz: __IMPL.TVector4; inline; + function zzww: __IMPL.TVector4; inline; + function zwxx: __IMPL.TVector4; inline; + function zwxy: __IMPL.TVector4; inline; + function zwxz: __IMPL.TVector4; inline; + function zwxw: __IMPL.TVector4; inline; + function zwyx: __IMPL.TVector4; inline; + function zwyy: __IMPL.TVector4; inline; + function zwyz: __IMPL.TVector4; inline; + function zwyw: __IMPL.TVector4; inline; + function zwzx: __IMPL.TVector4; inline; + function zwzy: __IMPL.TVector4; inline; + function zwzz: __IMPL.TVector4; inline; + function zwzw: __IMPL.TVector4; inline; + function zwwx: __IMPL.TVector4; inline; + function zwwy: __IMPL.TVector4; inline; + function zwwz: __IMPL.TVector4; inline; + function zwww: __IMPL.TVector4; inline; + function wxxx: __IMPL.TVector4; inline; + function wxxy: __IMPL.TVector4; inline; + function wxxz: __IMPL.TVector4; inline; + function wxxw: __IMPL.TVector4; inline; + function wxyx: __IMPL.TVector4; inline; + function wxyy: __IMPL.TVector4; inline; + function wxyz: __IMPL.TVector4; inline; + function wxyw: __IMPL.TVector4; inline; + function wxzx: __IMPL.TVector4; inline; + function wxzy: __IMPL.TVector4; inline; + function wxzz: __IMPL.TVector4; inline; + function wxzw: __IMPL.TVector4; inline; + function wxwx: __IMPL.TVector4; inline; + function wxwy: __IMPL.TVector4; inline; + function wxwz: __IMPL.TVector4; inline; + function wxww: __IMPL.TVector4; inline; + function wyxx: __IMPL.TVector4; inline; + function wyxy: __IMPL.TVector4; inline; + function wyxz: __IMPL.TVector4; inline; + function wyxw: __IMPL.TVector4; inline; + function wyyx: __IMPL.TVector4; inline; + function wyyy: __IMPL.TVector4; inline; + function wyyz: __IMPL.TVector4; inline; + function wyyw: __IMPL.TVector4; inline; + function wyzx: __IMPL.TVector4; inline; + function wyzy: __IMPL.TVector4; inline; + function wyzz: __IMPL.TVector4; inline; + function wyzw: __IMPL.TVector4; inline; + function wywx: __IMPL.TVector4; inline; + function wywy: __IMPL.TVector4; inline; + function wywz: __IMPL.TVector4; inline; + function wyww: __IMPL.TVector4; inline; + function wzxx: __IMPL.TVector4; inline; + function wzxy: __IMPL.TVector4; inline; + function wzxz: __IMPL.TVector4; inline; + function wzxw: __IMPL.TVector4; inline; + function wzyx: __IMPL.TVector4; inline; + function wzyy: __IMPL.TVector4; inline; + function wzyz: __IMPL.TVector4; inline; + function wzyw: __IMPL.TVector4; inline; + function wzzx: __IMPL.TVector4; inline; + function wzzy: __IMPL.TVector4; inline; + function wzzz: __IMPL.TVector4; inline; + function wzzw: __IMPL.TVector4; inline; + function wzwx: __IMPL.TVector4; inline; + function wzwy: __IMPL.TVector4; inline; + function wzwz: __IMPL.TVector4; inline; + function wzww: __IMPL.TVector4; inline; + function wwxx: __IMPL.TVector4; inline; + function wwxy: __IMPL.TVector4; inline; + function wwxz: __IMPL.TVector4; inline; + function wwxw: __IMPL.TVector4; inline; + function wwyx: __IMPL.TVector4; inline; + function wwyy: __IMPL.TVector4; inline; + function wwyz: __IMPL.TVector4; inline; + function wwyw: __IMPL.TVector4; inline; + function wwzx: __IMPL.TVector4; inline; + function wwzy: __IMPL.TVector4; inline; + function wwzz: __IMPL.TVector4; inline; + function wwzw: __IMPL.TVector4; inline; + function wwwx: __IMPL.TVector4; inline; + function wwwy: __IMPL.TVector4; inline; + function wwwz: __IMPL.TVector4; inline; + function wwww: __IMPL.TVector4; inline; + {$ENDIF} + end; + operator = (const v1, v2: __VEC): Boolean; inline; + {$IFDEF __HELPER_I} + type __HELPER_I = type helper(__HELPER) for __VEC + public + function Length: Double; inline; + {$IF __SIZE <> 4} + function Add(const v: __VEC): __VEC; inline; + function Subtract(const v: __VEC): __VEC; inline; + {$ENDIF} + function Multiply(const v: __IMPL.TBaseType): __VEC; inline; + end; + {$IF __SIZE <> 4} + operator + (const v1, v2: __VEC): __VEC; inline; + operator - (const v1, v2: __VEC): __VEC; inline; + {$ENDIF} + {$IFDEF __HELPER_F} + type __HELPER_F = type helper(__HELPER_I) for __VEC + public + function Normalize: __VEC; inline; + function Divide(const v: __IMPL.TBaseType): __VEC; inline; + function Dot(const v: __VEC): __IMPL.TBaseType; inline; + {$IF __SIZE <> 4} + function Angle(const v: __VEC): Double; inline; + {$ENDIF} + {$IF __SIZE = 2} + function Angle2(const v: __VEC): Double; inline; + {$ENDIF} + function Clamp(const min, max: __VEC): __VEC; inline; + function Clamp(const min, max: __IMPL.TBaseType): __VEC; inline; + end; + operator * (const v: __VEC; const s: __IMPL.TBaseType): __VEC; + operator * (const s: __IMPL.TBaseType; const v: __VEC): __VEC; + operator * (const v1, v2: __VEC): __IMPL.TBaseType; + {$ENDIF} + {$ENDIF} + {$ENDIF} +{$ELSEIF DEFINED (__VECTOR_HELPER_IMPL)} + {$IFDEF __HELPER} + {$IF __SIZE = 2} + class function __HELPER.Create(const x, y: __IMPL.TBaseType): __VEC; + begin + result := __IMPL.Vector2(x, y); + end; + {$ELSEIF __SIZE = 3} + class function __HELPER.Create(const x, y, z: __IMPL.TBaseType): __VEC; + begin + result := __IMPL.Vector3(x, y, z); + end; + {$ELSEIF __SIZE = 4} + class function __HELPER.Create(const x, y, z, w: __IMPL.TBaseType): __VEC; + begin + result := __IMPL.Vector4(x, y, z, w); + end; + {$ENDIF} + + function __HELPER.ToString(const aRound: Integer): String; + begin + result := __IMPL.ToString(self, aRound); + end; + + class function __HELPER.FromString(const s: String): __VEC; + begin + if not __IMPL.TryFromString(s, result) then + result := Zero; + end; + + class function __HELPER.TryFromString(const s: String; out v: __VEC): Boolean; + begin + result := __IMPl.TryFromString(s, v); + end; + + class function __HELPER.Zero: __VEC; + begin + FillByte(result{%H-}[0], Length(result) * SizeOf(result[0]), 0); + end; + + {$IF __SIZE = 2} + function __HELPER.x: __IMPL.TBaseType; begin result := self[0]; end; + function __HELPER.y: __IMPL.TBaseType; begin result := self[1]; end; + function __HELPER.yx: __IMPL.TVector2; begin result := __IMPL.Vector2(self[1], self[0]); end; + {$ENDIF} + + {$IF __SIZE = 3} + function __HELPER.x: __IMPL.TBaseType; begin result := self[0]; end; + function __HELPER.y: __IMPL.TBaseType; begin result := self[1]; end; + function __HELPER.z: __IMPL.TBaseType; begin result := self[2]; end; + + function __HELPER.xx: __IMPL.TVector2; begin result := __IMPL.Vector2(self[0], self[0]); end; + function __HELPER.xy: __IMPL.TVector2; begin result := __IMPL.Vector2(self[0], self[1]); end; + function __HELPER.xz: __IMPL.TVector2; begin result := __IMPL.Vector2(self[0], self[2]); end; + function __HELPER.yx: __IMPL.TVector2; begin result := __IMPL.Vector2(self[1], self[0]); end; + function __HELPER.yy: __IMPL.TVector2; begin result := __IMPL.Vector2(self[1], self[1]); end; + function __HELPER.yz: __IMPL.TVector2; begin result := __IMPL.Vector2(self[1], self[2]); end; + function __HELPER.zx: __IMPL.TVector2; begin result := __IMPL.Vector2(self[2], self[0]); end; + function __HELPER.zy: __IMPL.TVector2; begin result := __IMPL.Vector2(self[2], self[1]); end; + function __HELPER.zz: __IMPL.TVector2; begin result := __IMPL.Vector2(self[2], self[2]); end; + + function __HELPER.xxx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[0]); end; + function __HELPER.xxy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[1]); end; + function __HELPER.xxz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[2]); end; + function __HELPER.xyx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[0]); end; + function __HELPER.xyy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[1]); end; + function __HELPER.xyz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[2]); end; + function __HELPER.xzx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[0]); end; + function __HELPER.xzy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[1]); end; + function __HELPER.xzz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[1]); end; + + function __HELPER.yxx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[0]); end; + function __HELPER.yxy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[1]); end; + function __HELPER.yxz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[2]); end; + function __HELPER.yyx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[0]); end; + function __HELPER.yyy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[1]); end; + function __HELPER.yyz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[2]); end; + function __HELPER.yzx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[0]); end; + function __HELPER.yzy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[1]); end; + function __HELPER.yzz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[2]); end; + + function __HELPER.zxx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[0]); end; + function __HELPER.zxy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[1]); end; + function __HELPER.zxz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[2]); end; + function __HELPER.zyx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[0]); end; + function __HELPER.zyy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[1]); end; + function __HELPER.zyz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[2]); end; + function __HELPER.zzx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[0]); end; + function __HELPER.zzy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[1]); end; + function __HELPER.zzz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[2]); end; + {$ENDIF} + + {$IF __SIZE = 4} + function __Helper.x: __IMPL.TBaseType; begin result := self[0]; end; + function __Helper.y: __IMPL.TBaseType; begin result := self[1]; end; + function __Helper.z: __IMPL.TBaseType; begin result := self[2]; end; + function __Helper.w: __IMPL.TBaseType; begin result := self[3]; end; + + function __Helper.xx: __IMPL.TVector2; begin result := __IMPL.Vector2(self[0], self[0]); end; + function __Helper.xy: __IMPL.TVector2; begin result := __IMPL.Vector2(self[0], self[1]); end; + function __Helper.xz: __IMPL.TVector2; begin result := __IMPL.Vector2(self[0], self[2]); end; + function __Helper.xw: __IMPL.TVector2; begin result := __IMPL.Vector2(self[0], self[3]); end; + function __Helper.yx: __IMPL.TVector2; begin result := __IMPL.Vector2(self[1], self[0]); end; + function __Helper.yy: __IMPL.TVector2; begin result := __IMPL.Vector2(self[1], self[1]); end; + function __Helper.yz: __IMPL.TVector2; begin result := __IMPL.Vector2(self[1], self[2]); end; + function __Helper.yw: __IMPL.TVector2; begin result := __IMPL.Vector2(self[1], self[3]); end; + function __Helper.zx: __IMPL.TVector2; begin result := __IMPL.Vector2(self[2], self[0]); end; + function __Helper.zy: __IMPL.TVector2; begin result := __IMPL.Vector2(self[2], self[1]); end; + function __Helper.zz: __IMPL.TVector2; begin result := __IMPL.Vector2(self[2], self[2]); end; + function __Helper.zw: __IMPL.TVector2; begin result := __IMPL.Vector2(self[2], self[3]); end; + function __Helper.wx: __IMPL.TVector2; begin result := __IMPL.Vector2(self[3], self[0]); end; + function __Helper.wy: __IMPL.TVector2; begin result := __IMPL.Vector2(self[3], self[1]); end; + function __Helper.wz: __IMPL.TVector2; begin result := __IMPL.Vector2(self[3], self[2]); end; + function __Helper.ww: __IMPL.TVector2; begin result := __IMPL.Vector2(self[3], self[3]); end; + + function __Helper.xxx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[0]); end; + function __Helper.xxy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[1]); end; + function __Helper.xxz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[2]); end; + function __Helper.xxw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[0], self[3]); end; + function __Helper.xyx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[0]); end; + function __Helper.xyy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[1]); end; + function __Helper.xyz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[2]); end; + function __Helper.xyw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[1], self[3]); end; + function __Helper.xzx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[0]); end; + function __Helper.xzy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[1]); end; + function __Helper.xzz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[2]); end; + function __Helper.xzw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[2], self[3]); end; + function __Helper.xwx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[3], self[0]); end; + function __Helper.xwy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[3], self[1]); end; + function __Helper.xwz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[3], self[2]); end; + function __Helper.xww: __IMPL.TVector3; begin result := __IMPL.Vector3(self[0], self[3], self[3]); end; + function __Helper.yxx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[0], self[0]); end; + function __Helper.yxy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[0], self[1]); end; + function __Helper.yxz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[0], self[2]); end; + function __Helper.yxw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[0], self[3]); end; + function __Helper.yyx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[1], self[0]); end; + function __Helper.yyy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[1], self[1]); end; + function __Helper.yyz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[1], self[2]); end; + function __Helper.yyw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[1], self[3]); end; + function __Helper.yzx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[2], self[0]); end; + function __Helper.yzy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[2], self[1]); end; + function __Helper.yzz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[2], self[2]); end; + function __Helper.yzw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[2], self[3]); end; + function __Helper.ywx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[3], self[0]); end; + function __Helper.ywy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[3], self[1]); end; + function __Helper.ywz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[3], self[2]); end; + function __Helper.yww: __IMPL.TVector3; begin result := __IMPL.Vector3(self[1], self[3], self[3]); end; + function __Helper.zxx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[0], self[0]); end; + function __Helper.zxy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[0], self[1]); end; + function __Helper.zxz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[0], self[2]); end; + function __Helper.zxw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[0], self[3]); end; + function __Helper.zyx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[1], self[0]); end; + function __Helper.zyy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[1], self[1]); end; + function __Helper.zyz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[1], self[2]); end; + function __Helper.zyw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[1], self[3]); end; + function __Helper.zzx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[2], self[0]); end; + function __Helper.zzy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[2], self[1]); end; + function __Helper.zzz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[2], self[2]); end; + function __Helper.zzw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[2], self[3]); end; + function __Helper.zwx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[3], self[0]); end; + function __Helper.zwy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[3], self[1]); end; + function __Helper.zwz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[3], self[2]); end; + function __Helper.zww: __IMPL.TVector3; begin result := __IMPL.Vector3(self[2], self[3], self[3]); end; + function __Helper.wxx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[0], self[0]); end; + function __Helper.wxy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[0], self[1]); end; + function __Helper.wxz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[0], self[2]); end; + function __Helper.wxw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[0], self[3]); end; + function __Helper.wyx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[1], self[0]); end; + function __Helper.wyy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[1], self[1]); end; + function __Helper.wyz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[1], self[2]); end; + function __Helper.wyw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[1], self[3]); end; + function __Helper.wzx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[2], self[0]); end; + function __Helper.wzy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[2], self[1]); end; + function __Helper.wzz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[2], self[2]); end; + function __Helper.wzw: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[2], self[3]); end; + function __Helper.wwx: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[3], self[0]); end; + function __Helper.wwy: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[3], self[1]); end; + function __Helper.wwz: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[3], self[2]); end; + function __Helper.www: __IMPL.TVector3; begin result := __IMPL.Vector3(self[3], self[3], self[3]); end; + + function __Helper.xxxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[0], self[0]); end; + function __Helper.xxxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[0], self[1]); end; + function __Helper.xxxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[0], self[2]); end; + function __Helper.xxxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[0], self[3]); end; + function __Helper.xxyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[1], self[0]); end; + function __Helper.xxyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[1], self[1]); end; + function __Helper.xxyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[1], self[2]); end; + function __Helper.xxyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[1], self[3]); end; + function __Helper.xxzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[2], self[0]); end; + function __Helper.xxzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[2], self[1]); end; + function __Helper.xxzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[2], self[2]); end; + function __Helper.xxzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[2], self[3]); end; + function __Helper.xxwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[3], self[0]); end; + function __Helper.xxwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[3], self[1]); end; + function __Helper.xxwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[3], self[2]); end; + function __Helper.xxww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[0], self[3], self[3]); end; + function __Helper.xyxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[0], self[0]); end; + function __Helper.xyxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[0], self[1]); end; + function __Helper.xyxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[0], self[2]); end; + function __Helper.xyxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[0], self[3]); end; + function __Helper.xyyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[1], self[0]); end; + function __Helper.xyyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[1], self[1]); end; + function __Helper.xyyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[1], self[2]); end; + function __Helper.xyyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[1], self[3]); end; + function __Helper.xyzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[2], self[0]); end; + function __Helper.xyzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[2], self[1]); end; + function __Helper.xyzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[2], self[2]); end; + function __Helper.xyzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[2], self[3]); end; + function __Helper.xywx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[3], self[0]); end; + function __Helper.xywy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[3], self[1]); end; + function __Helper.xywz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[3], self[2]); end; + function __Helper.xyww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[1], self[3], self[3]); end; + function __Helper.xzxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[0], self[0]); end; + function __Helper.xzxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[0], self[1]); end; + function __Helper.xzxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[0], self[2]); end; + function __Helper.xzxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[0], self[3]); end; + function __Helper.xzyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[1], self[0]); end; + function __Helper.xzyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[1], self[1]); end; + function __Helper.xzyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[1], self[2]); end; + function __Helper.xzyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[1], self[3]); end; + function __Helper.xzzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[2], self[0]); end; + function __Helper.xzzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[2], self[1]); end; + function __Helper.xzzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[2], self[2]); end; + function __Helper.xzzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[2], self[3]); end; + function __Helper.xzwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[3], self[0]); end; + function __Helper.xzwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[3], self[1]); end; + function __Helper.xzwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[3], self[2]); end; + function __Helper.xzww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[2], self[3], self[3]); end; + function __Helper.xwxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[0], self[0]); end; + function __Helper.xwxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[0], self[1]); end; + function __Helper.xwxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[0], self[2]); end; + function __Helper.xwxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[0], self[3]); end; + function __Helper.xwyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[1], self[0]); end; + function __Helper.xwyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[1], self[1]); end; + function __Helper.xwyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[1], self[2]); end; + function __Helper.xwyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[1], self[3]); end; + function __Helper.xwzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[2], self[0]); end; + function __Helper.xwzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[2], self[1]); end; + function __Helper.xwzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[2], self[2]); end; + function __Helper.xwzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[2], self[3]); end; + function __Helper.xwwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[3], self[0]); end; + function __Helper.xwwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[3], self[1]); end; + function __Helper.xwwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[3], self[2]); end; + function __Helper.xwww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[0], self[3], self[3], self[3]); end; + function __Helper.yxxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[0], self[0]); end; + function __Helper.yxxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[0], self[1]); end; + function __Helper.yxxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[0], self[2]); end; + function __Helper.yxxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[0], self[3]); end; + function __Helper.yxyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[1], self[0]); end; + function __Helper.yxyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[1], self[1]); end; + function __Helper.yxyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[1], self[2]); end; + function __Helper.yxyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[1], self[3]); end; + function __Helper.yxzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[2], self[0]); end; + function __Helper.yxzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[2], self[1]); end; + function __Helper.yxzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[2], self[2]); end; + function __Helper.yxzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[2], self[3]); end; + function __Helper.yxwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[3], self[0]); end; + function __Helper.yxwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[3], self[1]); end; + function __Helper.yxwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[3], self[2]); end; + function __Helper.yxww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[0], self[3], self[3]); end; + function __Helper.yyxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[0], self[0]); end; + function __Helper.yyxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[0], self[1]); end; + function __Helper.yyxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[0], self[2]); end; + function __Helper.yyxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[0], self[3]); end; + function __Helper.yyyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[1], self[0]); end; + function __Helper.yyyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[1], self[1]); end; + function __Helper.yyyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[1], self[2]); end; + function __Helper.yyyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[1], self[3]); end; + function __Helper.yyzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[2], self[0]); end; + function __Helper.yyzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[2], self[1]); end; + function __Helper.yyzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[2], self[2]); end; + function __Helper.yyzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[2], self[3]); end; + function __Helper.yywx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[3], self[0]); end; + function __Helper.yywy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[3], self[1]); end; + function __Helper.yywz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[3], self[2]); end; + function __Helper.yyww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[1], self[3], self[3]); end; + function __Helper.yzxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[0], self[0]); end; + function __Helper.yzxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[0], self[1]); end; + function __Helper.yzxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[0], self[2]); end; + function __Helper.yzxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[0], self[3]); end; + function __Helper.yzyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[1], self[0]); end; + function __Helper.yzyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[1], self[1]); end; + function __Helper.yzyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[1], self[2]); end; + function __Helper.yzyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[1], self[3]); end; + function __Helper.yzzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[2], self[0]); end; + function __Helper.yzzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[2], self[1]); end; + function __Helper.yzzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[2], self[2]); end; + function __Helper.yzzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[2], self[3]); end; + function __Helper.yzwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[3], self[0]); end; + function __Helper.yzwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[3], self[1]); end; + function __Helper.yzwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[3], self[2]); end; + function __Helper.yzww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[2], self[3], self[3]); end; + function __Helper.ywxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[0], self[0]); end; + function __Helper.ywxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[0], self[1]); end; + function __Helper.ywxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[0], self[2]); end; + function __Helper.ywxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[0], self[3]); end; + function __Helper.ywyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[1], self[0]); end; + function __Helper.ywyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[1], self[1]); end; + function __Helper.ywyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[1], self[2]); end; + function __Helper.ywyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[1], self[3]); end; + function __Helper.ywzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[2], self[0]); end; + function __Helper.ywzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[2], self[1]); end; + function __Helper.ywzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[2], self[2]); end; + function __Helper.ywzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[2], self[3]); end; + function __Helper.ywwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[3], self[0]); end; + function __Helper.ywwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[3], self[1]); end; + function __Helper.ywwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[3], self[2]); end; + function __Helper.ywww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[1], self[3], self[3], self[3]); end; + function __Helper.zxxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[0], self[0]); end; + function __Helper.zxxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[0], self[1]); end; + function __Helper.zxxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[0], self[2]); end; + function __Helper.zxxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[0], self[3]); end; + function __Helper.zxyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[1], self[0]); end; + function __Helper.zxyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[1], self[1]); end; + function __Helper.zxyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[1], self[2]); end; + function __Helper.zxyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[1], self[3]); end; + function __Helper.zxzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[2], self[0]); end; + function __Helper.zxzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[2], self[1]); end; + function __Helper.zxzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[2], self[2]); end; + function __Helper.zxzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[2], self[3]); end; + function __Helper.zxwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[3], self[0]); end; + function __Helper.zxwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[3], self[1]); end; + function __Helper.zxwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[3], self[2]); end; + function __Helper.zxww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[0], self[3], self[3]); end; + function __Helper.zyxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[0], self[0]); end; + function __Helper.zyxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[0], self[1]); end; + function __Helper.zyxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[0], self[2]); end; + function __Helper.zyxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[0], self[3]); end; + function __Helper.zyyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[1], self[0]); end; + function __Helper.zyyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[1], self[1]); end; + function __Helper.zyyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[1], self[2]); end; + function __Helper.zyyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[1], self[3]); end; + function __Helper.zyzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[2], self[0]); end; + function __Helper.zyzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[2], self[1]); end; + function __Helper.zyzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[2], self[2]); end; + function __Helper.zyzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[2], self[3]); end; + function __Helper.zywx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[3], self[0]); end; + function __Helper.zywy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[3], self[1]); end; + function __Helper.zywz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[3], self[2]); end; + function __Helper.zyww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[1], self[3], self[3]); end; + function __Helper.zzxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[0], self[0]); end; + function __Helper.zzxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[0], self[1]); end; + function __Helper.zzxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[0], self[2]); end; + function __Helper.zzxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[0], self[3]); end; + function __Helper.zzyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[1], self[0]); end; + function __Helper.zzyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[1], self[1]); end; + function __Helper.zzyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[1], self[2]); end; + function __Helper.zzyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[1], self[3]); end; + function __Helper.zzzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[2], self[0]); end; + function __Helper.zzzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[2], self[1]); end; + function __Helper.zzzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[2], self[2]); end; + function __Helper.zzzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[2], self[3]); end; + function __Helper.zzwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[3], self[0]); end; + function __Helper.zzwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[3], self[1]); end; + function __Helper.zzwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[3], self[2]); end; + function __Helper.zzww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[2], self[3], self[3]); end; + function __Helper.zwxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[0], self[0]); end; + function __Helper.zwxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[0], self[1]); end; + function __Helper.zwxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[0], self[2]); end; + function __Helper.zwxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[0], self[3]); end; + function __Helper.zwyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[1], self[0]); end; + function __Helper.zwyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[1], self[1]); end; + function __Helper.zwyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[1], self[2]); end; + function __Helper.zwyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[1], self[3]); end; + function __Helper.zwzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[2], self[0]); end; + function __Helper.zwzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[2], self[1]); end; + function __Helper.zwzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[2], self[2]); end; + function __Helper.zwzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[2], self[3]); end; + function __Helper.zwwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[3], self[0]); end; + function __Helper.zwwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[3], self[1]); end; + function __Helper.zwwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[3], self[2]); end; + function __Helper.zwww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[2], self[3], self[3], self[3]); end; + function __Helper.wxxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[0], self[0]); end; + function __Helper.wxxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[0], self[1]); end; + function __Helper.wxxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[0], self[2]); end; + function __Helper.wxxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[0], self[3]); end; + function __Helper.wxyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[1], self[0]); end; + function __Helper.wxyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[1], self[1]); end; + function __Helper.wxyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[1], self[2]); end; + function __Helper.wxyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[1], self[3]); end; + function __Helper.wxzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[2], self[0]); end; + function __Helper.wxzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[2], self[1]); end; + function __Helper.wxzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[2], self[2]); end; + function __Helper.wxzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[2], self[3]); end; + function __Helper.wxwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[3], self[0]); end; + function __Helper.wxwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[3], self[1]); end; + function __Helper.wxwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[3], self[2]); end; + function __Helper.wxww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[0], self[3], self[3]); end; + function __Helper.wyxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[0], self[0]); end; + function __Helper.wyxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[0], self[1]); end; + function __Helper.wyxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[0], self[2]); end; + function __Helper.wyxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[0], self[3]); end; + function __Helper.wyyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[1], self[0]); end; + function __Helper.wyyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[1], self[1]); end; + function __Helper.wyyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[1], self[2]); end; + function __Helper.wyyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[1], self[3]); end; + function __Helper.wyzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[2], self[0]); end; + function __Helper.wyzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[2], self[1]); end; + function __Helper.wyzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[2], self[2]); end; + function __Helper.wyzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[2], self[3]); end; + function __Helper.wywx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[3], self[0]); end; + function __Helper.wywy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[3], self[1]); end; + function __Helper.wywz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[3], self[2]); end; + function __Helper.wyww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[1], self[3], self[3]); end; + function __Helper.wzxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[0], self[0]); end; + function __Helper.wzxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[0], self[1]); end; + function __Helper.wzxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[0], self[2]); end; + function __Helper.wzxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[0], self[3]); end; + function __Helper.wzyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[1], self[0]); end; + function __Helper.wzyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[1], self[1]); end; + function __Helper.wzyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[1], self[2]); end; + function __Helper.wzyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[1], self[3]); end; + function __Helper.wzzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[2], self[0]); end; + function __Helper.wzzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[2], self[1]); end; + function __Helper.wzzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[2], self[2]); end; + function __Helper.wzzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[2], self[3]); end; + function __Helper.wzwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[3], self[0]); end; + function __Helper.wzwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[3], self[1]); end; + function __Helper.wzwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[3], self[2]); end; + function __Helper.wzww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[2], self[3], self[3]); end; + function __Helper.wwxx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[0], self[0]); end; + function __Helper.wwxy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[0], self[1]); end; + function __Helper.wwxz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[0], self[2]); end; + function __Helper.wwxw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[0], self[3]); end; + function __Helper.wwyx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[1], self[0]); end; + function __Helper.wwyy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[1], self[1]); end; + function __Helper.wwyz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[1], self[2]); end; + function __Helper.wwyw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[1], self[3]); end; + function __Helper.wwzx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[2], self[0]); end; + function __Helper.wwzy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[2], self[1]); end; + function __Helper.wwzz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[2], self[2]); end; + function __Helper.wwzw: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[2], self[3]); end; + function __Helper.wwwx: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[3], self[0]); end; + function __Helper.wwwy: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[3], self[1]); end; + function __Helper.wwwz: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[3], self[2]); end; + function __Helper.wwww: __IMPL.TVector4; begin result := __IMPL.Vector4(self[3], self[3], self[3], self[3]); end; + {$ENDIF} + + operator = (const v1, v2: __VEC): Boolean; + begin + result := __IMPL.Equals(v1, v2); + end; + {$IFDEF __HELPER_I} + function __HELPER_I.Length: Double; + begin + result := __IMPL.Length(self); + end; + + {$IF __SIZE <> 4} + function __HELPER_I.Add(const v: __VEC): __VEC; + begin + result := __IMPL.Add(self, v); + end; + + function __HELPER_I.Subtract(const v: __VEC): __VEC; + begin + result := __IMPL.Sub(self, v); + end; + {$ENDIF} + + function __HELPER_I.Multiply(const v: __IMPL.TBaseType): __VEC; + begin + result := __IMPL.Multiply(self, v); + end; + + {$IF __SIZE <> 4} + operator + (const v1, v2: __VEC): __VEC; + begin + result := __IMPL.Add(v1, v2); + end; + + operator - (const v1, v2: __VEC): __VEC; + begin + result := __IMPL.Sub(v1, v2); + end; + {$ENDIF} + {$IFDEF __HELPER_F} + function __HELPER_F.Normalize: __VEC; + begin + result := __IMPL.Normalize(self); + end; + + function __HELPER_F.Divide(const v: __IMPL.TBaseType): __VEC; + begin + result := __IMPL.Divide(self, v); + end; + + function __HELPER_F.Dot(const v: __VEC): __IMPL.TBaseType; + begin + result := __IMPL.Dot(self, v); + end; + + {$IF __SIZE <> 4} + function __HELPER_F.Angle(const v: __VEC): Double; + begin + result := __IMPL.Angle(self, v); + end; + {$ENDIF} + + {$IF __SIZE = 2} + function __HELPER_F.Angle2(const v: __VEC): Double; + begin + result := __IMPL.Angle2(self, v); + end; + {$ENDIF} + + function __HELPER_F.Clamp(const min, max: __VEC): __VEC; + begin + result := __IMPL.Clamp(self, min, max); + end; + + function __HELPER_F.Clamp(const min, max: __IMPL.TBaseType): __VEC; + begin + result := __IMPL.Clamp(self, min, max); + end; + + operator * (const v: __VEC; const s: __IMPL.TBaseType): __VEC; + begin + result := __IMPl.Multiply(v, s); + end; + + operator * (const s: __IMPL.TBaseType; const v: __VEC): __VEC; + begin + result := __IMPl.Multiply(v, s); + end; + + operator * (const v1, v2: __VEC): __IMPL.TBaseType; + begin + result := __IMPl.Dot(v1, v2); + end; + {$ENDIF} + {$ENDIF} + {$ENDIF} +{$ENDIF} + +{$UNDEF __IMPL} +{$UNDEF __SIZE} +{$UNDEF __VEC} +{$UNDEF __HELPER} +{$UNDEF __HELPER_I} +{$UNDEF __HELPER_F} diff --git a/ugluVectorEx.pas b/ugluVectorEx.pas new file mode 100644 index 0000000..fb6d582 --- /dev/null +++ b/ugluVectorEx.pas @@ -0,0 +1,409 @@ +unit ugluVectorEx; + +{$mode objfpc}{$H+} +{$macro on} +{$modeswitch typehelpers} + +interface + +uses + Classes, SysUtils, + ugluVectorExHelper; + +type + TgluVector2p = TgluVectorP.TVector2; + TgluVector3p = TgluVectorP.TVector3; + TgluVector4p = TgluVectorP.TVector4; + + TgluVector2e = TgluVectorE.TVector2; + TgluVector3e = TgluVectorE.TVector3; + TgluVector4e = TgluVectorE.TVector4; + + TgluVector2i = TgluVectorI.TVector2; + TgluVector3i = TgluVectorI.TVector3; + TgluVector4i = TgluVectorI.TVector4; + + TgluVector2us = TgluVectorUS.TVector2; + TgluVector3us = TgluVectorUS.TVector3; + TgluVector4us = TgluVectorUS.TVector4; + + TgluVector2ub = TgluVectorUB.TVector2; + TgluVector3ub = TgluVectorUB.TVector3; + TgluVector4ub = TgluVectorUB.TVector4; + + TgluVector2f = TgluVectorF.TVector2; + TgluVector3f = TgluVectorF.TVector3; + TgluVector4f = TgluVectorF.TVector4; + + TgluVector2d = TgluVectorD.TVector2; + TgluVector3d = TgluVectorD.TVector3; + TgluVector4d = TgluVectorD.TVector4; + +{$DEFINE __VECTOR_HELPER_INTERFACE} + { TgluVector2p } + {$DEFINE __IMPL := TgluVectorP} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2p} + {$DEFINE __HELPER := TgluTypeHelperVector2p} + {$I ugluVectorEx.inc} + + { TgluVector3p } + {$DEFINE __IMPL := TgluVectorP} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3p} + {$DEFINE __HELPER := TgluTypeHelperVector3p} + {$I ugluVectorEx.inc} + + { TgluVector4p } + {$DEFINE __IMPL := TgluVectorP} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4p} + {$DEFINE __HELPER := TgluTypeHelperVector4p} + {$I ugluVectorEx.inc} + + + + { TgluVector2e } + {$DEFINE __IMPL := TgluVectorE} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2e} + {$DEFINE __HELPER := TgluTypeHelperVector2e} + {$I ugluVectorEx.inc} + + { TgluVector3e } + {$DEFINE __IMPL := TgluVectorE} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3e} + {$DEFINE __HELPER := TgluTypeHelperVector3e} + {$I ugluVectorEx.inc} + + { TgluVector4e } + {$DEFINE __IMPL := TgluVectorE} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4e} + {$DEFINE __HELPER := TgluTypeHelperVector4e} + {$I ugluVectorEx.inc} + + + + { TgluVector2i } + {$DEFINE __IMPL := TgluVectorI} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2i} + {$DEFINE __HELPER := TgluTypeHelperVector2i} + {$DEFINE __HELPER_I := TgluTypeHelperVector2ii} + {$I ugluVectorEx.inc} + + { TgluVector3i } + {$DEFINE __IMPL := TgluVectorI} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3i} + {$DEFINE __HELPER := TgluTypeHelperVector3i} + {$DEFINE __HELPER_I := TgluTypeHelperVector3ii} + {$I ugluVectorEx.inc} + + { TgluVector4i } + {$DEFINE __IMPL := TgluVectorI} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4i} + {$DEFINE __HELPER := TgluTypeHelperVector4i} + {$DEFINE __HELPER_I := TgluTypeHelperVector4ii} + {$I ugluVectorEx.inc} + + + + { TgluVector2us } + {$DEFINE __IMPL := TgluVectorUS} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2us} + {$DEFINE __HELPER := TgluTypeHelperVector2us} + {$DEFINE __HELPER_I := TgluTypeHelperVector2usi} + {$I ugluVectorEx.inc} + + { TgluVector3us } + {$DEFINE __IMPL := TgluVectorUS} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3us} + {$DEFINE __HELPER := TgluTypeHelperVector3us} + {$DEFINE __HELPER_I := TgluTypeHelperVector3usi} + {$I ugluVectorEx.inc} + + { TgluVector4us } + {$DEFINE __IMPL := TgluVectorUS} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4us} + {$DEFINE __HELPER := TgluTypeHelperVector4us} + {$DEFINE __HELPER_I := TgluTypeHelperVector4usi} + {$I ugluVectorEx.inc} + + + + { TgluVector2ub } + {$DEFINE __IMPL := TgluVectorUB} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2ub} + {$DEFINE __HELPER := TgluTypeHelperVector2ub} + {$DEFINE __HELPER_I := TgluTypeHelperVector2ubi} + {$I ugluVectorEx.inc} + + { TgluVector3ub } + {$DEFINE __IMPL := TgluVectorUB} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3ub} + {$DEFINE __HELPER := TgluTypeHelperVector3ub} + {$DEFINE __HELPER_I := TgluTypeHelperVector3ubi} + {$I ugluVectorEx.inc} + + { TgluVector4ub } + {$DEFINE __IMPL := TgluVectorUB} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4ub} + {$DEFINE __HELPER := TgluTypeHelperVector4ub} + {$DEFINE __HELPER_I := TgluTypeHelperVector4ubi} + {$I ugluVectorEx.inc} + + + + { TgluVector2f } + {$DEFINE __IMPL := TgluVectorF} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2f} + {$DEFINE __HELPER := TgluTypeHelperVector2f} + {$DEFINE __HELPER_I := TgluTypeHelperVector2fi} + {$DEFINE __HELPER_F := TgluTypeHelperVector2ff} + {$I ugluVectorEx.inc} + + { TgluVector3f } + {$DEFINE __IMPL := TgluVectorF} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3f} + {$DEFINE __HELPER := TgluTypeHelperVector3f} + {$DEFINE __HELPER_I := TgluTypeHelperVector3fi} + {$DEFINE __HELPER_F := TgluTypeHelperVector3ff} + {$I ugluVectorEx.inc} + + { TgluVector4f } + {$DEFINE __IMPL := TgluVectorF} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4f} + {$DEFINE __HELPER := TgluTypeHelperVector4f} + {$DEFINE __HELPER_I := TgluTypeHelperVector4fi} + {$DEFINE __HELPER_F := TgluTypeHelperVector4ff} + {$I ugluVectorEx.inc} + + + + { TgluVector2d } + {$DEFINE __IMPL := TgluVectorD} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2d} + {$DEFINE __HELPER := TgluTypeHelperVector2d} + {$DEFINE __HELPER_I := TgluTypeHelperVector2di} + {$DEFINE __HELPER_F := TgluTypeHelperVector2df} + {$I ugluVectorEx.inc} + + { TgluVector3d } + {$DEFINE __IMPL := TgluVectorD} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3d} + {$DEFINE __HELPER := TgluTypeHelperVector3d} + {$DEFINE __HELPER_I := TgluTypeHelperVector3di} + {$DEFINE __HELPER_F := TgluTypeHelperVector3df} + {$I ugluVectorEx.inc} + + { TgluVector4d } + {$DEFINE __IMPL := TgluVectorD} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4d} + {$DEFINE __HELPER := TgluTypeHelperVector4d} + {$DEFINE __HELPER_I := TgluTypeHelperVector4di} + {$DEFINE __HELPER_F := TgluTypeHelperVector4df} + {$I ugluVectorEx.inc} +{$UNDEF __VECTOR_HELPER_INTERFACE} + +implementation + +{$DEFINE __VECTOR_HELPER_IMPL} + { TgluVector2p } + {$DEFINE __IMPL := TgluVectorP} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2p} + {$DEFINE __HELPER := TgluTypeHelperVector2p} + {$I ugluVectorEx.inc} + + { TgluVector3p } + {$DEFINE __IMPL := TgluVectorP} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3p} + {$DEFINE __HELPER := TgluTypeHelperVector3p} + {$I ugluVectorEx.inc} + + { TgluVector4p } + {$DEFINE __IMPL := TgluVectorP} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4p} + {$DEFINE __HELPER := TgluTypeHelperVector4p} + {$I ugluVectorEx.inc} + + + + { TgluVector2e } + {$DEFINE __IMPL := TgluVectorE} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2e} + {$DEFINE __HELPER := TgluTypeHelperVector2e} + {$I ugluVectorEx.inc} + + { TgluVector3e } + {$DEFINE __IMPL := TgluVectorE} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3e} + {$DEFINE __HELPER := TgluTypeHelperVector3e} + {$I ugluVectorEx.inc} + + { TgluVector4e } + {$DEFINE __IMPL := TgluVectorE} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4e} + {$DEFINE __HELPER := TgluTypeHelperVector4e} + {$I ugluVectorEx.inc} + + + + { TgluVector2i } + {$DEFINE __IMPL := TgluVectorI} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2i} + {$DEFINE __HELPER := TgluTypeHelperVector2i} + {$DEFINE __HELPER_I := TgluTypeHelperVector2ii} + {$I ugluVectorEx.inc} + + { TgluVector3i } + {$DEFINE __IMPL := TgluVectorI} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3i} + {$DEFINE __HELPER := TgluTypeHelperVector3i} + {$DEFINE __HELPER_I := TgluTypeHelperVector3ii} + {$I ugluVectorEx.inc} + + { TgluVector4i } + {$DEFINE __IMPL := TgluVectorI} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4i} + {$DEFINE __HELPER := TgluTypeHelperVector4i} + {$DEFINE __HELPER_I := TgluTypeHelperVector4ii} + {$I ugluVectorEx.inc} + + + + { TgluVector2us } + {$DEFINE __IMPL := TgluVectorUS} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2us} + {$DEFINE __HELPER := TgluTypeHelperVector2us} + {$DEFINE __HELPER_I := TgluTypeHelperVector2usi} + {$I ugluVectorEx.inc} + + { TgluVector3us } + {$DEFINE __IMPL := TgluVectorUS} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3us} + {$DEFINE __HELPER := TgluTypeHelperVector3us} + {$DEFINE __HELPER_I := TgluTypeHelperVector3usi} + {$I ugluVectorEx.inc} + + { TgluVector4us } + {$DEFINE __IMPL := TgluVectorUS} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4us} + {$DEFINE __HELPER := TgluTypeHelperVector4us} + {$DEFINE __HELPER_I := TgluTypeHelperVector4usi} + {$I ugluVectorEx.inc} + + + + { TgluVector2ub } + {$DEFINE __IMPL := TgluVectorUB} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2ub} + {$DEFINE __HELPER := TgluTypeHelperVector2ub} + {$DEFINE __HELPER_I := TgluTypeHelperVector2ubi} + {$I ugluVectorEx.inc} + + { TgluVector3ub } + {$DEFINE __IMPL := TgluVectorUB} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3ub} + {$DEFINE __HELPER := TgluTypeHelperVector3ub} + {$DEFINE __HELPER_I := TgluTypeHelperVector3ubi} + {$I ugluVectorEx.inc} + + { TgluVector4ub } + {$DEFINE __IMPL := TgluVectorUB} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4ub} + {$DEFINE __HELPER := TgluTypeHelperVector4ub} + {$DEFINE __HELPER_I := TgluTypeHelperVector4ubi} + {$I ugluVectorEx.inc} + + + + { TgluVector2f } + {$DEFINE __IMPL := TgluVectorF} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2f} + {$DEFINE __HELPER := TgluTypeHelperVector2f} + {$DEFINE __HELPER_I := TgluTypeHelperVector2fi} + {$DEFINE __HELPER_F := TgluTypeHelperVector2ff} + {$I ugluVectorEx.inc} + + { TgluVector3f } + {$DEFINE __IMPL := TgluVectorF} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3f} + {$DEFINE __HELPER := TgluTypeHelperVector3f} + {$DEFINE __HELPER_I := TgluTypeHelperVector3fi} + {$DEFINE __HELPER_F := TgluTypeHelperVector3ff} + {$I ugluVectorEx.inc} + + { TgluVector4ub } + {$DEFINE __IMPL := TgluVectorF} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4f} + {$DEFINE __HELPER := TgluTypeHelperVector4f} + {$DEFINE __HELPER_I := TgluTypeHelperVector4fi} + {$DEFINE __HELPER_F := TgluTypeHelperVector4ff} + {$I ugluVectorEx.inc} + + + + { TgluVector2d } + {$DEFINE __IMPL := TgluVectorD} + {$DEFINE __SIZE := 2} + {$DEFINE __VEC := TgluVector2d} + {$DEFINE __HELPER := TgluTypeHelperVector2d} + {$DEFINE __HELPER_I := TgluTypeHelperVector2di} + {$DEFINE __HELPER_F := TgluTypeHelperVector2df} + {$I ugluVectorEx.inc} + + { TgluVector3d } + {$DEFINE __IMPL := TgluVectorD} + {$DEFINE __SIZE := 3} + {$DEFINE __VEC := TgluVector3d} + {$DEFINE __HELPER := TgluTypeHelperVector3d} + {$DEFINE __HELPER_I := TgluTypeHelperVector3di} + {$DEFINE __HELPER_F := TgluTypeHelperVector3df} + {$I ugluVectorEx.inc} + + { TgluVector4d } + {$DEFINE __IMPL := TgluVectorD} + {$DEFINE __SIZE := 4} + {$DEFINE __VEC := TgluVector4d} + {$DEFINE __HELPER := TgluTypeHelperVector4d} + {$DEFINE __HELPER_I := TgluTypeHelperVector4di} + {$DEFINE __HELPER_F := TgluTypeHelperVector4df} + {$I ugluVectorEx.inc} +{$UNDEF __VECTOR_HELPER_IMPL} + +end. + diff --git a/ugluVectorExHelper.pas b/ugluVectorExHelper.pas new file mode 100644 index 0000000..d20b92e --- /dev/null +++ b/ugluVectorExHelper.pas @@ -0,0 +1,577 @@ +unit ugluVectorExHelper; + +{$mode objfpc}{$H+} +{$modeswitch typehelpers} + +interface + +uses + Classes, SysUtils; + +type + generic TgluVectorHelper = class + public type + TBaseType = T; + PBaseType = ^TBaseType; + + TVector2 = array[0..1] of T; + TVector3 = array[0..2] of T; + TVector4 = array[0..3] of T; + + PVector2 = ^TVector2; + PVector3 = ^TVector3; + PVector4 = ^TVector4; + + public + class function Vector2(const x, y: T): TVector2; overload; inline; + class function Vector3(const x, y, z: T): TVector3; overload; inline; + class function Vector4(const x, y, z, w: T): TVector4; overload; inline; + + class function Equals(const v1: TVector2; const v2: TVector2): Boolean; overload; inline; + class function Equals(const v1: TVector3; const v2: TVector3): Boolean; overload; inline; + class function Equals(const v1: TVector4; const v2: TVector4): Boolean; overload; inline; + + class function ToString(const v: TVector2; const aRound: Integer = -3): String; overload; + class function ToString(const v: TVector3; const aRound: Integer = -3): String; overload; + class function ToString(const v: TVector4; const aRound: Integer = -3): String; overload; + + class function TryFromString(const s: String; out v: TVector2): Boolean; overload; inline; + class function TryFromString(const s: String; out v: TVector3): Boolean; overload; inline; + class function TryFromString(const s: String; out v: TVector4): Boolean; overload; inline; + + private + class function TryFromString(const s: String; p: PBaseType; aCount: Integer): Boolean; + end; + + generic TgluVectorHelperI = class(specialize TgluVectorHelper) + public + class function Length(const v: TVector2): Double; overload; inline; + class function Length(const v: TVector3): Double; overload; inline; + class function Length(const v: TVector4): Double; overload; inline; + + class function Multiply(const v: TVector2; const a: T): TVector2; overload; inline; + class function Multiply(const v: TVector3; const a: T): TVector3; overload; inline; + class function Multiply(const v: TVector4; const a: T): TVector4; overload; inline; + + class function Add(const v1, v2: TVector2): TVector2; overload; inline; + class function Add(const v1, v2: TVector3): TVector3; overload; inline; + + class function Sub(const v1, v2: TVector2): TVector2; overload; inline; + class function Sub(const v1, v2: TVector3): TVector3; overload; inline; + end; + + generic TgluVectorHelperF = class(specialize TgluVectorHelperI) + public + class function Normalize(const v: TVector2): TVector2; overload; inline; + class function Normalize(const v: TVector3): TVector3; overload; inline; + class function Normalize(const v: TVector4): TVector4; overload; inline; + + class function Divide(const v: TVector2; const a: T): TVector2; overload; inline; + class function Divide(const v: TVector3; const a: T): TVector3; overload; inline; + class function Divide(const v: TVector4; const a: T): TVector4; overload; inline; + + class function Dot(const v1: TVector2; const v2: TVector2): T; overload; inline; + class function Dot(const v1: TVector3; const v2: TVector3): T; overload; inline; + class function Dot(const v1: TVector4; const v2: TVector4): T; overload; inline; + + class function Cross(const v1: TVector3; const v2: TVector3): TVector3; overload; inline; + + class function Angle(const v1: TVector2; const v2: TVector2): Double; overload; inline; + class function Angle(const v1: TVector3; const v2: TVector3): Double; overload; inline; + class function Angle2(const v1: TVector2; const v2: TVector2): Double; overload; inline; + + class function ClampVal(const v, aMin, aMax: T): T; overload; inline; + class function Clamp(const v, aMin, aMax: TVector2): TVector2; overload; inline; + class function Clamp(const v, aMin, aMax: TVector3): TVector3; overload; inline; + class function Clamp(const v, aMin, aMax: TVector4): TVector4; overload; inline; + class function Clamp(const v: TVector2; const aMin, aMax: T): TVector2; overload; inline; + class function Clamp(const v: TVector3; const aMin, aMax: T): TVector3; overload; inline; + class function Clamp(const v: TVector4; const aMin, aMax: T): TVector4; overload; inline; + end; + + TgluVectorP = specialize TgluVectorHelper; + TgluVectorE = specialize TgluVectorHelper; + + TgluVectorI = specialize TgluVectorHelperI; + TgluVectorUS = specialize TgluVectorHelperI; + TgluVectorUB = specialize TgluVectorHelperI; + + TgluVectorF = specialize TgluVectorHelperF; + TgluVectorD = specialize TgluVectorHelperF; + +implementation + +uses + Math; + +type + TPointerTypeHelper = type helper for Pointer + function ToString(const aRound: Integer = -3): String; + class function TryFromString(s: String; out v: Pointer): Boolean; static; + end; + + TCardinalTypeHelper = type helper for Cardinal + function ToString(const aRound: Integer = -3): String; + class function TryFromString(s: String; out v: Cardinal): Boolean; static; + end; + + TIntegerTypeHelper = type helper for Integer + function ToString(const aRound: Integer = -3): String; + class function TryFromString(s: String; out v: Integer): Boolean; static; + end; + + TWordTypeHelper = type helper for Word + function ToString(const aRound: Integer = -3): String; + class function TryFromString(s: String; out v: Word): Boolean; static; + end; + + TByteTypeHelper = type helper for Byte + function ToString(const aRound: Integer = -3): String; + class function TryFromString(s: String; out v: Byte): Boolean; static; + end; + + TSingleTypeHelper = type helper for Single + function ToString(const aRound: Integer = -3): String; + class function TryFromString(s: String; out v: Single): Boolean; static; + end; + + TDoubleTypeHelper = type helper for Double + function ToString(const aRound: Integer = -3): String; + class function TryFromString(s: String; out v: Double): Boolean; static; + end; + +function IntToStrRounded(i: Int64; const aRound: Integer): String; +var p: Cardinal; +begin + if (aRound > 0) then begin + p := Round(power(10, aRound)); + i := i div p; + i := i * p; + end; + result := IntToStr(i); +end; + +function FloatToStrRounded(f: Extended; const aRound: Integer): String; +var p: Cardinal; fmt: TFormatSettings; +begin + if (aRound > 0) then begin + p := Round(power(10, aRound)); + f := Round(f / p) * p; + end; + fmt.DecimalSeparator := '.'; + result := Format('%.*f', [Max(0, -aRound), f], fmt); +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TPointerTypeHelper//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TPointerTypeHelper.ToString(const aRound: Integer): String; +begin + result := '0x' + IntToHex({%H-}PtrUInt(self), 2 * SizeOf(Pointer)); +end; + +class function TPointerTypeHelper.TryFromString(s: String; out v: Pointer): Boolean; +var + i: Int64; +begin + s := StringReplace(s, '0x', '$', [rfReplaceAll, rfIgnoreCase]); + result := TryStrToInt64(s, i); + if result + then v := {%H-}Pointer(PtrUInt(i)) + else v := nil; +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TCardinalTypeHelper/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TCardinalTypeHelper.ToString(const aRound: Integer): String; +begin + result := IntToStrRounded(self, aRound); +end; + +class function TCardinalTypeHelper.TryFromString(s: String; out v: Cardinal): Boolean; +var i: LongInt; +begin + result := TryStrToInt(s, i); + if result + then v := i + else v := 0; +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TIntegerTypeHelper//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TIntegerTypeHelper.ToString(const aRound: Integer): String; +begin + result := IntToStrRounded(self, aRound); +end; + +class function TIntegerTypeHelper.TryFromString(s: String; out v: Integer): Boolean; +begin + result := TryStrToInt(s, v); +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TWordTypeHelper/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TWordTypeHelper.ToString(const aRound: Integer): String; +begin + result := IntToStrRounded(self, aRound); +end; + +class function TWordTypeHelper.TryFromString(s: String; out v: Word): Boolean; +var i: LongInt; +begin + result := TryStrToInt(s, i); + if result + then v := i + else v := 0; +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TByteTypeHelper/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TByteTypeHelper.ToString(const aRound: Integer): String; +begin + result := IntToStrRounded(self, aRound); +end; + +class function TByteTypeHelper.TryFromString(s: String; out v: Byte): Boolean; +var i: LongInt; +begin + result := TryStrToInt(s, i); + if result + then v := i + else v := 0; +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TSingleTypeHelper///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TSingleTypeHelper.ToString(const aRound: Integer): String; +begin + result := FloatToStrRounded(self, aRound); +end; + +class function TSingleTypeHelper.TryFromString(s: String; out v: Single): Boolean; +var f: TFormatSettings; +begin + f.DecimalSeparator := '.'; + result := TryStrToFloat(s, v, f); +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TDoubleTypeHelper///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TDoubleTypeHelper.ToString(const aRound: Integer): String; +begin + result := FloatToStrRounded(self, aRound); +end; + +class function TDoubleTypeHelper.TryFromString(s: String; out v: Double): Boolean; +var f: TFormatSettings; +begin + f.DecimalSeparator := '.'; + result := TryStrToFloat(s, v, f); +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TgluVectorHelper////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class function TgluVectorHelper.Vector2(const x, y: T): TVector2; +begin + result[0] := x; + result[1] := y; +end; + +class function TgluVectorHelper.Vector3(const x, y, z: T): TVector3; +begin + result[0] := x; + result[1] := y; + result[2] := z; +end; + +class function TgluVectorHelper.Vector4(const x, y, z, w: T): TVector4; +begin + result[0] := x; + result[1] := y; + result[2] := z; + result[3] := w; +end; + +class function TgluVectorHelper.Equals(const v1: TVector2; const v2: TVector2): Boolean; +begin + result := (v1[0] = v2[0]) and (v1[1] = v2[1]); +end; + +class function TgluVectorHelper.Equals(const v1: TVector3; const v2: TVector3): Boolean; +begin + result := Equals(PVector2(@v1[0])^, PVector2(@v2[0])^) and (v1[2] = v2[2]); +end; + +class function TgluVectorHelper.Equals(const v1: TVector4; const v2: TVector4): Boolean; +begin + result := Equals(PVector3(@v1[0])^, PVector3(@v2[0])^) and (v1[3] = v2[3]); +end; + +class function TgluVectorHelper.ToString(const v: TVector2; const aRound: Integer): String; +begin + result := v[0].ToString(aRound) + '; ' + v[1].ToString(aRound); +end; + +class function TgluVectorHelper.ToString(const v: TVector3; const aRound: Integer): String; +begin + result := v[0].ToString(aRound) + '; ' + v[1].ToString(aRound) + '; ' + v[2].ToString(aRound); +end; + +class function TgluVectorHelper.ToString(const v: TVector4; const aRound: Integer): String; +begin + result := v[0].ToString(aRound) + '; ' + v[1].ToString(aRound) + '; ' + v[2].ToString(aRound) + '; ' + v[3].ToString(aRound); +end; + +class function TgluVectorHelper.TryFromString(const s: String; out v: TVector2): Boolean; +begin + result := TryFromString(s, @v[0], 2); +end; + +class function TgluVectorHelper.TryFromString(const s: String; out v: TVector3): Boolean; +begin + result := TryFromString(s, @v[0], 3); +end; + +class function TgluVectorHelper.TryFromString(const s: String; out v: TVector4): Boolean; +begin + result := TryFromString(s, @v[0], 4); +end; + +class function TgluVectorHelper.TryFromString(const s: String; p: PBaseType; aCount: Integer): Boolean; +var + i, j, l: Integer; +begin + result := true; + i := 1; + j := 1; + l := Length(s); + while ({%H-}i <= {%H-}l) and (aCount > 0) and result {%H-}do begin + if (s[i] = ';') then begin + result := TBaseType.TryFromString(Trim(copy(s, j, i-{%H-}j)), p^); + j := i+1; + inc(p); + dec(aCount); + end; + inc(i); + end; + + while (aCount > 0) do begin + p^ := TBaseType(0); + inc(p); + dec(aCount); + end; +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TgluVectorHelperI///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class function TgluVectorHelperI.Length(const v: TVector2): Double; +begin + result := SQRT(v[0]*v[0] + v[1]*v[1]); +end; + +class function TgluVectorHelperI.Length(const v: TVector3): Double; +begin + result := SQRT(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); +end; + +class function TgluVectorHelperI.Length(const v: TVector4): Double; +begin + result := SQRT(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]) * v[3]; +end; + +class function TgluVectorHelperI.Multiply(const v: TVector2; const a: T): TVector2; +begin + result[0] := v[0] * a; + result[1] := v[1] * a; +end; + +class function TgluVectorHelperI.Multiply(const v: TVector3; const a: T): TVector3; +begin + result[0] := v[0] * a; + result[1] := v[1] * a; + result[2] := v[2] * a; +end; + +class function TgluVectorHelperI.Multiply(const v: TVector4; const a: T): TVector4; +begin + result[0] := v[0] * a; + result[1] := v[1] * a; + result[2] := v[2] * a; + result[3] := v[3] * a; +end; + +class function TgluVectorHelperI.Add(const v1, v2: TVector2): TVector2; +begin + result[0] := v1[0] + v2[0]; + result[1] := v1[1] + v2[1]; +end; + +class function TgluVectorHelperI.Add(const v1, v2: TVector3): TVector3; +begin + result[0] := v1[0] + v2[0]; + result[1] := v1[1] + v2[1]; + result[2] := v1[2] + v2[2]; +end; + +class function TgluVectorHelperI.Sub(const v1, v2: TVector2): TVector2; +begin + result[0] := v1[0] - v2[0]; + result[1] := v1[1] - v2[1]; +end; + +class function TgluVectorHelperI.Sub(const v1, v2: TVector3): TVector3; +begin + result[0] := v1[0] - v2[0]; + result[1] := v1[1] - v2[1]; + result[2] := v1[2] - v2[2]; +end; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TgluVectorHelperF///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class function TgluVectorHelperF.Normalize(const v: TVector2): TVector2; +var l: Double; +begin + l := Length(v); + result[0] := v[0] / l; + result[1] := v[1] / l; +end; + +class function TgluVectorHelperF.Normalize(const v: TVector3): TVector3; +var l: Double; +begin + l := Length(v); + result[0] := v[0] / l; + result[1] := v[1] / l; + result[2] := v[2] / l; +end; + +class function TgluVectorHelperF.Normalize(const v: TVector4): TVector4; +begin + result := v; + if (result[3] <> 0) then + result := Divide(v, v[3]); + PVector3(@result[0])^ := Normalize(PVector3(@result[0])^); +end; + +class function TgluVectorHelperF.Divide(const v: TVector2; const a: T): TVector2; +begin + result[0] := v[0] / a; + result[1] := v[1] / a; +end; + +class function TgluVectorHelperF.Divide(const v: TVector3; const a: T): TVector3; +begin + result[0] := v[0] / a; + result[1] := v[1] / a; + result[2] := v[2] / a; +end; + +class function TgluVectorHelperF.Divide(const v: TVector4; const a: T): TVector4; +begin + result[0] := v[0] / a; + result[1] := v[1] / a; + result[2] := v[2] / a; + result[3] := v[3] / a; +end; + +class function TgluVectorHelperF.Dot(const v1: TVector2; const v2: TVector2): T; +begin + result := v1[0] * v2[0] + v1[1] * v2[1]; +end; + +class function TgluVectorHelperF.Dot(const v1: TVector3; const v2: TVector3): T; +begin + result := v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; +end; + +class function TgluVectorHelperF.Dot(const v1: TVector4; const v2: TVector4): T; +begin + result := v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2] + v1[3] * v2[3]; +end; + +class function TgluVectorHelperF.Cross(const v1: TVector3; const v2: TVector3): TVector3; +begin + result[0] := v1[1] * v2[2] - v1[2] * v2[1]; + result[1] := v1[2] * v2[0] - v1[0] * v2[2]; + result[2] := v1[0] * v2[1] - v1[1] * v2[0]; +end; + +class function TgluVectorHelperF.Angle(const v1: TVector2; const v2: TVector2): Double; +begin + result := ArcCos(Dot(v1, v2) / (Length(v1) * Length(v2))); +end; + +class function TgluVectorHelperF.Angle(const v1: TVector3; const v2: TVector3): Double; +begin + result := ArcCos(Dot(v1, v2) / (Length(v1) * Length(v2))); +end; + +class function TgluVectorHelperF.Angle2(const v1: TVector2; const v2: TVector2): Double; +begin + result := arctan2( + v2[0] * v1[1] - v2[1] * v1[0], + v2[0] * v1[0] + v2[1] * v1[1]); +end; + +class function TgluVectorHelperF.ClampVal(const v, aMin, aMax: T): T; +begin + if (v < aMin) then + result := aMin + else if (v > aMax) then + result := aMax + else + result := v; +end; + +class function TgluVectorHelperF.Clamp(const v, aMin, aMax: TVector2): TVector2; +begin + result[0] := ClampVal(v[0], aMin[0], aMax[0]); + result[1] := ClampVal(v[1], aMin[1], aMax[1]); +end; + +class function TgluVectorHelperF.Clamp(const v, aMin, aMax: TVector3): TVector3; +begin + result[0] := ClampVal(v[0], aMin[0], aMax[0]); + result[1] := ClampVal(v[1], aMin[1], aMax[1]); + result[2] := ClampVal(v[2], aMin[2], aMax[2]); +end; + +class function TgluVectorHelperF.Clamp(const v, aMin, aMax: TVector4): TVector4; +begin + result[0] := ClampVal(v[0], aMin[0], aMax[0]); + result[1] := ClampVal(v[1], aMin[1], aMax[1]); + result[2] := ClampVal(v[2], aMin[2], aMax[2]); + result[3] := ClampVal(v[3], aMin[3], aMax[3]); +end; + +class function TgluVectorHelperF.Clamp(const v: TVector2; const aMin, aMax: T): TVector2; +begin + result[0] := ClampVal(v[0], aMin, aMax); + result[1] := ClampVal(v[1], aMin, aMax); +end; + +class function TgluVectorHelperF.Clamp(const v: TVector3; const aMin, aMax: T): TVector3; +begin + result[0] := ClampVal(v[0], aMin, aMax); + result[1] := ClampVal(v[1], aMin, aMax); + result[2] := ClampVal(v[2], aMin, aMax); +end; + +class function TgluVectorHelperF.Clamp(const v: TVector4; const aMin, aMax: T): TVector4; +begin + result[0] := ClampVal(v[0], aMin, aMax); + result[1] := ClampVal(v[1], aMin, aMax); + result[2] := ClampVal(v[2], aMin, aMax); +end; + +end. +