Skip to content

Commit

Permalink
refactor: validate ignored constraints with warning
Browse files Browse the repository at this point in the history
  • Loading branch information
andywiecko committed Sep 11, 2024
1 parent 2d8cc84 commit 267cf4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
7 changes: 2 additions & 5 deletions Runtime/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,16 +1211,13 @@ private void ValidateIgnoredConstraints()

if (!constraints.IsCreated)
{
LogError($"[Triangulator]: IgnoreConstraintForPlantingSeeds buffer is provided, but ConstraintEdges is missing!");
status.Value |= Status.ERR;
return;
LogWarning($"[Triangulator]: IgnoreConstraintForPlantingSeeds buffer is provided, but ConstraintEdges is missing. This setting has no effect.");
}

if (ignoredConstraints.Length != constraints.Length / 2)
if (constraints.IsCreated && ignoredConstraints.Length != constraints.Length / 2)
{
LogError($"[Triangulator]: IgnoreConstraintForPlantingSeeds length must be equal to half the length of ConstraintEdges!");
status.Value |= Status.ERR;
return;
}
}

Expand Down
14 changes: 7 additions & 7 deletions Tests/TriangulatorGenericsEditorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,16 @@ public void ValidateConstraintDelaunayTriangulationTest(float2[] managedPosition

private static readonly TestCaseData[] validateIgnoredConstraintTestData = new TestCaseData[]
{
new(new int[]{ 0, 1 }, new bool[]{ false, false }) { TestName = "Test case 1 (bad length)"},
new(default(int[]), new bool[]{ false, false }) { TestName = "Test case 2 (missing constraints)"},
new(new int[]{ 0, 1 }, new bool[]{ false, false }, false) { TestName = "Test case 1 (bad length)"},
new(default(int[]), new bool[]{ false, false }, true) { TestName = "Test case 2 (missing constraints)"},
}.SelectMany(i => new[]
{
new TestCaseData(i.Arguments[0], i.Arguments[1], true){ TestName = i.TestName + ", verbose"},
new TestCaseData(i.Arguments[0], i.Arguments[1], false){ TestName = i.TestName + ", no verbose" }
new TestCaseData(i.Arguments[0], i.Arguments[1], i.Arguments[2], true){ TestName = i.TestName + ", verbose"},
new TestCaseData(i.Arguments[0], i.Arguments[1], i.Arguments[2], false){ TestName = i.TestName + ", no verbose" }
}).ToArray();

[Test, TestCaseSource(nameof(validateIgnoredConstraintTestData))]
public void ValidateIgnoredConstraintTest(int[] constraints, bool[] ignoredConstraints, bool verbose)
public void ValidateIgnoredConstraintTest(int[] constraints, bool[] ignoredConstraints, bool warning, bool verbose)
{
using var positions = new NativeArray<T>(new float2[] { 0, 1, math.float2(0, 1), }.DynamicCast<T>(), Allocator.Persistent);
using var constraintEdges = new NativeArray<int>(constraints ?? (new int[0]), Allocator.Persistent);
Expand All @@ -378,12 +378,12 @@ public void ValidateIgnoredConstraintTest(int[] constraints, bool[] ignoredConst

if (verbose)
{
LogAssert.Expect(LogType.Error, new Regex(".*"));
LogAssert.Expect(warning ? LogType.Warning : LogType.Error, new Regex(".*"));
}

triangulator.Run();

Assert.That(triangulator.Output.Status.Value, Is.EqualTo(Status.ERR));
Assert.That(triangulator.Output.Status.Value, Is.EqualTo(warning ? Status.OK : Status.ERR));
}

private static readonly TestCaseData[] edgeConstraintsTestData =
Expand Down

0 comments on commit 267cf4f

Please sign in to comment.