Page 1 of 1

Noesis.Vector2 property naming doesn't match System.Windows.Vector

Posted: 27 Jun 2023, 19:29
by groth
In System.Windows.Vector, the X and Y properties are defined as capitals ("X" and "Y"). But in the Noesis implementation of Vector2, the properties are defined as lowercase ("x" and "y"). Using the System.Windows.Vector in the XAML ends up throwing errors that there is no binding for the X property.

For example:
using System.Windows;

public class ControllerVisualizationContext
{
	...
	public ControllerInput ControllerInput { get; set; }
}

public class ControllerInput
{
	...
        // Ranged -1 to 1. Inactive = 0
        public Vector LStick { get; set; }
        ...
}
and in the Xaml:
<TextBlock x:Name="PreciseValue_L_Analog" Text="{Binding ControllerInput.LStick.X, StringFormat=\{0:F2\}}" />
Will throw the following errors:
Can't solve PropertyPath: Type 'Vector2' does not contain a property named 'X'
Binding failed: Path=ControllerInput.LStick.X, Source=Noesis.ControllerVisualizationContext.f1de4b00(''), Target=TextBlock('PreciseValue_L_Analog'), TargetProperty=TextBlock.Text
I can eliminate this if I modify the Vector2 reflection to add the capital accessors:
    NS_IMPLEMENT_INLINE_REFLECTION(Vector2, NoParent)
    {
        NsProp("x", &Vector2::x);
        NsProp("y", &Vector2::y);
        
	NsProp("X", &Vector2::x); // added
	NsProp("Y", &Vector2::y); // added
    }
I was curious if there was a specific reason the properties are different in their capitalization?
Are there any issues I'm unaware of in implementing this change?
Is there a better way to represent Vector2 (or Vector3) data that I'm not aware of?
Using System.Numerics.Vector2 has no properties defined in the C# side, so Blend doesn't like it.

Re: Noesis.Vector2 property naming doesn't match System.Windows.Vector

Posted: 29 Jun 2023, 12:27
by jsantos
Your patch is safe. For historical reasons our math library is using lower case for properties. We have plans to improve this by hiding our math types for internal use (SIMD friendly, no reflection) and create new types in Drawing that will mimic WPF ones (there are already a few like Point, Rect, Color, Thickness...).

Please, feel free to file a ticket if you want to track this.