private static IEnumerable <uint> Encode(IPuntal puntal, TileGeometryTransform tgt) { const int CoordinateIndex = 0; var geometry = (Geometry)puntal; int currentX = 0, currentY = 0; var parameters = new List <uint>(); for (int i = 0; i < geometry.NumGeometries; i++) { var point = (Point)geometry.GetGeometryN(i); (int x, int y) = tgt.Transform(point.CoordinateSequence, CoordinateIndex, ref currentX, ref currentY); if (i == 0 || x > 0 || y > 0) { parameters.Add(GenerateParameterInteger(x)); parameters.Add(GenerateParameterInteger(y)); } } // Return result yield return(GenerateCommandInteger(MapboxCommandType.MoveTo, parameters.Count / 2)); foreach (uint parameter in parameters) { yield return(parameter); } }
private static IEnumerable <uint> Encode(CoordinateSequence sequence, TileGeometryTransform tgt, ref int currentX, ref int currentY, bool ring = false, bool ccw = false) { // how many parameters for LineTo command int count = sequence.Count; // if we have a ring we need to check orientation if (ring) { if (ccw != Algorithm.Orientation.IsCCW(sequence)) { sequence = sequence.Copy(); CoordinateSequences.Reverse(sequence); } } var encoded = new List <uint>(); // Start point encoded.Add(GenerateCommandInteger(MapboxCommandType.MoveTo, 1)); var position = tgt.Transform(sequence, 0, ref currentX, ref currentY); encoded.Add(GenerateParameterInteger(position.x)); encoded.Add(GenerateParameterInteger(position.y)); // Add LineTo command (stub) int lineToCount = 0; encoded.Add(GenerateCommandInteger(MapboxCommandType.LineTo, lineToCount)); for (int i = 1; i < count; i++) { position = tgt.Transform(sequence, i, ref currentX, ref currentY); if (position.x != 0 || position.y != 0) { encoded.Add(GenerateParameterInteger(position.x)); encoded.Add(GenerateParameterInteger(position.y)); lineToCount++; } } if (lineToCount > 0) { encoded[3] = GenerateCommandInteger(MapboxCommandType.LineTo, lineToCount); } // Validate encoded data if (ring) { // A ring has 1 MoveTo and 1 LineTo command. // A ring is only valid if we have at least 3 points, otherwise collapse if (encoded.Count - 2 >= 6) { encoded.Add(GenerateCommandInteger(MapboxCommandType.ClosePath, 1)); } else { encoded.Clear(); } } else { // A line has 1 MoveTo and 1 LineTo command. // A line is valid if it has at least 2 points if (encoded.Count - 2 < 4) { encoded.Clear(); } } return(encoded); }