Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Angle.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under MIT License. See LICENSE.md for details.
3 //
4 // -----------------------------------------------------------------------------
5 // Original code from SlimMath project. http://code.google.com/p/slimmath/
6 // Greetings to SlimDX Group. Original code published with the following license:
7 // -----------------------------------------------------------------------------
8 /*
9 * Copyright (c) 2007-2011 SlimDX Group
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 */
29 using System;
30 using System.Globalization;
31 using SiliconStudio.Core.Serialization;
32 
33 namespace SiliconStudio.Core.Mathematics
34 {
35  /// <summary>
36  /// Represents a unit independant angle using a single-precision floating-point
37  /// internal representation.
38  /// </summary>
39  [DataContract]
40  public struct AngleSingle : IComparable, IComparable<AngleSingle>, IEquatable<AngleSingle>, IFormattable
41  {
42  /// <summary>
43  /// A value that specifies the size of a single degree.
44  /// </summary>
45  public const float Degree = 0.002777777777777778f;
46 
47  /// <summary>
48  /// A value that specifies the size of a single minute.
49  /// </summary>
50  public const float Minute = 0.000046296296296296f;
51 
52  /// <summary>
53  /// A value that specifies the size of a single second.
54  /// </summary>
55  public const float Second = 0.000000771604938272f;
56 
57  /// <summary>
58  /// A value that specifies the size of a single radian.
59  /// </summary>
60  public const float Radian = 0.159154943091895336f;
61 
62  /// <summary>
63  /// A value that specifies the size of a single milliradian.
64  /// </summary>
65  public const float Milliradian = 0.0001591549431f;
66 
67  /// <summary>
68  /// A value that specifies the size of a single gradian.
69  /// </summary>
70  public const float Gradian = 0.0025f;
71 
72  /// <summary>
73  /// The internal representation of the angle.
74  /// </summary>
75  float radians;
76 
77  /// <summary>
78  /// Initializes a new instance of the SiliconStudio.Core.Mathematics.AngleSingle structure with the
79  /// given unit dependant angle and unit type.
80  /// </summary>
81  /// <param name="angle">A unit dependant measure of the angle.</param>
82  /// <param name="type">The type of unit the angle argument is.</param>
83  public AngleSingle(float angle, AngleType type)
84  {
85  switch (type)
86  {
87  case AngleType.Revolution:
88  radians = MathUtil.RevolutionsToRadians(angle);
89  break;
90 
91  case AngleType.Degree:
92  radians = MathUtil.DegreesToRadians(angle);
93  break;
94 
95  case AngleType.Radian:
96  radians = angle;
97  break;
98 
99  case AngleType.Gradian:
100  radians = MathUtil.GradiansToRadians(angle);
101  break;
102 
103  default:
104  radians = 0.0f;
105  break;
106  }
107  }
108 
109  /// <summary>
110  /// Initializes a new instance of the SiliconStudio.Core.Mathematics.AngleSingle structure using the
111  /// arc length formula (θ = s/r).
112  /// </summary>
113  /// <param name="arcLength">The measure of the arc.</param>
114  /// <param name="radius">The radius of the circle.</param>
115  public AngleSingle(float arcLength, float radius)
116  {
117  radians = arcLength / radius;
118  }
119 
120  /// <summary>
121  /// Wraps this SiliconStudio.Core.Mathematics.AngleSingle to be in the range [π, -π].
122  /// </summary>
123  public void Wrap()
124  {
125  float newangle = (float)Math.IEEERemainder(radians, MathUtil.TwoPi);
126 
127  if (newangle <= -MathUtil.Pi)
128  newangle += MathUtil.TwoPi;
129  else if (newangle > MathUtil.Pi)
130  newangle -= MathUtil.TwoPi;
131 
132  radians = newangle;
133  }
134 
135  /// <summary>
136  /// Wraps this SiliconStudio.Core.Mathematics.AngleSingle to be in the range [0, 2π).
137  /// </summary>
138  public void WrapPositive()
139  {
140  float newangle = radians % MathUtil.TwoPi;
141 
142  if (newangle < 0.0)
143  newangle += MathUtil.TwoPi;
144 
145  radians = newangle;
146  }
147 
148  /// <summary>
149  /// Gets or sets the total number of revolutions this SiliconStudio.Core.Mathematics.AngleSingle represents.
150  /// </summary>
151  public float Revolutions
152  {
153  get { return MathUtil.RadiansToRevolutions(radians); }
154  set { radians = MathUtil.RevolutionsToRadians(value); }
155  }
156 
157  /// <summary>
158  /// Gets or sets the total number of degrees this SiliconStudio.Core.Mathematics.AngleSingle represents.
159  /// </summary>
160  public float Degrees
161  {
162  get { return MathUtil.RadiansToDegrees(radians); }
163  set { radians = MathUtil.DegreesToRadians(value); }
164  }
165 
166  /// <summary>
167  /// Gets or sets the minutes component of the degrees this SiliconStudio.Core.Mathematics.AngleSingle represents.
168  /// When setting the minutes, if the value is in the range (-60, 60) the whole degrees are
169  /// not changed; otherwise, the whole degrees may be changed. Fractional values may set
170  /// the seconds component.
171  /// </summary>
172  public float Minutes
173  {
174  get
175  {
176  float degrees = MathUtil.RadiansToDegrees(radians);
177 
178  if (degrees < 0)
179  {
180  float degreesfloor = (float)Math.Ceiling(degrees);
181  return (degrees - degreesfloor) * 60.0f;
182  }
183  else
184  {
185  float degreesfloor = (float)Math.Floor(degrees);
186  return (degrees - degreesfloor) * 60.0f;
187  }
188  }
189  set
190  {
191  float degrees = MathUtil.RadiansToDegrees(radians);
192  float degreesfloor = (float)Math.Floor(degrees);
193 
194  degreesfloor += value / 60.0f;
195  radians = MathUtil.DegreesToRadians(degreesfloor);
196  }
197  }
198 
199  /// <summary>
200  /// Gets or sets the seconds of the degrees this SiliconStudio.Core.Mathematics.AngleSingle represents.
201  /// When setting te seconds, if the value is in the range (-60, 60) the whole minutes
202  /// or whole degrees are not changed; otherwise, the whole minutes or whole degrees
203  /// may be changed.
204  /// </summary>
205  public float Seconds
206  {
207  get
208  {
209  float degrees = MathUtil.RadiansToDegrees(radians);
210 
211  if (degrees < 0)
212  {
213  float degreesfloor = (float)Math.Ceiling(degrees);
214 
215  float minutes = (degrees - degreesfloor) * 60.0f;
216  float minutesfloor = (float)Math.Ceiling(minutes);
217 
218  return (minutes - minutesfloor) * 60.0f;
219  }
220  else
221  {
222  float degreesfloor = (float)Math.Floor(degrees);
223 
224  float minutes = (degrees - degreesfloor) * 60.0f;
225  float minutesfloor = (float)Math.Floor(minutes);
226 
227  return (minutes - minutesfloor) * 60.0f;
228  }
229  }
230  set
231  {
232  float degrees = MathUtil.RadiansToDegrees(radians);
233  float degreesfloor = (float)Math.Floor(degrees);
234 
235  float minutes = (degrees - degreesfloor) * 60.0f;
236  float minutesfloor = (float)Math.Floor(minutes);
237 
238  minutesfloor += value / 60.0f;
239  degreesfloor += minutesfloor / 60.0f;
240  radians = MathUtil.DegreesToRadians(degreesfloor);
241  }
242  }
243 
244  /// <summary>
245  /// Gets or sets the total number of radians this SiliconStudio.Core.Mathematics.AngleSingle represents.
246  /// </summary>
247  public float Radians
248  {
249  get { return radians; }
250  set { radians = value; }
251  }
252 
253  /// <summary>
254  /// Gets or sets the total number of milliradians this SiliconStudio.Core.Mathematics.AngleSingle represents.
255  /// One milliradian is equal to 1/(2000π).
256  /// </summary>
257  public float Milliradians
258  {
259  get { return radians / (Milliradian * MathUtil.TwoPi); }
260  set { radians = value * (Milliradian * MathUtil.TwoPi); }
261  }
262 
263  /// <summary>
264  /// Gets or sets the total number of gradians this SiliconStudio.Core.Mathematics.AngleSingle represents.
265  /// </summary>
266  public float Gradians
267  {
268  get { return MathUtil.RadiansToGradians(radians); }
269  set { radians = MathUtil.RadiansToGradians(value); }
270  }
271 
272  /// <summary>
273  /// Gets a System.Boolean that determines whether this SiliconStudio.Core.Mathematics.Angle
274  /// is a right angle (i.e. 90° or π/2).
275  /// </summary>
276  public bool IsRight
277  {
278  get { return radians == MathUtil.PiOverTwo; }
279  }
280 
281  /// <summary>
282  /// Gets a System.Boolean that determines whether this SiliconStudio.Core.Mathematics.Angle
283  /// is a straight angle (i.e. 180° or π).
284  /// </summary>
285  public bool IsStraight
286  {
287  get { return radians == MathUtil.Pi; }
288  }
289 
290  /// <summary>
291  /// Gets a System.Boolean that determines whether this SiliconStudio.Core.Mathematics.Angle
292  /// is a full rotation angle (i.e. 360° or 2π).
293  /// </summary>
294  public bool IsFullRotation
295  {
296  get { return radians == MathUtil.TwoPi; }
297  }
298 
299  /// <summary>
300  /// Gets a System.Boolean that determines whether this SiliconStudio.Core.Mathematics.Angle
301  /// is an oblique angle (i.e. is not 90° or a multiple of 90°).
302  /// </summary>
303  public bool IsOblique
304  {
305  get { return WrapPositive(this).radians != MathUtil.PiOverTwo; }
306  }
307 
308  /// <summary>
309  /// Gets a System.Boolean that determines whether this SiliconStudio.Core.Mathematics.Angle
310  /// is an acute angle (i.e. less than 90° but greater than 0°).
311  /// </summary>
312  public bool IsAcute
313  {
314  get { return radians > 0.0 && radians < MathUtil.PiOverTwo; }
315  }
316 
317  /// <summary>
318  /// Gets a System.Boolean that determines whether this SiliconStudio.Core.Mathematics.Angle
319  /// is an obtuse angle (i.e. greater than 90° but less than 180°).
320  /// </summary>
321  public bool IsObtuse
322  {
323  get { return radians > MathUtil.PiOverTwo && radians < MathUtil.Pi; }
324  }
325 
326  /// <summary>
327  /// Gets a System.Boolean that determines whether this SiliconStudio.Core.Mathematics.Angle
328  /// is a reflex angle (i.e. greater than 180° but less than 360°).
329  /// </summary>
330  public bool IsReflex
331  {
332  get { return radians > MathUtil.Pi && radians < MathUtil.TwoPi; }
333  }
334 
335  /// <summary>
336  /// Gets a SiliconStudio.Core.Mathematics.AngleSingle instance that complements this angle (i.e. the two angles add to 90°).
337  /// </summary>
338  public AngleSingle Complement
339  {
340  get { return new AngleSingle(MathUtil.PiOverTwo - radians, AngleType.Radian); }
341  }
342 
343  /// <summary>
344  /// Gets a SiliconStudio.Core.Mathematics.AngleSingle instance that supplements this angle (i.e. the two angles add to 180°).
345  /// </summary>
346  public AngleSingle Supplement
347  {
348  get { return new AngleSingle(MathUtil.Pi - radians, AngleType.Radian); }
349  }
350 
351  /// <summary>
352  /// Wraps the SiliconStudio.Core.Mathematics.AngleSingle given in the value argument to be in the range [π, -π].
353  /// </summary>
354  /// <param name="value">A SiliconStudio.Core.Mathematics.AngleSingle to wrap.</param>
355  /// <returns>The SiliconStudio.Core.Mathematics.AngleSingle that is wrapped.</returns>
356  public static AngleSingle Wrap(AngleSingle value)
357  {
358  value.Wrap();
359  return value;
360  }
361 
362  /// <summary>
363  /// Wraps the SiliconStudio.Core.Mathematics.AngleSingle given in the value argument to be in the range [0, 2π).
364  /// </summary>
365  /// <param name="value">A SiliconStudio.Core.Mathematics.AngleSingle to wrap.</param>
366  /// <returns>The SiliconStudio.Core.Mathematics.AngleSingle that is wrapped.</returns>
367  public static AngleSingle WrapPositive(AngleSingle value)
368  {
369  value.WrapPositive();
370  return value;
371  }
372 
373  /// <summary>
374  /// Compares two SiliconStudio.Core.Mathematics.AngleSingle instances and returns the smaller angle.
375  /// </summary>
376  /// <param name="left">The first SiliconStudio.Core.Mathematics.AngleSingle instance to compare.</param>
377  /// <param name="right">The second SiliconStudio.Core.Mathematics.AngleSingle instance to compare.</param>
378  /// <returns>The smaller of the two given SiliconStudio.Core.Mathematics.AngleSingle instances.</returns>
379  public static AngleSingle Min(AngleSingle left, AngleSingle right)
380  {
381  if (left.radians < right.radians)
382  return left;
383 
384  return right;
385  }
386 
387  /// <summary>
388  /// Compares two SiliconStudio.Core.Mathematics.AngleSingle instances and returns the greater angle.
389  /// </summary>
390  /// <param name="left">The first SiliconStudio.Core.Mathematics.AngleSingle instance to compare.</param>
391  /// <param name="right">The second SiliconStudio.Core.Mathematics.AngleSingle instance to compare.</param>
392  /// <returns>The greater of the two given SiliconStudio.Core.Mathematics.AngleSingle instances.</returns>
393  public static AngleSingle Max(AngleSingle left, AngleSingle right)
394  {
395  if (left.radians > right.radians)
396  return left;
397 
398  return right;
399  }
400 
401  /// <summary>
402  /// Adds two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
403  /// </summary>
404  /// <param name="left">The first object to add.</param>
405  /// <param name="right">The second object to add.</param>
406  /// <returns>The value of the two objects added together.</returns>
407  public static AngleSingle Add(AngleSingle left, AngleSingle right)
408  {
409  return new AngleSingle(left.radians + right.radians, AngleType.Radian);
410  }
411 
412  /// <summary>
413  /// Subtracts two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
414  /// </summary>
415  /// <param name="left">The first object to subtract.</param>
416  /// <param name="right">The second object to subtract.</param>
417  /// <returns>The value of the two objects subtracted.</returns>
418  public static AngleSingle Subtract(AngleSingle left, AngleSingle right)
419  {
420  return new AngleSingle(left.radians - right.radians, AngleType.Radian);
421  }
422 
423  /// <summary>
424  /// Multiplies two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
425  /// </summary>
426  /// <param name="left">The first object to multiply.</param>
427  /// <param name="right">The second object to multiply.</param>
428  /// <returns>The value of the two objects multiplied together.</returns>
429  public static AngleSingle Multiply(AngleSingle left, AngleSingle right)
430  {
431  return new AngleSingle(left.radians * right.radians, AngleType.Radian);
432  }
433 
434  /// <summary>
435  /// Divides two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
436  /// </summary>
437  /// <param name="left">The numerator object.</param>
438  /// <param name="right">The denominator object.</param>
439  /// <returns>The value of the two objects divided.</returns>
440  public static AngleSingle Divide(AngleSingle left, AngleSingle right)
441  {
442  return new AngleSingle(left.radians / right.radians, AngleType.Radian);
443  }
444 
445  /// <summary>
446  /// Gets a new SiliconStudio.Core.Mathematics.AngleSingle instance that represents the zero angle (i.e. 0°).
447  /// </summary>
448  public static AngleSingle ZeroAngle
449  {
450  get { return new AngleSingle(0.0f, AngleType.Radian); }
451  }
452 
453  /// <summary>
454  /// Gets a new SiliconStudio.Core.Mathematics.AngleSingle instance that represents the right angle (i.e. 90° or π/2).
455  /// </summary>
456  public static AngleSingle RightAngle
457  {
458  get { return new AngleSingle(MathUtil.PiOverTwo, AngleType.Radian); }
459  }
460 
461  /// <summary>
462  /// Gets a new SiliconStudio.Core.Mathematics.AngleSingle instance that represents the straight angle (i.e. 180° or π).
463  /// </summary>
464  public static AngleSingle StraightAngle
465  {
466  get { return new AngleSingle(MathUtil.Pi, AngleType.Radian); }
467  }
468 
469  /// <summary>
470  /// Gets a new SiliconStudio.Core.Mathematics.AngleSingle instance that represents the full rotation angle (i.e. 360° or 2π).
471  /// </summary>
472  public static AngleSingle FullRotationAngle
473  {
474  get { return new AngleSingle(MathUtil.TwoPi, AngleType.Radian); }
475  }
476 
477  /// <summary>
478  /// Returns a System.Boolean that indicates whether the values of two SiliconStudio.Core.Mathematics.Angle
479  /// objects are equal.
480  /// </summary>
481  /// <param name="left">The first object to compare.</param>
482  /// <param name="right">The second object to compare.</param>
483  /// <returns>True if the left and right parameters have the same value; otherwise, false.</returns>
484  public static bool operator ==(AngleSingle left, AngleSingle right)
485  {
486  return left.radians == right.radians;
487  }
488 
489  /// <summary>
490  /// Returns a System.Boolean that indicates whether the values of two SiliconStudio.Core.Mathematics.Angle
491  /// objects are not equal.
492  /// </summary>
493  /// <param name="left">The first object to compare.</param>
494  /// <param name="right">The second object to compare.</param>
495  /// <returns>True if the left and right parameters do not have the same value; otherwise, false.</returns>
496  public static bool operator !=(AngleSingle left, AngleSingle right)
497  {
498  return left.radians != right.radians;
499  }
500 
501  /// <summary>
502  /// Returns a System.Boolean that indicates whether a SiliconStudio.Core.Mathematics.Angle
503  /// object is less than another SiliconStudio.Core.Mathematics.AngleSingle object.
504  /// </summary>
505  /// <param name="left">The first object to compare.</param>
506  /// <param name="right">The second object to compare.</param>
507  /// <returns>True if left is less than right; otherwise, false.</returns>
508  public static bool operator <(AngleSingle left, AngleSingle right)
509  {
510  return left.radians < right.radians;
511  }
512 
513  /// <summary>
514  /// Returns a System.Boolean that indicates whether a SiliconStudio.Core.Mathematics.Angle
515  /// object is greater than another SiliconStudio.Core.Mathematics.AngleSingle object.
516  /// </summary>
517  /// <param name="left">The first object to compare.</param>
518  /// <param name="right">The second object to compare.</param>
519  /// <returns>True if left is greater than right; otherwise, false.</returns>
520  public static bool operator >(AngleSingle left, AngleSingle right)
521  {
522  return left.radians > right.radians;
523  }
524 
525  /// <summary>
526  /// Returns a System.Boolean that indicates whether a SiliconStudio.Core.Mathematics.Angle
527  /// object is less than or equal to another SiliconStudio.Core.Mathematics.AngleSingle object.
528  /// </summary>
529  /// <param name="left">The first object to compare.</param>
530  /// <param name="right">The second object to compare.</param>
531  /// <returns>True if left is less than or equal to right; otherwise, false.</returns>
532  public static bool operator <=(AngleSingle left, AngleSingle right)
533  {
534  return left.radians <= right.radians;
535  }
536 
537  /// <summary>
538  /// Returns a System.Boolean that indicates whether a SiliconStudio.Core.Mathematics.Angle
539  /// object is greater than or equal to another SiliconStudio.Core.Mathematics.AngleSingle object.
540  /// </summary>
541  /// <param name="left">The first object to compare.</param>
542  /// <param name="right">The second object to compare.</param>
543  /// <returns>True if left is greater than or equal to right; otherwise, false.</returns>
544  public static bool operator >=(AngleSingle left, AngleSingle right)
545  {
546  return left.radians >= right.radians;
547  }
548 
549  /// <summary>
550  /// Returns the value of the SiliconStudio.Core.Mathematics.AngleSingle operand. (The sign of
551  /// the operand is unchanged.)
552  /// </summary>
553  /// <param name="value">A SiliconStudio.Core.Mathematics.AngleSingle object.</param>
554  /// <returns>The value of the value parameter.</returns>
555  public static AngleSingle operator +(AngleSingle value)
556  {
557  return value;
558  }
559 
560  /// <summary>
561  /// Returns the the negated value of the SiliconStudio.Core.Mathematics.AngleSingle operand.
562  /// </summary>
563  /// <param name="value">A SiliconStudio.Core.Mathematics.AngleSingle object.</param>
564  /// <returns>The negated value of the value parameter.</returns>
565  public static AngleSingle operator -(AngleSingle value)
566  {
567  return new AngleSingle(-value.radians, AngleType.Radian);
568  }
569 
570  /// <summary>
571  /// Adds two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
572  /// </summary>
573  /// <param name="left">The first object to add.</param>
574  /// <param name="right">The second object to add.</param>
575  /// <returns>The value of the two objects added together.</returns>
576  public static AngleSingle operator +(AngleSingle left, AngleSingle right)
577  {
578  return new AngleSingle(left.radians + right.radians, AngleType.Radian);
579  }
580 
581  /// <summary>
582  /// Subtracts two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
583  /// </summary>
584  /// <param name="left">The first object to subtract</param>
585  /// <param name="right">The second object to subtract.</param>
586  /// <returns>The value of the two objects subtracted.</returns>
587  public static AngleSingle operator -(AngleSingle left, AngleSingle right)
588  {
589  return new AngleSingle(left.radians - right.radians, AngleType.Radian);
590  }
591 
592  /// <summary>
593  /// Multiplies two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
594  /// </summary>
595  /// <param name="left">The first object to multiply.</param>
596  /// <param name="right">The second object to multiply.</param>
597  /// <returns>The value of the two objects multiplied together.</returns>
598  public static AngleSingle operator *(AngleSingle left, AngleSingle right)
599  {
600  return new AngleSingle(left.radians * right.radians, AngleType.Radian);
601  }
602 
603  /// <summary>
604  /// Divides two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
605  /// </summary>
606  /// <param name="left">The numerator object.</param>
607  /// <param name="right">The denominator object.</param>
608  /// <returns>The value of the two objects divided.</returns>
609  public static AngleSingle operator /(AngleSingle left, AngleSingle right)
610  {
611  return new AngleSingle(left.radians / right.radians, AngleType.Radian);
612  }
613 
614  /// <summary>
615  /// Compares this instance to a specified object and returns an integer that
616  /// indicates whether the value of this instance is less than, equal to, or greater
617  /// than the value of the specified object.
618  /// </summary>
619  /// <param name="other">The object to compare.</param>
620  /// <returns>
621  /// A signed integer that indicates the relationship of the current instance
622  /// to the obj parameter. If the value is less than zero, the current instance
623  /// is less than the other. If the value is zero, the current instance is equal
624  /// to the other. If the value is greater than zero, the current instance is
625  /// greater than the other.
626  /// </returns>
627  public int CompareTo(object other)
628  {
629  if (other == null)
630  return 1;
631 
632  if (!(other is AngleSingle))
633  throw new ArgumentException("Argument must be of type Angle.", "other");
634 
635  float radians = ((AngleSingle)other).radians;
636 
637  if (this.radians > radians)
638  return 1;
639 
640  if (this.radians < radians)
641  return -1;
642 
643  return 0;
644  }
645 
646  /// <summary>
647  /// Compares this instance to a second SiliconStudio.Core.Mathematics.AngleSingle and returns
648  /// an integer that indicates whether the value of this instance is less than,
649  /// equal to, or greater than the value of the specified object.
650  /// </summary>
651  /// <param name="other">The object to compare.</param>
652  /// <returns>
653  /// A signed integer that indicates the relationship of the current instance
654  /// to the obj parameter. If the value is less than zero, the current instance
655  /// is less than the other. If the value is zero, the current instance is equal
656  /// to the other. If the value is greater than zero, the current instance is
657  /// greater than the other.
658  /// </returns>
659  public int CompareTo(AngleSingle other)
660  {
661  if (this.radians > other.radians)
662  return 1;
663 
664  if (this.radians < other.radians)
665  return -1;
666 
667  return 0;
668  }
669 
670  /// <summary>
671  /// Returns a value that indicates whether the current instance and a specified
672  /// SiliconStudio.Core.Mathematics.AngleSingle object have the same value.
673  /// </summary>
674  /// <param name="other">The object to compare.</param>
675  /// <returns>
676  /// Returns true if this SiliconStudio.Core.Mathematics.AngleSingle object and another have the same value;
677  /// otherwise, false.
678  /// </returns>
679  public bool Equals(AngleSingle other)
680  {
681  return this == other;
682  }
683 
684  /// <summary>
685  /// Returns a <see cref="System.String"/> that represents this instance.
686  /// </summary>
687  /// <returns>
688  /// A <see cref="System.String"/> that represents this instance.
689  /// </returns>
690  public override string ToString()
691  {
692  return string.Format(CultureInfo.CurrentCulture, MathUtil.RadiansToDegrees(radians).ToString("0.##°"));
693  }
694 
695  /// <summary>
696  /// Returns a <see cref="System.String"/> that represents this instance.
697  /// </summary>
698  /// <param name="format">The format.</param>
699  /// <returns>
700  /// A <see cref="System.String"/> that represents this instance.
701  /// </returns>
702  public string ToString(string format)
703  {
704  if (format == null)
705  return ToString();
706 
707  return string.Format(CultureInfo.CurrentCulture, "{0}°", MathUtil.RadiansToDegrees(radians).ToString(format, CultureInfo.CurrentCulture));
708  }
709 
710  /// <summary>
711  /// Returns a <see cref="System.String"/> that represents this instance.
712  /// </summary>
713  /// <param name="formatProvider">The format provider.</param>
714  /// <returns>
715  /// A <see cref="System.String"/> that represents this instance.
716  /// </returns>
717  public string ToString(IFormatProvider formatProvider)
718  {
719  return string.Format(formatProvider, MathUtil.RadiansToDegrees(radians).ToString("0.##°"));
720  }
721 
722  /// <summary>
723  /// Returns a <see cref="System.String"/> that represents this instance.
724  /// </summary>
725  /// <param name="format">The format.</param>
726  /// <param name="formatProvider">The format provider.</param>
727  /// <returns>
728  /// A <see cref="System.String"/> that represents this instance.
729  /// </returns>
730  public string ToString(string format, IFormatProvider formatProvider)
731  {
732  if (format == null)
733  return ToString(formatProvider);
734 
735  return string.Format(formatProvider, "{0}°", MathUtil.RadiansToDegrees(radians).ToString(format, CultureInfo.CurrentCulture));
736  }
737 
738  /// <summary>
739  /// Returns a hash code for this SiliconStudio.Core.Mathematics.AngleSingle instance.
740  /// </summary>
741  /// <returns>A 32-bit signed integer hash code.</returns>
742  public override int GetHashCode()
743  {
744  return (int)(BitConverter.DoubleToInt64Bits(radians) % int.MaxValue);
745  }
746 
747  /// <summary>
748  /// Returns a value that indicates whether the current instance and a specified
749  /// object have the same value.
750  /// </summary>
751  /// <param name="obj">The object to compare.</param>
752  /// <returns>
753  /// Returns true if the obj parameter is a SiliconStudio.Core.Mathematics.AngleSingle object or a type
754  /// capable of implicit conversion to a SiliconStudio.Core.Mathematics.AngleSingle value, and
755  /// its value is equal to the value of the current SiliconStudio.Core.Mathematics.Angle
756  /// object; otherwise, false.
757  /// </returns>
758  public override bool Equals(object obj)
759  {
760  return (obj is AngleSingle) && (this == (AngleSingle)obj);
761  }
762  }
763 }
const float PiOverTwo
A value specifying the approximation of π/2 which is 90 degrees.
Definition: MathUtil.cs:58
int CompareTo(object other)
Compares this instance to a specified object and returns an integer that indicates whether the value ...
Definition: Angle.cs:627
const float TwoPi
A value specifying the approximation of 2π which is 360 degrees.
Definition: MathUtil.cs:53
FbxDouble3 operator*(double factor, FbxDouble3 vector)
override string ToString()
Returns a System.String that represents this instance.
Definition: Angle.cs:690
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Definition: Angle.cs:730
void Wrap()
Wraps this SiliconStudio.Core.Mathematics.AngleSingle to be in the range [π, -π]. ...
Definition: Angle.cs:123
int CompareTo(AngleSingle other)
Compares this instance to a second SiliconStudio.Core.Mathematics.AngleSingle and returns an integer ...
Definition: Angle.cs:659
override bool Equals(object obj)
Returns a value that indicates whether the current instance and a specified object have the same valu...
Definition: Angle.cs:758
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
Definition: Angle.cs:717
void WrapPositive()
Wraps this SiliconStudio.Core.Mathematics.AngleSingle to be in the range [0, 2π). ...
Definition: Angle.cs:138
override int GetHashCode()
Returns a hash code for this SiliconStudio.Core.Mathematics.AngleSingle instance. ...
Definition: Angle.cs:742
Specifies an angle measurement in degrees.
const float Pi
A value specifying the approximation of π which is 180 degrees.
Definition: MathUtil.cs:48
string ToString(string format)
Returns a System.String that represents this instance.
Definition: Angle.cs:702
Specifies an angle measurement in radians.
static AngleSingle WrapPositive(AngleSingle value)
Wraps the SiliconStudio.Core.Mathematics.AngleSingle given in the value argument to be in the range [...
Definition: Angle.cs:367
AngleSingle(float angle, AngleType type)
Initializes a new instance of the SiliconStudio.Core.Mathematics.AngleSingle structure with the given...
Definition: Angle.cs:83
bool Equals(AngleSingle other)
Returns a value that indicates whether the current instance and a specified SiliconStudio.Core.Mathematics.AngleSingle object have the same value.
Definition: Angle.cs:679
AngleSingle(float arcLength, float radius)
Initializes a new instance of the SiliconStudio.Core.Mathematics.AngleSingle structure using the arc ...
Definition: Angle.cs:115
static AngleSingle Add(AngleSingle left, AngleSingle right)
Adds two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
Definition: Angle.cs:407
static AngleSingle Wrap(AngleSingle value)
Wraps the SiliconStudio.Core.Mathematics.AngleSingle given in the value argument to be in the range [...
Definition: Angle.cs:356
AngleType
Describes the type of angle.
Definition: AngleType.cs:34
float radians
The internal representation of the angle.
Definition: Angle.cs:75
Represents a unit independant angle using a single-precision floating-point internal representation...
Definition: Angle.cs:40
static AngleSingle Subtract(AngleSingle left, AngleSingle right)
Subtracts two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
Definition: Angle.cs:418
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175
static AngleSingle Max(AngleSingle left, AngleSingle right)
Compares two SiliconStudio.Core.Mathematics.AngleSingle instances and returns the greater angle...
Definition: Angle.cs:393
static AngleSingle Multiply(AngleSingle left, AngleSingle right)
Multiplies two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result...
Definition: Angle.cs:429
static AngleSingle Divide(AngleSingle left, AngleSingle right)
Divides two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
Definition: Angle.cs:440
Specifies an angle measurement in gradians.
static AngleSingle Min(AngleSingle left, AngleSingle right)
Compares two SiliconStudio.Core.Mathematics.AngleSingle instances and returns the smaller angle...
Definition: Angle.cs:379