Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public Matrix4x4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3,
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
return $"Matrix3x2({_value.M11},{_value.M12},{_value.M21},{_value.M22},{_value.M31},{_value.M32})";
return $"Matrix3x2({_value.M11.ToCompositionString()},{_value.M12.ToCompositionString()},{_value.M21.ToCompositionString()},{_value.M22.ToCompositionString()},{_value.M31.ToCompositionString()},{_value.M32.ToCompositionString()})";
}

private Matrix3x2 _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,10 @@ public Matrix4x4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3,
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
return $"Matrix4x4({_value.M11},{_value.M12},{_value.M13},{_value.M14}," +
$"{_value.M21},{_value.M22},{_value.M23},{_value.M24}," +
$"{_value.M31},{_value.M32},{_value.M33},{_value.M34}," +
$"{_value.M41},{_value.M42},{_value.M43},{_value.M44})";
return $"Matrix4x4({_value.M11.ToCompositionString()},{_value.M12.ToCompositionString()},{_value.M13.ToCompositionString()},{_value.M14.ToCompositionString()}," +
$"{_value.M21.ToCompositionString()},{_value.M22.ToCompositionString()},{_value.M23.ToCompositionString()},{_value.M24.ToCompositionString()}," +
$"{_value.M31.ToCompositionString()},{_value.M32.ToCompositionString()},{_value.M33.ToCompositionString()},{_value.M34.ToCompositionString()}," +
$"{_value.M41.ToCompositionString()},{_value.M42.ToCompositionString()},{_value.M43.ToCompositionString()},{_value.M44.ToCompositionString()})";
}

private Matrix4x4 _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static implicit operator QuaternionNode(Quaternion value)
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
return $"Quaternion({_value.X},{_value.Y},{_value.Z},{_value.W})";
return $"Quaternion({_value.X.ToCompositionString()},{_value.Y.ToCompositionString()},{_value.Z.ToCompositionString()},{_value.W.ToCompositionString()})";
}

private Quaternion _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ public static implicit operator ScalarNode(int value)
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
// Important to use invariant culture to make sure that floats are written using a .
return _value.ToString(System.Globalization.CultureInfo.InvariantCulture);
return _value.ToCompositionString();
}

private float _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public Matrix4x4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3,
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
return $"Vector2({_value.X},{_value.Y})";
return $"Vector2({_value.X.ToCompositionString()},{_value.Y.ToCompositionString()})";
}

private Vector2 _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public Matrix4x4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3,
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
return $"Vector3({_value.X},{_value.Y},{_value.Z})";
return $"Vector3({_value.X.ToCompositionString()},{_value.Y.ToCompositionString()},{_value.Z.ToCompositionString()})";
}

private Vector3 _value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public Matrix4x4Node GetSubchannels(Subchannel s1, Subchannel s2, Subchannel s3,
/// <returns>System.String.</returns>
protected internal override string GetValue()
{
return $"Vector4({_value.X},{_value.Y},{_value.Z},{_value.W})";
return $"Vector4({_value.X.ToCompositionString()},{_value.Y.ToCompositionString()},{_value.Z.ToCompositionString()},{_value.W.ToCompositionString()})";
}

private Vector4 _value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.Contracts;

namespace Microsoft.Toolkit.Uwp.UI.Animations
{
/// <summary>
/// An extension <see langword="class"/> for the <see cref="float"/> type
/// </summary>
internal static class FloatExtensions
{
/// <summary>
/// Returns a <see cref="string"/> representation of a <see cref="float"/> that avoids scientific notation, which is not compatible with the composition expression animations API
/// </summary>
/// <param name="number">The input <see cref="float"/> to process</param>
/// <returns>A <see cref="string"/> representation of <paramref name="number"/> that can be used in a expression animation</returns>
[Pure]
public static string ToCompositionString(this float number)
{
var defaultString = number.ToString(System.Globalization.CultureInfo.InvariantCulture);
var eIndex = defaultString.IndexOf('E');

// If the default string representation is not in scientific notation, we can use it
if (eIndex == -1)
{
return defaultString;
}

// If the number uses scientific notation because it is too large, we can print it without the decimal places
var exponent = int.Parse(defaultString.Substring(eIndex + 1));
if (exponent >= 0)
{
return number.ToString($"F0", System.Globalization.CultureInfo.InvariantCulture);
}

// Otherwise, we need to print it with the right number of decimals
var decimalPlaces = -exponent // The number of decimal places is the exponent of 10
+ eIndex // Plus each character in the mantissa
+ (number < 0 ?
-3 : // Minus the sign, dot and first number of the mantissa if negative
-2); // Minus the dot and first number of the mantissa otherwise

return number.ToString($"F{decimalPlaces}", System.Globalization.CultureInfo.InvariantCulture);
}
}
}