2021-07-21 06:36:34 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System ;
#nullable enable
namespace osu.Game.Rulesets.Catch.Edit
{
/// <summary>
2021-07-22 04:28:40 +00:00
/// Represents either the empty range or a closed interval of horizontal positions in the playfield.
/// A <see cref="PositionRange"/> represents a closed interval if it is <see cref="Min"/> <= <see cref="Max"/>, and represents the empty range otherwise.
2021-07-21 06:36:34 +00:00
/// </summary>
public readonly struct PositionRange
{
public readonly float Min ;
public readonly float Max ;
2021-07-22 04:28:40 +00:00
public float Length = > Math . Max ( 0 , Max - Min ) ;
2021-07-22 04:06:48 +00:00
2021-07-21 06:36:34 +00:00
public PositionRange ( float value )
: this ( value , value )
{
}
public PositionRange ( float min , float max )
{
Min = min ;
Max = max ;
}
public static PositionRange Union ( PositionRange a , PositionRange b ) = > new PositionRange ( Math . Min ( a . Min , b . Min ) , Math . Max ( a . Max , b . Max ) ) ;
2021-07-22 04:28:40 +00:00
/// <summary>
/// Get the given position flipped (mirrored) for the axis at the center of this range.
/// Returns the given position unchanged if the range was empty.
/// </summary>
public float GetFlippedPosition ( float x ) = > Min < = Max ? Max - ( x - Min ) : x ;
2021-07-21 06:47:16 +00:00
2021-07-21 06:36:34 +00:00
public static readonly PositionRange EMPTY = new PositionRange ( float . PositiveInfinity , float . NegativeInfinity ) ;
}
}