// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections; using System.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; namespace Core.Common.Base.Data { /// /// This class provides a collection of with coordinates. /// public class RoundedPoint2DCollection : IEnumerable { private readonly IEnumerable points; private readonly int numberOfDecimalPlaces; /// /// Creates a new instance of . /// /// The number of decimal places for the coordinates. /// The original collection of to round /// the coordinates for. /// Thrown when /// is not in range [0, 15]. /// Thrown when /// is null. public RoundedPoint2DCollection(int numberOfDecimalPlaces, IEnumerable originalPoints) { if (originalPoints == null) { throw new ArgumentNullException("originalPoints"); } if (numberOfDecimalPlaces < 0 || numberOfDecimalPlaces > RoundedDouble.MaximumNumberOfDecimalPlaces) { throw new ArgumentOutOfRangeException("numberOfDecimalPlaces", @"Value must be in range [0, 15]."); } points = originalPoints.Select(p => new Point2D( new RoundedDouble(numberOfDecimalPlaces, p.X), new RoundedDouble(numberOfDecimalPlaces, p.Y))); this.numberOfDecimalPlaces = numberOfDecimalPlaces; } /// /// Gets the number of decimal places of the coordinates. /// public int NumberOfDecimalPlaces { get { return numberOfDecimalPlaces; } } public IEnumerator GetEnumerator() { return points.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } }