@@ -1582,6 +1582,63 @@ func TestLoopNormalizedCompatibleWithContains(t *testing.T) {
1582
1582
}
1583
1583
}
1584
1584
1585
+ func TestLoopIsValidDetectsInvalidLoops (t * testing.T ) {
1586
+ tests := []struct {
1587
+ msg string
1588
+ points []Point
1589
+ }{
1590
+ // Not enough vertices. Note that all single-vertex loops are valid; they
1591
+ // are interpreted as being either "empty" or "full".
1592
+ {
1593
+ msg : "loop has no vertices" ,
1594
+ points : parsePoints ("" ),
1595
+ },
1596
+ {
1597
+ msg : "loop has too few vertices" ,
1598
+ points : parsePoints ("20:20, 21:21" ),
1599
+ },
1600
+ // degenerate edge checks happen in validation before duplicate vertices.
1601
+ {
1602
+ msg : "loop has degenerate first edge" ,
1603
+ points : parsePoints ("20:20, 20:20, 20:21" ),
1604
+ },
1605
+ {
1606
+ msg : "loop has degenerate third edge" ,
1607
+ points : parsePoints ("20:20, 20:21, 20:20" ),
1608
+ },
1609
+ // TODO(roberts): Uncomment these cases when FindAnyCrossings is in.
1610
+ /*
1611
+ {
1612
+ msg: "loop has duplicate points",
1613
+ points: parsePoints("20:20, 21:21, 21:20, 20:20, 20:21"),
1614
+ },
1615
+ {
1616
+ msg: "loop has crossing edges",
1617
+ points: parsePoints("20:20, 21:21, 21:20.5, 21:20, 20:21"),
1618
+ },
1619
+ */
1620
+ {
1621
+ // Ensure points are not normalized.
1622
+ msg : "loop with non-normalized vertices" ,
1623
+ points : []Point {
1624
+ Point {r3.Vector {2 , 0 , 0 }},
1625
+ Point {r3.Vector {0 , 1 , 0 }},
1626
+ Point {r3.Vector {0 , 0 , 1 }},
1627
+ },
1628
+ },
1629
+ }
1630
+
1631
+ for _ , test := range tests {
1632
+ loop := LoopFromPoints (test .points )
1633
+ err := loop .findValidationError ()
1634
+ if err == nil {
1635
+ t .Errorf ("%s. %v.findValidationError() = nil, want err to be non-nil" , test .msg , loop )
1636
+ }
1637
+ // The C++ tests also tests that the returned error message string contains
1638
+ // a specific set of text. That part of the test is skipped here.
1639
+ }
1640
+ }
1641
+
1585
1642
const (
1586
1643
// TODO(roberts): Convert these into changeable flags or parameters.
1587
1644
// A loop with a 10km radius and 4096 vertices has an edge length of 15 meters.
0 commit comments