|
|
|
@ -21,7 +21,10 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
Matrix3x2, |
|
|
|
Matrix4x4, |
|
|
|
Quaternion, |
|
|
|
Color |
|
|
|
Color, |
|
|
|
RelativePoint, |
|
|
|
RelativeScalar, |
|
|
|
RelativeUnit |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -45,7 +48,9 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
[FieldOffset(4)] public Matrix4x4 Matrix4x4; |
|
|
|
[FieldOffset(4)] public Quaternion Quaternion; |
|
|
|
[FieldOffset(4)] public Color Color; |
|
|
|
|
|
|
|
[FieldOffset(4)] public RelativePoint RelativePoint; |
|
|
|
[FieldOffset(4)] public RelativeScalar RelativeScalar; |
|
|
|
[FieldOffset(4)] public RelativeUnit RelativeUnit; |
|
|
|
|
|
|
|
public ExpressionVariant GetProperty(string property) |
|
|
|
{ |
|
|
|
@ -57,7 +62,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return Vector2.Y; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Vector) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
@ -75,21 +80,21 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return Vector3.Y; |
|
|
|
if (ReferenceEquals(property, "Z")) |
|
|
|
return Vector3.Z; |
|
|
|
if(ReferenceEquals(property, "XY")) |
|
|
|
if (ReferenceEquals(property, "XY")) |
|
|
|
return new Vector2(Vector3.X, Vector3.Y); |
|
|
|
if(ReferenceEquals(property, "YX")) |
|
|
|
if (ReferenceEquals(property, "YX")) |
|
|
|
return new Vector2(Vector3.Y, Vector3.X); |
|
|
|
if(ReferenceEquals(property, "XZ")) |
|
|
|
if (ReferenceEquals(property, "XZ")) |
|
|
|
return new Vector2(Vector3.X, Vector3.Z); |
|
|
|
if(ReferenceEquals(property, "ZX")) |
|
|
|
if (ReferenceEquals(property, "ZX")) |
|
|
|
return new Vector2(Vector3.Z, Vector3.X); |
|
|
|
if(ReferenceEquals(property, "YZ")) |
|
|
|
if (ReferenceEquals(property, "YZ")) |
|
|
|
return new Vector2(Vector3.Y, Vector3.Z); |
|
|
|
if(ReferenceEquals(property, "ZY")) |
|
|
|
if (ReferenceEquals(property, "ZY")) |
|
|
|
return new Vector2(Vector3.Z, Vector3.Y); |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Vector3D) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
@ -98,17 +103,17 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return Vector3D.Y; |
|
|
|
if (ReferenceEquals(property, "Z")) |
|
|
|
return Vector3D.Z; |
|
|
|
if(ReferenceEquals(property, "XY")) |
|
|
|
if (ReferenceEquals(property, "XY")) |
|
|
|
return new Vector(Vector3D.X, Vector3D.Y); |
|
|
|
if(ReferenceEquals(property, "YX")) |
|
|
|
if (ReferenceEquals(property, "YX")) |
|
|
|
return new Vector(Vector3D.Y, Vector3D.X); |
|
|
|
if(ReferenceEquals(property, "XZ")) |
|
|
|
if (ReferenceEquals(property, "XZ")) |
|
|
|
return new Vector(Vector3D.X, Vector3D.Z); |
|
|
|
if(ReferenceEquals(property, "ZX")) |
|
|
|
if (ReferenceEquals(property, "ZX")) |
|
|
|
return new Vector(Vector3D.Z, Vector3D.X); |
|
|
|
if(ReferenceEquals(property, "YZ")) |
|
|
|
if (ReferenceEquals(property, "YZ")) |
|
|
|
return new Vector(Vector3D.Y, Vector3D.Z); |
|
|
|
if(ReferenceEquals(property, "ZY")) |
|
|
|
if (ReferenceEquals(property, "ZY")) |
|
|
|
return new Vector(Vector3D.Z, Vector3D.Y); |
|
|
|
return default; |
|
|
|
} |
|
|
|
@ -142,7 +147,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return Matrix3x2.M32; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.AvaloniaMatrix) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "M11")) |
|
|
|
@ -215,7 +220,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return Quaternion.W; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Color) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "A")) |
|
|
|
@ -229,6 +234,26 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.RelativePoint) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "X")) |
|
|
|
return (float)RelativePoint.Point.X; |
|
|
|
if (ReferenceEquals(property, "Y")) |
|
|
|
return (float)RelativePoint.Point.Y; |
|
|
|
if (ReferenceEquals(property, "Unit")) |
|
|
|
return RelativePoint.Unit; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.RelativeScalar) |
|
|
|
{ |
|
|
|
if (ReferenceEquals(property, "Scalar")) |
|
|
|
return RelativeScalar.Scalar; |
|
|
|
if (ReferenceEquals(property, "Unit")) |
|
|
|
return RelativeScalar.Unit; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -245,7 +270,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
Type = VariantType.Scalar, |
|
|
|
Scalar = scalar |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(double d) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
@ -260,7 +285,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
Type = VariantType.Vector2, |
|
|
|
Vector2 = value |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(Vector value) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
@ -274,7 +299,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
Type = VariantType.Vector3, |
|
|
|
Vector3 = value |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(Vector3D value) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
@ -296,7 +321,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
Type = VariantType.Matrix3x2, |
|
|
|
Matrix3x2 = value |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(Matrix value) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
@ -317,7 +342,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
Type = VariantType.Quaternion, |
|
|
|
Quaternion = value |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(Avalonia.Media.Color value) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
@ -325,6 +350,27 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
Color = value |
|
|
|
}; |
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(RelativePoint value) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
Type = VariantType.RelativePoint, |
|
|
|
RelativePoint = value |
|
|
|
}; |
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(RelativeScalar value) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
Type = VariantType.RelativeScalar, |
|
|
|
RelativeScalar = value |
|
|
|
}; |
|
|
|
|
|
|
|
public static implicit operator ExpressionVariant(RelativeUnit value) => |
|
|
|
new ExpressionVariant |
|
|
|
{ |
|
|
|
Type = VariantType.RelativeUnit, |
|
|
|
RelativeUnit = value |
|
|
|
}; |
|
|
|
|
|
|
|
public static ExpressionVariant operator +(ExpressionVariant left, ExpressionVariant right) |
|
|
|
{ |
|
|
|
if (left.Type != right.Type || left.Type == VariantType.Invalid) |
|
|
|
@ -332,13 +378,13 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
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 +396,29 @@ 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; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativePoint && left.RelativePoint.Unit == right.RelativePoint.Unit) |
|
|
|
{ |
|
|
|
return new RelativePoint( |
|
|
|
left.RelativePoint.Point.X + right.RelativePoint.Point.X, |
|
|
|
left.RelativePoint.Point.Y + right.RelativePoint.Point.Y, |
|
|
|
left.RelativePoint.Unit); |
|
|
|
} |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar && left.RelativeScalar.Unit == right.RelativeScalar.Unit) |
|
|
|
{ |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar + right.RelativeScalar.Scalar, left.RelativeScalar.Unit); |
|
|
|
} |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -370,13 +429,13 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
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,16 +447,29 @@ 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; |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativePoint && left.RelativePoint.Unit == right.RelativePoint.Unit) |
|
|
|
{ |
|
|
|
return new RelativePoint( |
|
|
|
left.RelativePoint.Point.X - right.RelativePoint.Point.X, |
|
|
|
left.RelativePoint.Point.Y - right.RelativePoint.Point.Y, |
|
|
|
left.RelativePoint.Unit); |
|
|
|
} |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar && left.RelativeScalar.Unit == right.RelativeScalar.Unit) |
|
|
|
{ |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar - right.RelativeScalar.Scalar, left.RelativeScalar.Unit); |
|
|
|
} |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -406,37 +478,43 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
if (left.Type == VariantType.Quaternion) |
|
|
|
return -left.Quaternion; |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativePoint) |
|
|
|
return new RelativePoint(-left.RelativePoint.Point.X, -left.RelativePoint.Point.Y, left.RelativePoint.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar) |
|
|
|
return new RelativeScalar(-left.RelativeScalar.Scalar, left.RelativeScalar.Unit); |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -447,7 +525,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
@ -459,22 +537,22 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
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.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); |
|
|
|
|
|
|
|
@ -483,28 +561,63 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4 && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector4 * right.Scalar; |
|
|
|
|
|
|
|
|
|
|
|
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.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.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.RelativePoint && right.Type == VariantType.Scalar) |
|
|
|
return new RelativePoint(left.RelativePoint.Point.X * right.Scalar, left.RelativePoint.Point.Y * right.Scalar, left.RelativePoint.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativePoint && right.Type == VariantType.Double) |
|
|
|
return new RelativePoint(left.RelativePoint.Point.X * right.Double, left.RelativePoint.Point.Y * right.Double, left.RelativePoint.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Scalar && right.Type == VariantType.RelativePoint) |
|
|
|
return new RelativePoint(left.Scalar * right.RelativePoint.Point.X, left.Scalar * right.RelativePoint.Point.Y, right.RelativePoint.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.RelativePoint) |
|
|
|
return new RelativePoint(left.Double * right.RelativePoint.Point.X, left.Double * right.RelativePoint.Point.Y, right.RelativePoint.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.Scalar) |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar * right.Scalar, left.RelativeScalar.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.Double) |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar * right.Double, left.RelativeScalar.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Scalar && right.Type == VariantType.RelativeScalar) |
|
|
|
return new RelativeScalar(left.Scalar * right.RelativeScalar.Scalar, right.RelativeScalar.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.RelativeScalar) |
|
|
|
return new RelativeScalar(left.Double * right.RelativeScalar.Scalar, right.RelativeScalar.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativePoint && right.Type == VariantType.RelativePoint && left.RelativePoint.Unit == right.RelativePoint.Unit) |
|
|
|
{ |
|
|
|
return new RelativePoint( |
|
|
|
left.RelativePoint.Point.X * right.RelativePoint.Point.X, |
|
|
|
left.RelativePoint.Point.Y * right.RelativePoint.Point.Y, |
|
|
|
left.RelativePoint.Unit); |
|
|
|
} |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.RelativeScalar && left.RelativeScalar.Unit == right.RelativeScalar.Unit) |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar * right.RelativeScalar.Scalar, left.RelativeScalar.Unit); |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -515,7 +628,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
@ -527,10 +640,10 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
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.Vector && right.Type == VariantType.Double) |
|
|
|
return left.Vector / right.Scalar; |
|
|
|
|
|
|
|
@ -545,7 +658,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3D && right.Type == VariantType.Scalar) |
|
|
|
return Avalonia.Vector3D.Divide(left.Vector3D, right.Scalar); |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector3D && right.Type == VariantType.Double) |
|
|
|
return Avalonia.Vector3D.Divide(left.Vector3D, right.Double); |
|
|
|
|
|
|
|
@ -554,10 +667,33 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
if (left.Type == VariantType.Vector4 && right.Type == VariantType.Scalar) |
|
|
|
return left.Vector4 / right.Scalar; |
|
|
|
|
|
|
|
|
|
|
|
if (left.Type == VariantType.Quaternion && right.Type == VariantType.Quaternion) |
|
|
|
return left.Quaternion / right.Quaternion; |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativePoint && right.Type == VariantType.Scalar) |
|
|
|
return new RelativePoint(left.RelativePoint.Point.X / right.Scalar, left.RelativePoint.Point.Y / right.Scalar, left.RelativePoint.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativePoint && right.Type == VariantType.Double) |
|
|
|
return new RelativePoint(left.RelativePoint.Point.X / right.Double, left.RelativePoint.Point.Y / right.Double, left.RelativePoint.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.Scalar) |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar / right.Scalar, left.RelativeScalar.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.Double) |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar / right.Double, left.RelativeScalar.Unit); |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativePoint && right.Type == VariantType.RelativePoint && left.RelativePoint.Unit == right.RelativePoint.Unit) |
|
|
|
{ |
|
|
|
return new RelativePoint( |
|
|
|
left.RelativePoint.Point.X / right.RelativePoint.Point.X, |
|
|
|
left.RelativePoint.Point.Y / right.RelativePoint.Point.Y, |
|
|
|
left.RelativePoint.Unit); |
|
|
|
} |
|
|
|
|
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.RelativeScalar && left.RelativeScalar.Unit == right.RelativeScalar.Unit) |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar / right.RelativeScalar.Scalar, left.RelativeScalar.Unit); |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -568,20 +704,20 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
if (Type == VariantType.Scalar) |
|
|
|
return Scalar == right.Scalar; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Double) |
|
|
|
return Double == right.Double; |
|
|
|
|
|
|
|
if (Type == VariantType.Vector2) |
|
|
|
return Vector2 == right.Vector2; |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Vector) |
|
|
|
return Vector == right.Vector; |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Vector3) |
|
|
|
return Vector3 == right.Vector3; |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Vector3D) |
|
|
|
return Vector3D == right.Vector3D; |
|
|
|
|
|
|
|
@ -593,7 +729,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
if (Type == VariantType.Matrix3x2) |
|
|
|
return Matrix3x2 == right.Matrix3x2; |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.AvaloniaMatrix) |
|
|
|
return AvaloniaMatrix == right.AvaloniaMatrix; |
|
|
|
|
|
|
|
@ -602,7 +738,16 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
|
|
|
|
if (Type == VariantType.Quaternion) |
|
|
|
return Quaternion == right.Quaternion; |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.RelativePoint) |
|
|
|
return RelativePoint == right.RelativePoint; |
|
|
|
|
|
|
|
if (Type == VariantType.RelativeScalar) |
|
|
|
return RelativeScalar == right.RelativeScalar; |
|
|
|
|
|
|
|
if (Type == VariantType.RelativeUnit) |
|
|
|
return RelativeUnit == right.RelativeUnit; |
|
|
|
|
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -627,6 +772,8 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return left.Scalar % right.Scalar; |
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.Double) |
|
|
|
return left.Double % right.Double; |
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.RelativeScalar && left.RelativeScalar.Unit == right.RelativeScalar.Unit) |
|
|
|
return new RelativeScalar(left.RelativeScalar.Scalar % right.RelativeScalar.Scalar, left.RelativeScalar.Unit); |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -636,6 +783,8 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return left.Scalar < right.Scalar; |
|
|
|
if (left.Type == VariantType.Double && right.Type == VariantType.Double) |
|
|
|
return left.Double < right.Double; |
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.RelativeScalar && left.RelativeScalar.Unit == right.RelativeScalar.Unit) |
|
|
|
return left.RelativeScalar.Scalar < right.RelativeScalar.Scalar; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -643,9 +792,11 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
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; |
|
|
|
if (left.Type == VariantType.RelativeScalar && right.Type == VariantType.RelativeScalar && left.RelativeScalar.Unit == right.RelativeScalar.Unit) |
|
|
|
return left.RelativeScalar.Scalar > right.RelativeScalar.Scalar; |
|
|
|
return default; |
|
|
|
} |
|
|
|
|
|
|
|
@ -669,7 +820,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
if (Type == VariantType.Boolean) |
|
|
|
{ |
|
|
|
res = (T) (object) Boolean; |
|
|
|
res = (T)(object)Boolean; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -678,27 +829,27 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
if (Type == VariantType.Scalar) |
|
|
|
{ |
|
|
|
res = (T) (object) Scalar; |
|
|
|
res = (T)(object)Scalar; |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (Type == VariantType.Double) |
|
|
|
{ |
|
|
|
res = (T)(object)Scalar; |
|
|
|
res = (T)(object)(float)Double; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeof(T) == typeof(double)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Double) |
|
|
|
{ |
|
|
|
res = (T) (object) Double; |
|
|
|
res = (T)(object)Double; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Scalar) |
|
|
|
{ |
|
|
|
res = (T)(object)(float)Double; |
|
|
|
res = (T)(object)(double)Scalar; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -707,22 +858,22 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector2) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector2; |
|
|
|
res = (T)(object)Vector2; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (Type == VariantType.Vector) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector.ToVector2(); |
|
|
|
res = (T)(object)Vector.ToVector2(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector; |
|
|
|
res = (T)(object)Vector; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@ -737,24 +888,24 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector3) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector3; |
|
|
|
res = (T)(object)Vector3; |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (Type == VariantType.Vector3D) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector3D.ToVector3(); |
|
|
|
res = (T)(object)Vector3D.ToVector3(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector3D)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector3D) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector3D; |
|
|
|
res = (T)(object)Vector3D; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Type == VariantType.Vector3) |
|
|
|
{ |
|
|
|
res = (T)(object)new Vector3D(Vector3); |
|
|
|
@ -766,7 +917,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
if (Type == VariantType.Vector4) |
|
|
|
{ |
|
|
|
res = (T) (object) Vector4; |
|
|
|
res = (T)(object)Vector4; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -775,16 +926,16 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
if (Type == VariantType.Matrix3x2) |
|
|
|
{ |
|
|
|
res = (T) (object) Matrix3x2; |
|
|
|
res = (T)(object)Matrix3x2; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.AvaloniaMatrix) |
|
|
|
{ |
|
|
|
res = (T) (object) Matrix3x2; |
|
|
|
res = (T)(object)Matrix3x2; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -793,7 +944,7 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
if (Type == VariantType.Matrix4x4) |
|
|
|
{ |
|
|
|
res = (T) (object) Matrix4x4; |
|
|
|
res = (T)(object)Matrix4x4; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -802,16 +953,44 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
{ |
|
|
|
if (Type == VariantType.Quaternion) |
|
|
|
{ |
|
|
|
res = (T) (object) Quaternion; |
|
|
|
res = (T)(object)Quaternion; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Avalonia.Media.Color)) |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Color)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.Color) |
|
|
|
{ |
|
|
|
res = (T) (object) Color; |
|
|
|
res = (T)(object)Color; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(RelativePoint)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.RelativePoint) |
|
|
|
{ |
|
|
|
res = (T)(object)RelativePoint; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeof(T) == typeof(RelativeScalar)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.RelativeScalar) |
|
|
|
{ |
|
|
|
res = (T)(object)RelativeScalar; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(T) == typeof(RelativeUnit)) |
|
|
|
{ |
|
|
|
if (Type == VariantType.RelativeUnit) |
|
|
|
{ |
|
|
|
res = (T)(object)RelativeUnit; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -823,40 +1002,52 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
public static ExpressionVariant Create<T>(T v) where T : struct |
|
|
|
{ |
|
|
|
if (typeof(T) == typeof(bool)) |
|
|
|
return (bool) (object) v; |
|
|
|
return (bool)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(float)) |
|
|
|
return (float) (object) v; |
|
|
|
return (float)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(double)) |
|
|
|
return (double)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector2)) |
|
|
|
return (Vector2) (object) v; |
|
|
|
|
|
|
|
return (Vector2)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector)) |
|
|
|
return (Vector) (object) v; |
|
|
|
return (Vector)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector3)) |
|
|
|
return (Vector3) (object) v; |
|
|
|
|
|
|
|
return (Vector3)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector3D)) |
|
|
|
return (Vector3D) (object) v; |
|
|
|
return (Vector3D)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Vector4)) |
|
|
|
return (Vector4) (object) v; |
|
|
|
return (Vector4)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix3x2)) |
|
|
|
return (Matrix3x2) (object) v; |
|
|
|
|
|
|
|
return (Matrix3x2)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix)) |
|
|
|
return (Matrix) (object) v; |
|
|
|
return (Matrix)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Matrix4x4)) |
|
|
|
return (Matrix4x4) (object) v; |
|
|
|
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; |
|
|
|
return (Quaternion)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(Color)) |
|
|
|
return (Color)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(RelativePoint)) |
|
|
|
return (RelativePoint)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(RelativeScalar)) |
|
|
|
return (RelativeScalar)(object)v; |
|
|
|
|
|
|
|
if (typeof(T) == typeof(RelativeUnit)) |
|
|
|
return (RelativeUnit)(object)v; |
|
|
|
|
|
|
|
throw new ArgumentException("Invalid variant type: " + typeof(T)); |
|
|
|
} |
|
|
|
@ -895,6 +1086,12 @@ namespace Avalonia.Rendering.Composition.Expressions |
|
|
|
return Matrix4x4.ToString(); |
|
|
|
if (Type == VariantType.Color) |
|
|
|
return Color.ToString(); |
|
|
|
if (Type == VariantType.RelativePoint) |
|
|
|
return RelativePoint.ToString(); |
|
|
|
if (Type == VariantType.RelativeScalar) |
|
|
|
return RelativeScalar.ToString(); |
|
|
|
if (Type == VariantType.RelativeUnit) |
|
|
|
return RelativeUnit.ToString(); |
|
|
|
if (Type == VariantType.Invalid) |
|
|
|
return "Invalid"; |
|
|
|
return "Unknown"; |
|
|
|
|