// Copyright (C) Stichting Deltares 2017. 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 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 General Public License for more details. // // You should have received a copy of the GNU 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 Core.Common.Base.Data; using Core.Common.Base.Geometry; using Ringtoets.Common.Data.Hydraulics; namespace Ringtoets.Common.Forms.PresentationObjects { /// /// Class that represents a with respect to a reference point. /// public class SelectableHydraulicBoundaryLocation { /// /// Creates a new instance of . /// /// The . /// A reference point to which the distance of /// needs to be calculated. /// Thrown when /// is null. /// The distance between and its reference point is defined as /// when is null. public SelectableHydraulicBoundaryLocation(HydraulicBoundaryLocation hydraulicBoundaryLocation, Point2D referencePoint) { if (hydraulicBoundaryLocation == null) { throw new ArgumentNullException(nameof(hydraulicBoundaryLocation)); } HydraulicBoundaryLocation = hydraulicBoundaryLocation; Distance = new RoundedDouble(0, referencePoint?.GetEuclideanDistanceTo(hydraulicBoundaryLocation.Location) ?? double.NaN); } /// /// Gets the hydraulic boundary location. /// public HydraulicBoundaryLocation HydraulicBoundaryLocation { get; } /// /// Gets the distance between the and the given reference point. /// [m] /// The value will be in case there's no reference point specified. /// public RoundedDouble Distance { get; } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } if (obj.GetType() != GetType()) { return false; } return Equals((SelectableHydraulicBoundaryLocation) obj); } public override int GetHashCode() { return HydraulicBoundaryLocation.GetHashCode(); } public override string ToString() { if (double.IsNaN(Distance)) { return HydraulicBoundaryLocation.Name; } return Distance < 1000 ? string.Format("{0} ({1:f0} m)", HydraulicBoundaryLocation.Name, Distance) : string.Format("{0} ({1:f1} km)", HydraulicBoundaryLocation.Name, Distance / 1000); } private bool Equals(SelectableHydraulicBoundaryLocation other) { return Equals(HydraulicBoundaryLocation, other.HydraulicBoundaryLocation); } } }