// Verifies that EncodedS2LaxPolygonShape behaves identically to // S2LaxPolygonShape. Also supports testing that the encoded form is identical // to the re-encoded form. private static void TestEncodedS2LaxPolygonShape(S2LaxPolygonShape original) { Encoder encoder = new(); original.Encode(encoder, CodingHint.COMPACT); var decoder = encoder.Decoder(); var(success, encoded) = EncodedS2LaxPolygonShape.Init(decoder); Assert.True(success); Assert.Equal(encoded.NumLoops, original.NumLoops); Assert.Equal(encoded.NumVertices, original.NumVertices); Assert.Equal(encoded.NumEdges(), original.NumEdges()); Assert.Equal(encoded.NumChains(), original.NumChains()); Assert.Equal(encoded.Dimension(), original.Dimension()); Assert.Equal(encoded.IsEmpty(), original.IsEmpty()); Assert.Equal(encoded.IsFull(), original.IsFull()); Assert.Equal(encoded.GetReferencePoint(), original.GetReferencePoint()); for (int i = 0; i < original.NumLoops; ++i) { Assert.Equal(encoded.NumLoopVertices(i), original.NumLoopVertices(i)); Assert.Equal(encoded.GetChain(i), original.GetChain(i)); for (int j = 0; j < original.NumLoopVertices(i); ++j) { Assert.Equal(encoded.LoopVertex(i, j), original.LoopVertex(i, j)); Assert.Equal(encoded.ChainEdge(i, j), original.ChainEdge(i, j)); } } // Now test all the edges in a random order in order to exercise the cases // involving prev_loop_. var count = original.NumEdges(); List <int> edge_ids = new(count); LinqUtils.Iota(edge_ids, 0, count); var mt = new PseudoRandom.MersenneTwister(); edge_ids = edge_ids.Shuffle(mt.genrand_N).ToList(); foreach (var e in edge_ids) { Assert.Equal(encoded.GetChainPosition(e), original.GetChainPosition(e)); Assert.Equal(encoded.GetEdge(e), original.GetEdge(e)); } // Let's also test that the encoded form can be encoded, yielding the same // bytes as the originally encoded form. Encoder reencoder = new(); encoded.Encode(reencoder, CodingHint.COMPACT); Assert.True(encoder == reencoder); }