// 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 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;
namespace Core.Components.OxyPlot.Forms
{
///
/// Class for helping determine new extents for the plot view.
///
internal class Extent
{
///
/// Creates a new instance of .
///
/// The smallest x value.
/// The largest x value.
/// The smallest y value.
/// The largest y value.
public Extent(double xMin, double xMax, double yMin, double yMax)
{
XMin = xMin;
XMax = xMax;
YMin = yMin;
YMax = yMax;
}
///
/// Creates a new instance of without values for
/// the properties.
///
public Extent()
{
XMin = double.NaN;
XMax = double.NaN;
YMin = double.NaN;
YMax = double.NaN;
}
///
/// Gets the smallest x value.
///
public double XMin { get; private set; }
///
/// Gets the largest x value.
///
public double XMax { get; private set; }
///
/// Gets the smallest y value.
///
public double YMin { get; private set; }
///
/// Gets the largest y value.
///
public double YMax { get; private set; }
///
/// Adds padding to the extent and returns the new
/// extent.
///
/// The padding to add.
/// A new extent with padding added
/// to the property values.
public Extent AddPadding(double padding)
{
double xPadding = (XMax - XMin) * padding;
double yPadding = (YMax - YMin) * padding;
return new Extent
{
XMin = XMin - xPadding,
XMax = XMax + xPadding,
YMin = YMin - yPadding,
YMax = YMax + yPadding,
};
}
///
/// Gets a value indicating whether values were
/// given to the properties.
///
public bool IsNaN
{
get
{
return double.IsNaN(XMin)
|| double.IsNaN(XMax)
|| double.IsNaN(YMin)
|| double.IsNaN(YMax);
}
}
///
/// Assigns new values to the properties in such a way
/// that the new values include both the
/// and the .
///
/// The other extent to include in
/// the .
public void ExpandToInclude(Extent otherExtent)
{
if (otherExtent.IsNaN)
{
return;
}
XMin = double.IsNaN(XMin) ? otherExtent.XMin : Math.Min(XMin, otherExtent.XMin);
XMax = double.IsNaN(XMax) ? otherExtent.XMax : Math.Max(XMax, otherExtent.XMax);
YMin = double.IsNaN(YMin) ? otherExtent.YMin : Math.Min(YMin, otherExtent.YMin);
YMax = double.IsNaN(YMax) ? otherExtent.YMax : Math.Max(YMax, otherExtent.YMax);
}
}
}