forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurveKey.cs
201 lines (171 loc) · 7.16 KB
/
CurveKey.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// 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 Microsoft.Xna.Framework
{
/// <summary>
/// Key point on the <see cref="Curve"/>.
/// </summary>
// TODO : [TypeConverter(typeof(ExpandableObjectConverter))]
[DataContract]
public class CurveKey : IEquatable<CurveKey>, IComparable<CurveKey>
{
#region Private Fields
private CurveContinuity _continuity;
private readonly float _position;
private float _tangentIn;
private float _tangentOut;
private float _value;
#endregion
#region Properties
/// <summary>
/// Gets or sets the indicator whether the segment between this point and the next point on the curve is discrete or continuous.
/// </summary>
[DataMember]
public CurveContinuity Continuity
{
get { return this._continuity; }
set { this._continuity = value; }
}
/// <summary>
/// Gets a position of the key on the curve.
/// </summary>
[DataMember]
public float Position
{
get { return this._position; }
}
/// <summary>
/// Gets or sets a tangent when approaching this point from the previous point on the curve.
/// </summary>
[DataMember]
public float TangentIn
{
get { return this._tangentIn; }
set { this._tangentIn = value; }
}
/// <summary>
/// Gets or sets a tangent when leaving this point to the next point on the curve.
/// </summary>
[DataMember]
public float TangentOut
{
get { return this._tangentOut; }
set { this._tangentOut = value; }
}
/// <summary>
/// Gets a value of this point.
/// </summary>
[DataMember]
public float Value
{
get { return this._value; }
set { this._value = value; }
}
#endregion
#region Constructors
/// <summary>
/// Creates a new instance of <see cref="CurveKey"/> class with position: 0 and value: 0.
/// </summary>
public CurveKey() : this(0, 0)
{
// This parameterless constructor is needed for correct serialization of CurveKeyCollection and CurveKey.
}
/// <summary>
/// Creates a new instance of <see cref="CurveKey"/> class.
/// </summary>
/// <param name="position">Position on the curve.</param>
/// <param name="value">Value of the control point.</param>
public CurveKey(float position, float value)
: this(position, value, 0, 0, CurveContinuity.Smooth)
{
}
/// <summary>
/// Creates a new instance of <see cref="CurveKey"/> class.
/// </summary>
/// <param name="position">Position on the curve.</param>
/// <param name="value">Value of the control point.</param>
/// <param name="tangentIn">Tangent approaching point from the previous point on the curve.</param>
/// <param name="tangentOut">Tangent leaving point toward next point on the curve.</param>
public CurveKey(float position, float value, float tangentIn, float tangentOut)
: this(position, value, tangentIn, tangentOut, CurveContinuity.Smooth)
{
}
/// <summary>
/// Creates a new instance of <see cref="CurveKey"/> class.
/// </summary>
/// <param name="position">Position on the curve.</param>
/// <param name="value">Value of the control point.</param>
/// <param name="tangentIn">Tangent approaching point from the previous point on the curve.</param>
/// <param name="tangentOut">Tangent leaving point toward next point on the curve.</param>
/// <param name="continuity">Indicates whether the curve is discrete or continuous.</param>
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
/// <summary>
///
/// Compares whether two <see cref="CurveKey"/> instances are not equal.
/// </summary>
/// <param name="value1"><see cref="CurveKey"/> instance on the left of the not equal sign.</param>
/// <param name="value2"><see cref="CurveKey"/> instance on the right of the not equal sign.</param>
/// <returns><c>true</c> if the instances are not equal; <c>false</c> otherwise.</returns>
public static bool operator !=(CurveKey value1, CurveKey value2)
{
return !(value1 == value2);
}
/// <summary>
/// Compares whether two <see cref="CurveKey"/> instances are equal.
/// </summary>
/// <param name="value1"><see cref="CurveKey"/> instance on the left of the equal sign.</param>
/// <param name="value2"><see cref="CurveKey"/> instance on the right of the equal sign.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
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);
}
/// <summary>
/// Creates a copy of this key.
/// </summary>
/// <returns>A copy of this key.</returns>
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
}
}