// MIT License - Copyright (C) The Mono.Xna Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.ComponentModel;
using System.Runtime.Serialization;
namespace CommonLang.Geometry
{
///
/// Key point on the .
///
// TODO : [TypeConverter(typeof(ExpandableObjectConverter))]
public class CurveKey : IEquatable, IComparable
{
#region Private Fields
private CurveContinuity _continuity;
private readonly float _position;
private float _tangentIn;
private float _tangentOut;
private float _value;
#endregion
#region Properties
///
/// Gets or sets the indicator whether the segment between this point and the next point on the curve is discrete or continuous.
///
public CurveContinuity Continuity
{
get { return this._continuity; }
set { this._continuity = value; }
}
///
/// Gets a position of the key on the curve.
///
public float Position
{
get { return this._position; }
}
///
/// Gets or sets a tangent when approaching this point from the previous point on the curve.
///
public float TangentIn
{
get { return this._tangentIn; }
set { this._tangentIn = value; }
}
///
/// Gets or sets a tangent when leaving this point to the next point on the curve.
///
public float TangentOut
{
get { return this._tangentOut; }
set { this._tangentOut = value; }
}
///
/// Gets a value of this point.
///
public float Value
{
get { return this._value; }
set { this._value = value; }
}
#endregion
#region Constructors
///
/// Creates a new instance of class with position: 0 and value: 0.
///
public CurveKey() : this(0, 0)
{
// This parameterless constructor is needed for correct serialization of CurveKeyCollection and CurveKey.
}
///
/// Creates a new instance of class.
///
/// Position on the curve.
/// Value of the control point.
public CurveKey(float position, float value)
: this(position, value, 0, 0, CurveContinuity.Smooth)
{
}
///
/// Creates a new instance of class.
///
/// Position on the curve.
/// Value of the control point.
/// Tangent approaching point from the previous point on the curve.
/// Tangent leaving point toward next point on the curve.
public CurveKey(float position, float value, float tangentIn, float tangentOut)
: this(position, value, tangentIn, tangentOut, CurveContinuity.Smooth)
{
}
///
/// Creates a new instance of class.
///
/// Position on the curve.
/// Value of the control point.
/// Tangent approaching point from the previous point on the curve.
/// Tangent leaving point toward next point on the curve.
/// Indicates whether the curve is discrete or continuous.
public CurveKey(float position, float value, float tangentIn, float tangentOut, CurveContinuity continuity)
{
this._position = position;
this._value = value;
this._tangentIn = tangentIn;
this._tangentOut = tangentOut;
this._continuity = continuity;
}
#endregion
///
///
/// Compares whether two instances are not equal.
///
/// instance on the left of the not equal sign.
/// instance on the right of the not equal sign.
/// true if the instances are not equal; false otherwise.
public static bool operator !=(CurveKey value1, CurveKey value2)
{
return !(value1 == value2);
}
///
/// Compares whether two instances are equal.
///
/// instance on the left of the equal sign.
/// instance on the right of the equal sign.
/// true if the instances are equal; false otherwise.
public static bool operator ==(CurveKey value1, CurveKey value2)
{
if (object.Equals(value1, null))
return object.Equals(value2, null);
if (object.Equals(value2, null))
return object.Equals(value1, null);
return (value1._position == value2._position)
&& (value1._value == value2._value)
&& (value1._tangentIn == value2._tangentIn)
&& (value1._tangentOut == value2._tangentOut)
&& (value1._continuity == value2._continuity);
}
///
/// Creates a copy of this key.
///
/// A copy of this key.
public CurveKey Clone()
{
return new CurveKey(this._position, this._value, this._tangentIn, this._tangentOut, this._continuity);
}
#region Inherited Methods
public int CompareTo(CurveKey other)
{
return this._position.CompareTo(other._position);
}
public bool Equals(CurveKey other)
{
return (this == other);
}
public override bool Equals(object obj)
{
return (obj as CurveKey) != null && Equals((CurveKey)obj);
}
public override int GetHashCode()
{
return this._position.GetHashCode() ^ this._value.GetHashCode() ^ this._tangentIn.GetHashCode() ^
this._tangentOut.GetHashCode() ^ this._continuity.GetHashCode();
}
#endregion
}
}