|
|
|
@ -10,7 +10,6 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
Invalid, |
|
|
|
Boolean, |
|
|
|
Scalar, |
|
|
|
Double, |
|
|
|
Vector2, |
|
|
|
Vector3, |
|
|
|
@ -33,7 +32,6 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
[FieldOffset(0)] public VariantType Type; |
|
|
|
|
|
|
|
[FieldOffset(4)] public bool Boolean; |
|
|
|
[FieldOffset(4)] public float Scalar; |
|
|
|
[FieldOffset(4)] public double Double; |
|
|
|
[FieldOffset(4)] public Vector2 Vector2; |
|
|
|
[FieldOffset(4)] public Vector3 Vector3; |
|
|
|
@ -45,191 +43,194 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
[FieldOffset(4)] public Matrix4x4 Matrix4x4; |
|
|
|
[FieldOffset(4)] public Quaternion Quaternion; |
|
|
|
[FieldOffset(4)] public Color Color; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ExpressionVariant GetProperty(string property) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector2) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
if (IsMatch(property, "X")) |
|
|
|
return Vector2.X; |
|
|
|
if (ReferenceEquals(property, "Y")) |
|
|
|
if (IsMatch(property, "Y")) |
|
|
|
return Vector2.Y; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Vector) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
if (IsMatch(property, "X")) |
|
|
|
return Vector.X; |
|
|
|
if (ReferenceEquals(property, "Y")) |
|
|
|
if (IsMatch(property, "Y")) |
|
|
|
return Vector.Y; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Vector3) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
if (IsMatch(property, "X")) |
|
|
|
return Vector3.X; |
|
|
|
if (ReferenceEquals(property, "Y")) |
|
|
|
if (IsMatch(property, "Y")) |
|
|
|
return Vector3.Y; |
|
|
|
if (ReferenceEquals(property, "Z")) |
|
|
|
if (IsMatch(property, "Z")) |
|
|
|
return Vector3.Z; |
|
|
|
if(ReferenceEquals(property, "XY")) |
|
|
|
if (IsMatch(property, "XY")) |
|
|
|
return new Vector2(Vector3.X, Vector3.Y); |
|
|
|
if(ReferenceEquals(property, "YX")) |
|
|
|
if (IsMatch(property, "YX")) |
|
|
|
return new Vector2(Vector3.Y, Vector3.X); |
|
|
|
if(ReferenceEquals(property, "XZ")) |
|
|
|
if (IsMatch(property, "XZ")) |
|
|
|
return new Vector2(Vector3.X, Vector3.Z); |
|
|
|
if(ReferenceEquals(property, "ZX")) |
|
|
|
if (IsMatch(property, "ZX")) |
|
|
|
return new Vector2(Vector3.Z, Vector3.X); |
|
|
|
if(ReferenceEquals(property, "YZ")) |
|
|
|
if (IsMatch(property, "YZ")) |
|
|
|
return new Vector2(Vector3.Y, Vector3.Z); |
|
|
|
if(ReferenceEquals(property, "ZY")) |
|
|
|
if (IsMatch(property, "ZY")) |
|
|
|
return new Vector2(Vector3.Z, Vector3.Y); |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Vector3D) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
if (IsMatch(property, "X")) |
|
|
|
return Vector3D.X; |
|
|
|
if (ReferenceEquals(property, "Y")) |
|
|
|
if (IsMatch(property, "Y")) |
|
|
|
return Vector3D.Y; |
|
|
|
if (ReferenceEquals(property, "Z")) |
|
|
|
if (IsMatch(property, "Z")) |
|
|
|
return Vector3D.Z; |
|
|
|
if(ReferenceEquals(property, "XY")) |
|
|
|
if (IsMatch(property, "XY")) |
|
|
|
return new Vector(Vector3D.X, Vector3D.Y); |
|
|
|
if(ReferenceEquals(property, "YX")) |
|
|
|
if (IsMatch(property, "YX")) |
|
|
|
return new Vector(Vector3D.Y, Vector3D.X); |
|
|
|
if(ReferenceEquals(property, "XZ")) |
|
|
|
if (IsMatch(property, "XZ")) |
|
|
|
return new Vector(Vector3D.X, Vector3D.Z); |
|
|
|
if(ReferenceEquals(property, "ZX")) |
|
|
|
if (IsMatch(property, "ZX")) |
|
|
|
return new Vector(Vector3D.Z, Vector3D.X); |
|
|
|
if(ReferenceEquals(property, "YZ")) |
|
|
|
if (IsMatch(property, "YZ")) |
|
|
|
return new Vector(Vector3D.Y, Vector3D.Z); |
|
|
|
if(ReferenceEquals(property, "ZY")) |
|
|
|
if (IsMatch(property, "ZY")) |
|
|
|
return new Vector(Vector3D.Z, Vector3D.Y); |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Vector4) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
if (IsMatch(property, "X")) |
|
|
|
return Vector4.X; |
|
|
|
if (ReferenceEquals(property, "Y")) |
|
|
|
if (IsMatch(property, "Y")) |
|
|
|
return Vector4.Y; |
|
|
|
if (ReferenceEquals(property, "Z")) |
|
|
|
if (IsMatch(property, "Z")) |
|
|
|
return Vector4.Z; |
|
|
|
if (ReferenceEquals(property, "W")) |
|
|
|
if (IsMatch(property, "W")) |
|
|
|
return Vector4.W; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Matrix3x2) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "M11")) |
|
|
|
if (IsMatch(property, "M11")) |
|
|
|
return Matrix3x2.M11; |
|
|
|
if (ReferenceEquals(property, "M12")) |
|
|
|
if (IsMatch(property, "M12")) |
|
|
|
return Matrix3x2.M12; |
|
|
|
if (ReferenceEquals(property, "M21")) |
|
|
|
if (IsMatch(property, "M21")) |
|
|
|
return Matrix3x2.M21; |
|
|
|
if (ReferenceEquals(property, "M22")) |
|
|
|
if (IsMatch(property, "M22")) |
|
|
|
return Matrix3x2.M22; |
|
|
|
if (ReferenceEquals(property, "M31")) |
|
|
|
if (IsMatch(property, "M31")) |
|
|
|
return Matrix3x2.M31; |
|
|
|
if (ReferenceEquals(property, "M32")) |
|
|
|
if (IsMatch(property, "M32")) |
|
|
|
return Matrix3x2.M32; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.AvaloniaMatrix) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "M11")) |
|
|
|
if (IsMatch(property, "M11")) |
|
|
|
return AvaloniaMatrix.M11; |
|
|
|
if (ReferenceEquals(property, "M12")) |
|
|
|
if (IsMatch(property, "M12")) |
|
|
|
return AvaloniaMatrix.M12; |
|
|
|
if (ReferenceEquals(property, "M13")) |
|
|
|
if (IsMatch(property, "M13")) |
|
|
|
return AvaloniaMatrix.M13; |
|
|
|
if (ReferenceEquals(property, "M21")) |
|
|
|
if (IsMatch(property, "M21")) |
|
|
|
return AvaloniaMatrix.M21; |
|
|
|
if (ReferenceEquals(property, "M22")) |
|
|
|
if (IsMatch(property, "M22")) |
|
|
|
return AvaloniaMatrix.M22; |
|
|
|
if (ReferenceEquals(property, "M23")) |
|
|
|
if (IsMatch(property, "M23")) |
|
|
|
return AvaloniaMatrix.M23; |
|
|
|
if (ReferenceEquals(property, "M31")) |
|
|
|
if (IsMatch(property, "M31")) |
|
|
|
return AvaloniaMatrix.M31; |
|
|
|
if (ReferenceEquals(property, "M32")) |
|
|
|
if (IsMatch(property, "M32")) |
|
|
|
return AvaloniaMatrix.M32; |
|
|
|
if (ReferenceEquals(property, "M33")) |
|
|
|
if (IsMatch(property, "M33")) |
|
|
|
return AvaloniaMatrix.M33; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Matrix4x4) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "M11")) |
|
|
|
if (IsMatch(property, "M11")) |
|
|
|
return Matrix4x4.M11; |
|
|
|
if (ReferenceEquals(property, "M12")) |
|
|
|
if (IsMatch(property, "M12")) |
|
|
|
return Matrix4x4.M12; |
|
|
|
if (ReferenceEquals(property, "M13")) |
|
|
|
if (IsMatch(property, "M13")) |
|
|
|
return Matrix4x4.M13; |
|
|
|
if (ReferenceEquals(property, "M14")) |
|
|
|
if (IsMatch(property, "M14")) |
|
|
|
return Matrix4x4.M14; |
|
|
|
if (ReferenceEquals(property, "M21")) |
|
|
|
if (IsMatch(property, "M21")) |
|
|
|
return Matrix4x4.M21; |
|
|
|
if (ReferenceEquals(property, "M22")) |
|
|
|
if (IsMatch(property, "M22")) |
|
|
|
return Matrix4x4.M22; |
|
|
|
if (ReferenceEquals(property, "M23")) |
|
|
|
if (IsMatch(property, "M23")) |
|
|
|
return Matrix4x4.M23; |
|
|
|
if (ReferenceEquals(property, "M24")) |
|
|
|
if (IsMatch(property, "M24")) |
|
|
|
return Matrix4x4.M24; |
|
|
|
if (ReferenceEquals(property, "M31")) |
|
|
|
if (IsMatch(property, "M31")) |
|
|
|
return Matrix4x4.M31; |
|
|
|
if (ReferenceEquals(property, "M32")) |
|
|
|
if (IsMatch(property, "M32")) |
|
|
|
return Matrix4x4.M32; |
|
|
|
if (ReferenceEquals(property, "M33")) |
|
|
|
if (IsMatch(property, "M33")) |
|
|
|
return Matrix4x4.M33; |
|
|
|
if (ReferenceEquals(property, "M34")) |
|
|
|
if (IsMatch(property, "M34")) |
|
|
|
return Matrix4x4.M34; |
|
|
|
if (ReferenceEquals(property, "M41")) |
|
|
|
if (IsMatch(property, "M41")) |
|
|
|
return Matrix4x4.M41; |
|
|
|
if (ReferenceEquals(property, "M42")) |
|
|
|
if (IsMatch(property, "M42")) |
|
|
|
return Matrix4x4.M42; |
|
|
|
if (ReferenceEquals(property, "M43")) |
|
|
|
if (IsMatch(property, "M43")) |
|
|
|
return Matrix4x4.M43; |
|
|
|
if (ReferenceEquals(property, "M44")) |
|
|
|
if (IsMatch(property, "M44")) |
|
|
|
return Matrix4x4.M44; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Quaternion) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
if (IsMatch(property, "X")) |
|
|
|
return Quaternion.X; |
|
|
|
if (ReferenceEquals(property, "Y")) |
|
|
|
if (IsMatch(property, "Y")) |
|
|
|
return Quaternion.Y; |
|
|
|
if (ReferenceEquals(property, "Z")) |
|
|
|
if (IsMatch(property, "Z")) |
|
|
|
return Quaternion.Z; |
|
|
|
if (ReferenceEquals(property, "W")) |
|
|
|
if (IsMatch(property, "W")) |
|
|
|
return Quaternion.W; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Color) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "A")) |
|
|
|
if (IsMatch(property, "A")) |
|
|
|
return Color.A; |
|
|
|
if (ReferenceEquals(property, "R")) |
|
|
|
if (IsMatch(property, "R")) |
|
|
|
return Color.R; |
|
|
|
if (ReferenceEquals(property, "G")) |
|
|
|
if (IsMatch(property, "G")) |
|
|
|
return Color.G; |
|
|
|
if (ReferenceEquals(property, "B")) |
|
|
|
if (IsMatch(property, "B")) |
|
|
|
return Color.B; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
|
|
static bool IsMatch(string propertyName, string memberName) => |
|
|
|
string.Equals(propertyName, memberName, StringComparison.Ordinal); |
|
|
|
} |
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(bool value) => |
|
|
|
@ -238,13 +239,6 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
Type = VariantType.Boolean, |
|
|
|
Boolean = value |
|
|
|
}; |
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(float scalar) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
Type = VariantType.Scalar, |
|
|
|
Scalar = scalar |
|
|
|
}; |
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(double d) => |
|
|
|
new ExpressionVariant |
|
|
|
@ -300,7 +294,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
public static implicit operator ExpressionVariant(Matrix value) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
Type = VariantType.Matrix3x2, |
|
|
|
Type = VariantType.AvaloniaMatrix, |
|
|
|
AvaloniaMatrix = value |
|
|
|
}; |
|
|
|
|
|
|
|
@ -330,15 +324,12 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
if (left.Type != right.Type || left.Type == VariantType.Invalid) |
|
|
|
return default; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Scalar) |
|
|
|
return left.Scalar + right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Double) |
|
|
|
return left.Double + right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector2) |
|
|
|
return left.Vector2 + right.Vector2; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector) |
|
|
|
return left.Vector + right.Vector; |
|
|
|
|
|
|
|
@ -350,16 +341,16 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4) |
|
|
|
return left.Vector4 + right.Vector4; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix3x2) |
|
|
|
return left.Matrix3x2 + right.Matrix3x2; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix4x4) |
|
|
|
return left.Matrix4x4 + right.Matrix4x4; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Quaternion) |
|
|
|
return left.Quaternion + right.Quaternion; |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -368,15 +359,12 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
if (left.Type != right.Type || left.Type == VariantType.Invalid) |
|
|
|
return default; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Scalar) |
|
|
|
return left.Scalar - right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Double) |
|
|
|
return left.Double - right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector2) |
|
|
|
return left.Vector2 - right.Vector2; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector) |
|
|
|
return left.Vector - right.Vector; |
|
|
|
|
|
|
|
@ -388,13 +376,13 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4) |
|
|
|
return left.Vector4 - right.Vector4; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix3x2) |
|
|
|
return left.Matrix3x2 - right.Matrix3x2; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix4x4) |
|
|
|
return left.Matrix4x4 - right.Matrix4x4; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Quaternion) |
|
|
|
return left.Quaternion - right.Quaternion; |
|
|
|
|
|
|
|
@ -403,34 +391,31 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
public static ExpressionVariant operator -(ExpressionVariant left) |
|
|
|
{ |
|
|
|
|
|
|
|
if (left.Type == VariantType.Scalar) |
|
|
|
return -left.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Double) |
|
|
|
return -left.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector2) |
|
|
|
return -left.Vector2; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector) |
|
|
|
return -left.Vector; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3) |
|
|
|
return -left.Vector3; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3D) |
|
|
|
return -left.Vector3D; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4) |
|
|
|
return -left.Vector4; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix3x2) |
|
|
|
return -left.Matrix3x2; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.AvaloniaMatrix) |
|
|
|
return -left.AvaloniaMatrix; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix4x4) |
|
|
|
return -left.Matrix4x4; |
|
|
|
|
|
|
|
@ -445,9 +430,6 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
if (left.Type == VariantType.Invalid || right.Type == VariantType.Invalid) |
|
|
|
return default; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Scalar && right.Type == VariantType.Scalar) |
|
|
|
return left.Scalar * right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.Double) |
|
|
|
return left.Double * right.Double; |
|
|
|
|
|
|
|
@ -457,53 +439,50 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
if (left.Type == VariantType.Vector && right.Type == VariantType.Vector) |
|
|
|
return Vector.Multiply(left.Vector, right.Vector); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector2 && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector2 * right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector * right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector2 && right.Type == VariantType.Double) |
|
|
|
return left.Vector2 * (float)right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector && right.Type == VariantType.Double) |
|
|
|
return left.Vector * right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3 && right.Type == VariantType.Vector3) |
|
|
|
return left.Vector3 * right.Vector3; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3D && right.Type == VariantType.Vector3D) |
|
|
|
return Vector3D.Multiply(left.Vector3D, right.Vector3D); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3 && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector3 * right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3D && right.Type == VariantType.Scalar) |
|
|
|
return Vector3D.Multiply(left.Vector3D, right.Scalar); |
|
|
|
if (left.Type == VariantType.Vector3 && right.Type == VariantType.Double) |
|
|
|
return left.Vector3 * (float)right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3D && right.Type == VariantType.Double) |
|
|
|
return Vector3D.Multiply(left.Vector3D, right.Double); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4 && right.Type == VariantType.Vector4) |
|
|
|
return left.Vector4 * right.Vector4; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4 && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector4 * right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4 && right.Type == VariantType.Double) |
|
|
|
return left.Vector4 * (float)right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix3x2 && right.Type == VariantType.Matrix3x2) |
|
|
|
return left.Matrix3x2 * right.Matrix3x2; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix3x2 && right.Type == VariantType.Scalar) |
|
|
|
return left.Matrix3x2 * right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix3x2 && right.Type == VariantType.Double) |
|
|
|
return left.Matrix3x2 * (float)right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.AvaloniaMatrix && right.Type == VariantType.AvaloniaMatrix) |
|
|
|
return left.AvaloniaMatrix * right.AvaloniaMatrix; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix4x4 && right.Type == VariantType.Matrix4x4) |
|
|
|
return left.Matrix4x4 * right.Matrix4x4; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix4x4 && right.Type == VariantType.Scalar) |
|
|
|
return left.Matrix4x4 * right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Matrix4x4 && right.Type == VariantType.Double) |
|
|
|
return left.Matrix4x4 * (float)right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Quaternion && right.Type == VariantType.Quaternion) |
|
|
|
return left.Quaternion * right.Quaternion; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Quaternion && right.Type == VariantType.Scalar) |
|
|
|
return left.Quaternion * right.Scalar; |
|
|
|
if (left.Type == VariantType.Quaternion && right.Type == VariantType.Double) |
|
|
|
return left.Quaternion * (float)right.Double; |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
@ -513,9 +492,6 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
if (left.Type == VariantType.Invalid || right.Type == VariantType.Invalid) |
|
|
|
return default; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Scalar && right.Type == VariantType.Scalar) |
|
|
|
return left.Scalar / right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.Double) |
|
|
|
return left.Double / right.Double; |
|
|
|
|
|
|
|
@ -525,14 +501,11 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
if (left.Type == VariantType.Vector && right.Type == VariantType.Vector) |
|
|
|
return Vector.Divide(left.Vector, right.Vector); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector2 && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector2 / right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector / right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector2 && right.Type == VariantType.Double) |
|
|
|
return left.Vector2 / (float)right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector && right.Type == VariantType.Double) |
|
|
|
return left.Vector / right.Scalar; |
|
|
|
return left.Vector / right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3 && right.Type == VariantType.Vector3) |
|
|
|
return left.Vector3 / right.Vector3; |
|
|
|
@ -540,21 +513,18 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
if (left.Type == VariantType.Vector3D && right.Type == VariantType.Vector3D) |
|
|
|
return Vector3D.Divide(left.Vector3D, right.Vector3D); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3 && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector3 / right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3D && right.Type == VariantType.Scalar) |
|
|
|
return Avalonia.Vector3D.Divide(left.Vector3D, right.Scalar); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3 && right.Type == VariantType.Double) |
|
|
|
return left.Vector3 / (float)right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3D && right.Type == VariantType.Double) |
|
|
|
return Avalonia.Vector3D.Divide(left.Vector3D, right.Double); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4 && right.Type == VariantType.Vector4) |
|
|
|
return left.Vector4 / right.Vector4; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4 && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector4 / right.Scalar; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4 && right.Type == VariantType.Double) |
|
|
|
return left.Vector4 / (float)right.Double; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Quaternion && right.Type == VariantType.Quaternion) |
|
|
|
return left.Quaternion / right.Quaternion; |
|
|
|
|
|
|
|
@ -564,11 +534,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
public ExpressionVariant EqualsTo(ExpressionVariant right) |
|
|
|
{ |
|
|
|
if (Type != right.Type || Type == VariantType.Invalid) |
|
|
|
return default; |
|
|
|
|
|
|
|
if (Type == VariantType.Scalar) |
|
|
|
return Scalar == right.Scalar; |
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
|
|
if (Type == VariantType.Double) |
|
|
|
return Double == right.Double; |
|
|
|
@ -623,8 +589,6 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
public static ExpressionVariant operator %(ExpressionVariant left, ExpressionVariant right) |
|
|
|
{ |
|
|
|
if (left.Type == VariantType.Scalar && right.Type == VariantType.Scalar) |
|
|
|
return left.Scalar % right.Scalar; |
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.Double) |
|
|
|
return left.Double % right.Double; |
|
|
|
return default; |
|
|
|
@ -632,18 +596,13 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
public static ExpressionVariant operator <(ExpressionVariant left, ExpressionVariant right) |
|
|
|
{ |
|
|
|
if (left.Type == VariantType.Scalar && right.Type == VariantType.Scalar) |
|
|
|
return left.Scalar < right.Scalar; |
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.Double) |
|
|
|
return left.Double < right.Double; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
public static ExpressionVariant operator >(ExpressionVariant left, ExpressionVariant right) |
|
|
|
{ |
|
|
|
if (left.Type == VariantType.Scalar && right.Type == VariantType.Scalar) |
|
|
|
return left.Scalar > right.Scalar; |
|
|
|
|
|
|
|
{ |
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.Double) |
|
|
|
return left.Double > right.Double; |
|
|
|
return default; |
|
|
|
@ -659,207 +618,89 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
public ExpressionVariant Or(ExpressionVariant right) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Boolean && right.Type == VariantType.Boolean) |
|
|
|
return Boolean && right.Boolean; |
|
|
|
return Boolean || right.Boolean; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
public bool TryCast<T>(out T res) where T : struct |
|
|
|
{ |
|
|
|
if (typeof(T) == typeof(bool)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Boolean) |
|
|
|
{ |
|
|
|
res = (T) (object) Boolean; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(float)) |
|
|
|
switch (default(T)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Scalar) |
|
|
|
{ |
|
|
|
res = (T) (object) Scalar; |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (Type == VariantType.Double) |
|
|
|
{ |
|
|
|
res = (T)(object)Scalar; |
|
|
|
case bool when Type is VariantType.Boolean: |
|
|
|
res = (T)(object)Boolean; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(double)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Double) |
|
|
|
{ |
|
|
|
res = (T) (object) Double; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Scalar) |
|
|
|
{ |
|
|
|
case float when Type is VariantType.Double: |
|
|
|
res = (T)(object)(float)Double; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector2)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector2) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector2; |
|
|
|
case double when Type is VariantType.Double: |
|
|
|
res = (T)(object)Double; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Vector) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector.ToVector2(); |
|
|
|
case System.Numerics.Vector2 when Type is VariantType.Vector2: |
|
|
|
res = (T)(object)Vector2; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector; |
|
|
|
case System.Numerics.Vector2 when Type is VariantType.Vector: |
|
|
|
res = (T)(object)Vector.ToVector2(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Vector2) |
|
|
|
{ |
|
|
|
case Avalonia.Vector when Type is VariantType.Vector: |
|
|
|
res = (T)(object)Vector; |
|
|
|
return true; |
|
|
|
case Avalonia.Vector when Type is VariantType.Vector2: |
|
|
|
res = (T)(object)new Vector(Vector2); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector3)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector3) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector3; |
|
|
|
case System.Numerics.Vector3 when Type is VariantType.Vector3: |
|
|
|
res = (T)(object)Vector3; |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (Type == VariantType.Vector3D) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector3D.ToVector3(); |
|
|
|
case System.Numerics.Vector3 when Type is VariantType.Vector3D: |
|
|
|
res = (T)(object)Vector3D.ToVector3(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector3D)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector3D) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector3D; |
|
|
|
case Avalonia.Vector3D when Type is VariantType.Vector3D: |
|
|
|
res = (T)(object)Vector3D; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Vector3) |
|
|
|
{ |
|
|
|
case Avalonia.Vector3D when Type is VariantType.Vector3: |
|
|
|
res = (T)(object)new Vector3D(Vector3); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector4)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector4) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector4; |
|
|
|
case System.Numerics.Vector4 when Type is VariantType.Vector4: |
|
|
|
res = (T)(object)Vector4; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix3x2)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Matrix3x2) |
|
|
|
{ |
|
|
|
res = (T) (object) Matrix3x2; |
|
|
|
case System.Numerics.Matrix3x2 when Type is VariantType.Matrix3x2: |
|
|
|
res = (T)(object)Matrix3x2; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.AvaloniaMatrix) |
|
|
|
{ |
|
|
|
res = (T) (object) Matrix3x2; |
|
|
|
case Avalonia.Matrix when Type is VariantType.AvaloniaMatrix: |
|
|
|
res = (T)(object)AvaloniaMatrix; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix4x4)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Matrix4x4) |
|
|
|
{ |
|
|
|
res = (T) (object) Matrix4x4; |
|
|
|
case System.Numerics.Matrix4x4 when Type is VariantType.Matrix4x4: |
|
|
|
res = (T)(object)Matrix4x4; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Quaternion)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Quaternion) |
|
|
|
{ |
|
|
|
res = (T) (object) Quaternion; |
|
|
|
case System.Numerics.Quaternion when Type is VariantType.Quaternion: |
|
|
|
res = (T)(object)Quaternion; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Avalonia.Media.Color)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Color) |
|
|
|
{ |
|
|
|
res = (T) (object) Color; |
|
|
|
case Avalonia.Media.Color when Type is VariantType.Color: |
|
|
|
res = (T)(object)Color; |
|
|
|
return true; |
|
|
|
} |
|
|
|
default: |
|
|
|
res = default; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
res = default; |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public static ExpressionVariant Create<T>(T v) where T : struct |
|
|
|
{ |
|
|
|
if (typeof(T) == typeof(bool)) |
|
|
|
return (bool) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(float)) |
|
|
|
return (float) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector2)) |
|
|
|
return (Vector2) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector)) |
|
|
|
return (Vector) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector3)) |
|
|
|
return (Vector3) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector3D)) |
|
|
|
return (Vector3D) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector4)) |
|
|
|
return (Vector4) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix3x2)) |
|
|
|
return (Matrix3x2) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix)) |
|
|
|
return (Matrix) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix4x4)) |
|
|
|
return (Matrix4x4) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Quaternion)) |
|
|
|
return (Quaternion) (object) v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Avalonia.Media.Color)) |
|
|
|
return (Avalonia.Media.Color) (object) v; |
|
|
|
|
|
|
|
throw new ArgumentException("Invalid variant type: " + typeof(T)); |
|
|
|
} |
|
|
|
=> default(T) switch |
|
|
|
{ |
|
|
|
bool => (bool)(object)v, |
|
|
|
float => (float)(object)v, |
|
|
|
double => (double)(object)v, |
|
|
|
System.Numerics.Vector2 => (Vector2)(object)v, |
|
|
|
Avalonia.Vector => (Vector)(object)v, |
|
|
|
System.Numerics.Vector3 => (Vector3)(object)v, |
|
|
|
Avalonia.Vector3D => (Vector3D)(object)v, |
|
|
|
System.Numerics.Vector4 => (Vector4)(object)v, |
|
|
|
System.Numerics.Matrix3x2 => (Matrix3x2)(object)v, |
|
|
|
Avalonia.Matrix => (Matrix)(object)v, |
|
|
|
System.Numerics.Matrix4x4 => (Matrix4x4)(object)v, |
|
|
|
System.Numerics.Quaternion => (Quaternion)(object)v, |
|
|
|
Avalonia.Media.Color => (Avalonia.Media.Color)(object)v, |
|
|
|
_ => throw new ArgumentException("Invalid variant type: " + typeof(T)) |
|
|
|
}; |
|
|
|
|
|
|
|
public T CastOrDefault<T>() where T : struct |
|
|
|
{ |
|
|
|
@ -869,35 +710,23 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
{ |
|
|
|
if (Type == VariantType.Boolean) |
|
|
|
return Boolean.ToString(); |
|
|
|
if (Type == VariantType.Scalar) |
|
|
|
return Scalar.ToString(CultureInfo.InvariantCulture); |
|
|
|
if (Type == VariantType.Double) |
|
|
|
return Double.ToString(CultureInfo.InvariantCulture); |
|
|
|
if (Type == VariantType.Vector2) |
|
|
|
return Vector2.ToString(); |
|
|
|
if (Type == VariantType.Vector) |
|
|
|
return Vector.ToString(); |
|
|
|
if (Type == VariantType.Vector3) |
|
|
|
return Vector3.ToString(); |
|
|
|
if (Type == VariantType.Vector3D) |
|
|
|
return Vector3D.ToString(); |
|
|
|
if (Type == VariantType.Vector4) |
|
|
|
return Vector4.ToString(); |
|
|
|
if (Type == VariantType.Quaternion) |
|
|
|
return Quaternion.ToString(); |
|
|
|
if (Type == VariantType.Matrix3x2) |
|
|
|
return Matrix3x2.ToString(); |
|
|
|
if (Type == VariantType.AvaloniaMatrix) |
|
|
|
return AvaloniaMatrix.ToString(); |
|
|
|
if (Type == VariantType.Matrix4x4) |
|
|
|
return Matrix4x4.ToString(); |
|
|
|
if (Type == VariantType.Color) |
|
|
|
return Color.ToString(); |
|
|
|
if (Type == VariantType.Invalid) |
|
|
|
return "Invalid"; |
|
|
|
return "Unknown"; |
|
|
|
return Type switch |
|
|
|
{ |
|
|
|
VariantType.Boolean => Boolean.ToString(), |
|
|
|
VariantType.Double => Double.ToString(CultureInfo.InvariantCulture), |
|
|
|
VariantType.Vector2 => Vector2.ToString(), |
|
|
|
VariantType.Vector => Vector.ToString(), |
|
|
|
VariantType.Vector3 => Vector3.ToString(), |
|
|
|
VariantType.Vector3D => Vector3D.ToString(), |
|
|
|
VariantType.Vector4 => Vector4.ToString(), |
|
|
|
VariantType.Quaternion => Quaternion.ToString(), |
|
|
|
VariantType.Matrix3x2 => Matrix3x2.ToString(), |
|
|
|
VariantType.AvaloniaMatrix => AvaloniaMatrix.ToString(), |
|
|
|
VariantType.Matrix4x4 => Matrix4x4.ToString(), |
|
|
|
VariantType.Color => Color.ToString(), |
|
|
|
VariantType.Invalid => "Invalid", |
|
|
|
_ => "Unknown" |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|