Add Vector3 field test

This commit is contained in:
jlewin 2019-04-11 13:33:41 -07:00
parent a169d0a14c
commit fb1dfce378
2 changed files with 41 additions and 19 deletions

View file

@ -27,7 +27,7 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using System.Linq;
using MatterHackers.Agg.UI;
using MatterHackers.VectorMath;
@ -49,11 +49,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public Vector3 Vector3
{
get
{
return new Vector3(xEditWidget.Value, yEditWidget.Value, zEditWidget.Value);
}
get => new Vector3(xEditWidget.Value, yEditWidget.Value, zEditWidget.Value);
set
{
xEditWidget.Value = value.X;
@ -144,8 +140,21 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
protected override string ConvertValue(string newValue)
{
// Ensure we have a two value CSV or force to '0,0'
return (newValue?.Split(',').Length == 3) ? newValue.Trim() : "0,0,0";
// Ensure we have a three value CSV or force to '0,0,0'
string[] xyzwStrings = newValue.Split(',');
if (xyzwStrings.Length != 3)
{
xyzwStrings = new string[] { "0", "0", "0" };
}
// Convert string segments to double, then back to expected CSV string
return string.Join(
",",
xyzwStrings.Select(s =>
{
double.TryParse(s, out double doubleValue);
return doubleValue.ToString();
}).ToArray());
}
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
@ -156,14 +165,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
xyzStrings = new string[] { "0", "0", "0" };
}
double.TryParse(xyzStrings[0], out double currentValue);
xEditWidget.ActuallNumberEdit.Value = currentValue;
double.TryParse(xyzStrings[1], out currentValue);
yEditWidget.ActuallNumberEdit.Value = currentValue;
double.TryParse(xyzStrings[2], out currentValue);
zEditWidget.ActuallNumberEdit.Value = currentValue;
xEditWidget.Text = xyzStrings[0];
yEditWidget.Text = xyzStrings[1];
zEditWidget.Text = xyzStrings[2];
base.OnValueChanged(fieldChangedEventArgs);
}

View file

@ -371,10 +371,28 @@ namespace MatterControl.Tests.MatterControl
});
}
[Test, Ignore("Not Implemented")]
public void Vector3FieldTest()
[Test]
public async Task Vector3FieldTest()
{
Assert.Fail();
var theme = MatterHackers.MatterControl.AppContext.Theme;
var testField = new Vector3Field(theme);
await ValidateAgainstValueMap(
testField,
theme,
(field) =>
{
return string.Join(",", field.Content.Children.OfType<MHNumberEdit>().Select(w => w.ActuallNumberEdit.Text).ToArray());
},
new List<ValueMap>()
{
{"0.1,0.2,0.3", "0.1,0.2,0.3"},
{"1,2,3", "1,2,3"},
{",2,", "0,2,0"}, // Empty components should revert to 0s
{"x,2,y", "0,2,0"}, // Non-numeric components should revert to 0s
{",2", "0,0,0"}, // Non-vector4 csv should revert to Vector4.Zero
});
}
[Test]