コード例 #1
0
 /// <summary>
 /// Creates and returns a full copy of this <see cref="ILinearRing"/> object.
 /// (including all coordinates contained by it).
 /// </summary>
 /// <returns>A copy of this instance</returns>
 public override IGeometry Copy()
 {
     return(new LinearRing(CoordinateSequence.Copy(), Factory));
 }
コード例 #2
0
 /// <summary>
 /// Convenience method which provides a standard way of copying <see cref="CoordinateSequence"/>s.
 /// </summary>
 /// <param name="seq">The sequence to copy.</param>
 /// <returns>A deep copy of the sequence.</returns>
 protected virtual CoordinateSequence Copy(CoordinateSequence seq)
 {
     return(seq.Copy());
 }
        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);
        }