-
-
Notifications
You must be signed in to change notification settings - Fork 911
/
AngleSingle.cs
778 lines (690 loc) · 31 KB
/
AngleSingle.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
//
// -----------------------------------------------------------------------------
// Original code from SlimMath project. http://code.google.com/p/slimmath/
// Greetings to SlimDX Group. Original code published with the following license:
// -----------------------------------------------------------------------------
/*
* Copyright (c) 2007-2011 SlimDX Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
using System;
using System.Globalization;
namespace Stride.Core.Mathematics
{
/// <summary>
/// Represents a unit independant angle using a single-precision floating-point
/// internal representation.
/// </summary>
[DataStyle(DataStyle.Compact)]
[DataContract]
public struct AngleSingle : IComparable, IComparable<AngleSingle>, IEquatable<AngleSingle>, IFormattable
{
/// <summary>
/// A value that specifies the size of a single degree.
/// </summary>
public const float Degree = 0.002777777777777778f;
/// <summary>
/// A value that specifies the size of a single minute.
/// </summary>
public const float Minute = 0.000046296296296296f;
/// <summary>
/// A value that specifies the size of a single second.
/// </summary>
public const float Second = 0.000000771604938272f;
/// <summary>
/// A value that specifies the size of a single radian.
/// </summary>
public const float Radian = 0.159154943091895336f;
/// <summary>
/// A value that specifies the size of a single milliradian.
/// </summary>
public const float Milliradian = 0.0001591549431f;
/// <summary>
/// A value that specifies the size of a single gradian.
/// </summary>
public const float Gradian = 0.0025f;
/// <summary>
/// The internal representation of the angle.
/// </summary>
private float radians;
/// <summary>
/// Initializes a new instance of the <see cref="AngleSingle"/> struct with the
/// given unit dependant angle and unit type.
/// </summary>
/// <param name="angle">A unit dependant measure of the angle.</param>
/// <param name="type">The type of unit the angle argument is.</param>
public AngleSingle(float angle, AngleType type)
{
switch (type)
{
case AngleType.Revolution:
radians = MathUtil.RevolutionsToRadians(angle);
break;
case AngleType.Degree:
radians = MathUtil.DegreesToRadians(angle);
break;
case AngleType.Radian:
radians = angle;
break;
case AngleType.Gradian:
radians = MathUtil.GradiansToRadians(angle);
break;
default:
radians = 0.0f;
break;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="AngleSingle"/> struct using the
/// arc length formula (θ = s/r).
/// </summary>
/// <param name="arcLength">The measure of the arc.</param>
/// <param name="radius">The radius of the circle.</param>
public AngleSingle(float arcLength, float radius)
{
radians = arcLength / radius;
}
/// <summary>
/// Wraps this Stride.Core.Mathematics.AngleSingle to be in the range [π, -π].
/// </summary>
public void Wrap()
{
float newangle = (float)Math.IEEERemainder(radians, MathUtil.TwoPi);
if (newangle <= -MathUtil.Pi)
newangle += MathUtil.TwoPi;
else if (newangle > MathUtil.Pi)
newangle -= MathUtil.TwoPi;
radians = newangle;
}
/// <summary>
/// Wraps this Stride.Core.Mathematics.AngleSingle to be in the range [0, 2π).
/// </summary>
public void WrapPositive()
{
float newangle = radians % MathUtil.TwoPi;
if (newangle < 0.0)
newangle += MathUtil.TwoPi;
radians = newangle;
}
/// <summary>
/// Gets or sets the total number of revolutions this Stride.Core.Mathematics.AngleSingle represents.
/// </summary>
[DataMemberIgnore]
public float Revolutions
{
get { return MathUtil.RadiansToRevolutions(radians); }
set { radians = MathUtil.RevolutionsToRadians(value); }
}
/// <summary>
/// Gets or sets the total number of degrees this Stride.Core.Mathematics.AngleSingle represents.
/// </summary>
[DataMemberIgnore]
public float Degrees
{
get { return MathUtil.RadiansToDegrees(radians); }
set { radians = MathUtil.DegreesToRadians(value); }
}
/// <summary>
/// Gets or sets the minutes component of the degrees this Stride.Core.Mathematics.AngleSingle represents.
/// When setting the minutes, if the value is in the range (-60, 60) the whole degrees are
/// not changed; otherwise, the whole degrees may be changed. Fractional values may set
/// the seconds component.
/// </summary>
[DataMemberIgnore]
public float Minutes
{
get
{
float degrees = MathUtil.RadiansToDegrees(radians);
if (degrees < 0)
{
float degreesfloor = (float)Math.Ceiling(degrees);
return (degrees - degreesfloor) * 60.0f;
}
else
{
float degreesfloor = (float)Math.Floor(degrees);
return (degrees - degreesfloor) * 60.0f;
}
}
set
{
float degrees = MathUtil.RadiansToDegrees(radians);
float degreesfloor = (float)Math.Floor(degrees);
degreesfloor += value / 60.0f;
radians = MathUtil.DegreesToRadians(degreesfloor);
}
}
/// <summary>
/// Gets or sets the seconds of the degrees this Stride.Core.Mathematics.AngleSingle represents.
/// When setting te seconds, if the value is in the range (-60, 60) the whole minutes
/// or whole degrees are not changed; otherwise, the whole minutes or whole degrees
/// may be changed.
/// </summary>
[DataMemberIgnore]
public float Seconds
{
get
{
float degrees = MathUtil.RadiansToDegrees(radians);
if (degrees < 0)
{
float degreesfloor = (float)Math.Ceiling(degrees);
float minutes = (degrees - degreesfloor) * 60.0f;
float minutesfloor = (float)Math.Ceiling(minutes);
return (minutes - minutesfloor) * 60.0f;
}
else
{
float degreesfloor = (float)Math.Floor(degrees);
float minutes = (degrees - degreesfloor) * 60.0f;
float minutesfloor = (float)Math.Floor(minutes);
return (minutes - minutesfloor) * 60.0f;
}
}
set
{
float degrees = MathUtil.RadiansToDegrees(radians);
float degreesfloor = (float)Math.Floor(degrees);
float minutes = (degrees - degreesfloor) * 60.0f;
float minutesfloor = (float)Math.Floor(minutes);
minutesfloor += value / 60.0f;
degreesfloor += minutesfloor / 60.0f;
radians = MathUtil.DegreesToRadians(degreesfloor);
}
}
/// <summary>
/// Gets or sets the total number of radians this Stride.Core.Mathematics.AngleSingle represents.
/// </summary>
public float Radians
{
get { return radians; }
set { radians = value; }
}
/// <summary>
/// Gets or sets the total number of milliradians this Stride.Core.Mathematics.AngleSingle represents.
/// One milliradian is equal to 1/(2000π).
/// </summary>
[DataMemberIgnore]
public float Milliradians
{
get { return radians / (Milliradian * MathUtil.TwoPi); }
set { radians = value * (Milliradian * MathUtil.TwoPi); }
}
/// <summary>
/// Gets or sets the total number of gradians this Stride.Core.Mathematics.AngleSingle represents.
/// </summary>
[DataMemberIgnore]
public float Gradians
{
get { return MathUtil.RadiansToGradians(radians); }
set { radians = MathUtil.GradiansToRadians(value); }
}
/// <summary>
/// Gets a System.Boolean that determines whether this Stride.Core.Mathematics.Angle
/// is a right angle (i.e. 90° or π/2).
/// </summary>
[DataMemberIgnore]
public bool IsRight
{
get { return radians == MathUtil.PiOverTwo; }
}
/// <summary>
/// Gets a System.Boolean that determines whether this Stride.Core.Mathematics.Angle
/// is a straight angle (i.e. 180° or π).
/// </summary>
[DataMemberIgnore]
public bool IsStraight
{
get { return radians == MathUtil.Pi; }
}
/// <summary>
/// Gets a System.Boolean that determines whether this Stride.Core.Mathematics.Angle
/// is a full rotation angle (i.e. 360° or 2π).
/// </summary>
[DataMemberIgnore]
public bool IsFullRotation
{
get { return radians == MathUtil.TwoPi; }
}
/// <summary>
/// Gets a System.Boolean that determines whether this Stride.Core.Mathematics.Angle
/// is an oblique angle (i.e. is not 90° or a multiple of 90°).
/// </summary>
[DataMemberIgnore]
public bool IsOblique
{
get { return WrapPositive(this).radians != MathUtil.PiOverTwo; }
}
/// <summary>
/// Gets a System.Boolean that determines whether this Stride.Core.Mathematics.Angle
/// is an acute angle (i.e. less than 90° but greater than 0°).
/// </summary>
[DataMemberIgnore]
public bool IsAcute
{
get { return radians > 0.0 && radians < MathUtil.PiOverTwo; }
}
/// <summary>
/// Gets a System.Boolean that determines whether this Stride.Core.Mathematics.Angle
/// is an obtuse angle (i.e. greater than 90° but less than 180°).
/// </summary>
[DataMemberIgnore]
public bool IsObtuse
{
get { return radians > MathUtil.PiOverTwo && radians < MathUtil.Pi; }
}
/// <summary>
/// Gets a System.Boolean that determines whether this Stride.Core.Mathematics.Angle
/// is a reflex angle (i.e. greater than 180° but less than 360°).
/// </summary>
[DataMemberIgnore]
public bool IsReflex
{
get { return radians > MathUtil.Pi && radians < MathUtil.TwoPi; }
}
/// <summary>
/// Gets a Stride.Core.Mathematics.AngleSingle instance that complements this angle (i.e. the two angles add to 90°).
/// </summary>
[DataMemberIgnore]
public AngleSingle Complement
{
get { return new AngleSingle(MathUtil.PiOverTwo - radians, AngleType.Radian); }
}
/// <summary>
/// Gets a Stride.Core.Mathematics.AngleSingle instance that supplements this angle (i.e. the two angles add to 180°).
/// </summary>
[DataMemberIgnore]
public AngleSingle Supplement
{
get { return new AngleSingle(MathUtil.Pi - radians, AngleType.Radian); }
}
/// <summary>
/// Wraps the Stride.Core.Mathematics.AngleSingle given in the value argument to be in the range [π, -π].
/// </summary>
/// <param name="value">A Stride.Core.Mathematics.AngleSingle to wrap.</param>
/// <returns>The Stride.Core.Mathematics.AngleSingle that is wrapped.</returns>
public static AngleSingle Wrap(AngleSingle value)
{
value.Wrap();
return value;
}
/// <summary>
/// Wraps the Stride.Core.Mathematics.AngleSingle given in the value argument to be in the range [0, 2π).
/// </summary>
/// <param name="value">A Stride.Core.Mathematics.AngleSingle to wrap.</param>
/// <returns>The Stride.Core.Mathematics.AngleSingle that is wrapped.</returns>
public static AngleSingle WrapPositive(AngleSingle value)
{
value.WrapPositive();
return value;
}
/// <summary>
/// Compares two Stride.Core.Mathematics.AngleSingle instances and returns the smaller angle.
/// </summary>
/// <param name="left">The first Stride.Core.Mathematics.AngleSingle instance to compare.</param>
/// <param name="right">The second Stride.Core.Mathematics.AngleSingle instance to compare.</param>
/// <returns>The smaller of the two given Stride.Core.Mathematics.AngleSingle instances.</returns>
public static AngleSingle Min(AngleSingle left, AngleSingle right)
{
if (left.radians < right.radians)
return left;
return right;
}
/// <summary>
/// Compares two Stride.Core.Mathematics.AngleSingle instances and returns the greater angle.
/// </summary>
/// <param name="left">The first Stride.Core.Mathematics.AngleSingle instance to compare.</param>
/// <param name="right">The second Stride.Core.Mathematics.AngleSingle instance to compare.</param>
/// <returns>The greater of the two given Stride.Core.Mathematics.AngleSingle instances.</returns>
public static AngleSingle Max(AngleSingle left, AngleSingle right)
{
if (left.radians > right.radians)
return left;
return right;
}
/// <summary>
/// Adds two Stride.Core.Mathematics.AngleSingle objects and returns the result.
/// </summary>
/// <param name="left">The first object to add.</param>
/// <param name="right">The second object to add.</param>
/// <returns>The value of the two objects added together.</returns>
public static AngleSingle Add(AngleSingle left, AngleSingle right)
{
return new AngleSingle(left.radians + right.radians, AngleType.Radian);
}
/// <summary>
/// Subtracts two Stride.Core.Mathematics.AngleSingle objects and returns the result.
/// </summary>
/// <param name="left">The first object to subtract.</param>
/// <param name="right">The second object to subtract.</param>
/// <returns>The value of the two objects subtracted.</returns>
public static AngleSingle Subtract(AngleSingle left, AngleSingle right)
{
return new AngleSingle(left.radians - right.radians, AngleType.Radian);
}
/// <summary>
/// Multiplies two Stride.Core.Mathematics.AngleSingle objects and returns the result.
/// </summary>
/// <param name="left">The first object to multiply.</param>
/// <param name="right">The second object to multiply.</param>
/// <returns>The value of the two objects multiplied together.</returns>
public static AngleSingle Multiply(AngleSingle left, AngleSingle right)
{
return new AngleSingle(left.radians * right.radians, AngleType.Radian);
}
/// <summary>
/// Divides two Stride.Core.Mathematics.AngleSingle objects and returns the result.
/// </summary>
/// <param name="left">The numerator object.</param>
/// <param name="right">The denominator object.</param>
/// <returns>The value of the two objects divided.</returns>
public static AngleSingle Divide(AngleSingle left, AngleSingle right)
{
return new AngleSingle(left.radians / right.radians, AngleType.Radian);
}
/// <summary>
/// Gets a new Stride.Core.Mathematics.AngleSingle instance that represents the zero angle (i.e. 0°).
/// </summary>
public static AngleSingle ZeroAngle
{
get { return new AngleSingle(0.0f, AngleType.Radian); }
}
/// <summary>
/// Gets a new Stride.Core.Mathematics.AngleSingle instance that represents the right angle (i.e. 90° or π/2).
/// </summary>
public static AngleSingle RightAngle
{
get { return new AngleSingle(MathUtil.PiOverTwo, AngleType.Radian); }
}
/// <summary>
/// Gets a new Stride.Core.Mathematics.AngleSingle instance that represents the straight angle (i.e. 180° or π).
/// </summary>
public static AngleSingle StraightAngle
{
get { return new AngleSingle(MathUtil.Pi, AngleType.Radian); }
}
/// <summary>
/// Gets a new Stride.Core.Mathematics.AngleSingle instance that represents the full rotation angle (i.e. 360° or 2π).
/// </summary>
public static AngleSingle FullRotationAngle
{
get { return new AngleSingle(MathUtil.TwoPi, AngleType.Radian); }
}
/// <summary>
/// Returns a System.Boolean that indicates whether the values of two Stride.Core.Mathematics.Angle
/// objects are equal.
/// </summary>
/// <param name="left">The first object to compare.</param>
/// <param name="right">The second object to compare.</param>
/// <returns>True if the left and right parameters have the same value; otherwise, false.</returns>
public static bool operator ==(AngleSingle left, AngleSingle right)
{
return left.radians == right.radians;
}
/// <summary>
/// Returns a System.Boolean that indicates whether the values of two Stride.Core.Mathematics.Angle
/// objects are not equal.
/// </summary>
/// <param name="left">The first object to compare.</param>
/// <param name="right">The second object to compare.</param>
/// <returns>True if the left and right parameters do not have the same value; otherwise, false.</returns>
public static bool operator !=(AngleSingle left, AngleSingle right)
{
return left.radians != right.radians;
}
/// <summary>
/// Returns a System.Boolean that indicates whether a Stride.Core.Mathematics.Angle
/// object is less than another Stride.Core.Mathematics.AngleSingle object.
/// </summary>
/// <param name="left">The first object to compare.</param>
/// <param name="right">The second object to compare.</param>
/// <returns>True if left is less than right; otherwise, false.</returns>
public static bool operator <(AngleSingle left, AngleSingle right)
{
return left.radians < right.radians;
}
/// <summary>
/// Returns a System.Boolean that indicates whether a Stride.Core.Mathematics.Angle
/// object is greater than another Stride.Core.Mathematics.AngleSingle object.
/// </summary>
/// <param name="left">The first object to compare.</param>
/// <param name="right">The second object to compare.</param>
/// <returns>True if left is greater than right; otherwise, false.</returns>
public static bool operator >(AngleSingle left, AngleSingle right)
{
return left.radians > right.radians;
}
/// <summary>
/// Returns a System.Boolean that indicates whether a Stride.Core.Mathematics.Angle
/// object is less than or equal to another Stride.Core.Mathematics.AngleSingle object.
/// </summary>
/// <param name="left">The first object to compare.</param>
/// <param name="right">The second object to compare.</param>
/// <returns>True if left is less than or equal to right; otherwise, false.</returns>
public static bool operator <=(AngleSingle left, AngleSingle right)
{
return left.radians <= right.radians;
}
/// <summary>
/// Returns a System.Boolean that indicates whether a Stride.Core.Mathematics.Angle
/// object is greater than or equal to another Stride.Core.Mathematics.AngleSingle object.
/// </summary>
/// <param name="left">The first object to compare.</param>
/// <param name="right">The second object to compare.</param>
/// <returns>True if left is greater than or equal to right; otherwise, false.</returns>
public static bool operator >=(AngleSingle left, AngleSingle right)
{
return left.radians >= right.radians;
}
/// <summary>
/// Returns the value of the Stride.Core.Mathematics.AngleSingle operand. (The sign of
/// the operand is unchanged.)
/// </summary>
/// <param name="value">A Stride.Core.Mathematics.AngleSingle object.</param>
/// <returns>The value of the value parameter.</returns>
public static AngleSingle operator +(AngleSingle value)
{
return value;
}
/// <summary>
/// Returns the the negated value of the Stride.Core.Mathematics.AngleSingle operand.
/// </summary>
/// <param name="value">A Stride.Core.Mathematics.AngleSingle object.</param>
/// <returns>The negated value of the value parameter.</returns>
public static AngleSingle operator -(AngleSingle value)
{
return new AngleSingle(-value.radians, AngleType.Radian);
}
/// <summary>
/// Adds two Stride.Core.Mathematics.AngleSingle objects and returns the result.
/// </summary>
/// <param name="left">The first object to add.</param>
/// <param name="right">The second object to add.</param>
/// <returns>The value of the two objects added together.</returns>
public static AngleSingle operator +(AngleSingle left, AngleSingle right)
{
return new AngleSingle(left.radians + right.radians, AngleType.Radian);
}
/// <summary>
/// Subtracts two Stride.Core.Mathematics.AngleSingle objects and returns the result.
/// </summary>
/// <param name="left">The first object to subtract</param>
/// <param name="right">The second object to subtract.</param>
/// <returns>The value of the two objects subtracted.</returns>
public static AngleSingle operator -(AngleSingle left, AngleSingle right)
{
return new AngleSingle(left.radians - right.radians, AngleType.Radian);
}
/// <summary>
/// Multiplies two Stride.Core.Mathematics.AngleSingle objects and returns the result.
/// </summary>
/// <param name="left">The first object to multiply.</param>
/// <param name="right">The second object to multiply.</param>
/// <returns>The value of the two objects multiplied together.</returns>
public static AngleSingle operator *(AngleSingle left, AngleSingle right)
{
return new AngleSingle(left.radians * right.radians, AngleType.Radian);
}
/// <summary>
/// Divides two Stride.Core.Mathematics.AngleSingle objects and returns the result.
/// </summary>
/// <param name="left">The numerator object.</param>
/// <param name="right">The denominator object.</param>
/// <returns>The value of the two objects divided.</returns>
public static AngleSingle operator /(AngleSingle left, AngleSingle right)
{
return new AngleSingle(left.radians / right.radians, AngleType.Radian);
}
/// <summary>
/// Compares this instance to a specified object and returns an integer that
/// indicates whether the value of this instance is less than, equal to, or greater
/// than the value of the specified object.
/// </summary>
/// <param name="other">The object to compare.</param>
/// <returns>
/// A signed integer that indicates the relationship of the current instance
/// to the obj parameter. If the value is less than zero, the current instance
/// is less than the other. If the value is zero, the current instance is equal
/// to the other. If the value is greater than zero, the current instance is
/// greater than the other.
/// </returns>
public int CompareTo(object other)
{
if (other == null)
return 1;
if (!(other is AngleSingle))
throw new ArgumentException("Argument must be of type Angle.", "other");
float radians = ((AngleSingle)other).radians;
if (this.radians > radians)
return 1;
if (this.radians < radians)
return -1;
return 0;
}
/// <summary>
/// Compares this instance to a second Stride.Core.Mathematics.AngleSingle and returns
/// an integer that indicates whether the value of this instance is less than,
/// equal to, or greater than the value of the specified object.
/// </summary>
/// <param name="other">The object to compare.</param>
/// <returns>
/// A signed integer that indicates the relationship of the current instance
/// to the obj parameter. If the value is less than zero, the current instance
/// is less than the other. If the value is zero, the current instance is equal
/// to the other. If the value is greater than zero, the current instance is
/// greater than the other.
/// </returns>
public int CompareTo(AngleSingle other)
{
if (this.radians > other.radians)
return 1;
if (this.radians < other.radians)
return -1;
return 0;
}
/// <summary>
/// Returns a value that indicates whether the current instance and a specified
/// Stride.Core.Mathematics.AngleSingle object have the same value.
/// </summary>
/// <param name="other">The object to compare.</param>
/// <returns>
/// Returns true if this Stride.Core.Mathematics.AngleSingle object and another have the same value;
/// otherwise, false.
/// </returns>
public bool Equals(AngleSingle other)
{
return this == other;
}
/// <summary>
/// Returns a <see cref="string"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="string"/> that represents this instance.
/// </returns>
public override string ToString()
{
return string.Format(CultureInfo.CurrentCulture, MathUtil.RadiansToDegrees(radians).ToString("0.##°"));
}
/// <summary>
/// Returns a <see cref="string"/> that represents this instance.
/// </summary>
/// <param name="format">The format.</param>
/// <returns>
/// A <see cref="string"/> that represents this instance.
/// </returns>
public string ToString(string format)
{
if (format == null)
return ToString();
return string.Format(CultureInfo.CurrentCulture, "{0}°", MathUtil.RadiansToDegrees(radians).ToString(format, CultureInfo.CurrentCulture));
}
/// <summary>
/// Returns a <see cref="string"/> that represents this instance.
/// </summary>
/// <param name="formatProvider">The format provider.</param>
/// <returns>
/// A <see cref="string"/> that represents this instance.
/// </returns>
public string ToString(IFormatProvider formatProvider)
{
return string.Format(formatProvider, MathUtil.RadiansToDegrees(radians).ToString("0.##°"));
}
/// <summary>
/// Returns a <see cref="string"/> that represents this instance.
/// </summary>
/// <param name="format">The format.</param>
/// <param name="formatProvider">The format provider.</param>
/// <returns>
/// A <see cref="string"/> that represents this instance.
/// </returns>
public string ToString(string format, IFormatProvider formatProvider)
{
if (format == null)
return ToString(formatProvider);
return string.Format(formatProvider, "{0}°", MathUtil.RadiansToDegrees(radians).ToString(format, CultureInfo.CurrentCulture));
}
/// <summary>
/// Returns a hash code for this Stride.Core.Mathematics.AngleSingle instance.
/// </summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return (int)(BitConverter.DoubleToInt64Bits(radians) % int.MaxValue);
}
/// <summary>
/// Returns a value that indicates whether the current instance and a specified
/// object have the same value.
/// </summary>
/// <param name="obj">The object to compare.</param>
/// <returns>
/// Returns true if the obj parameter is a Stride.Core.Mathematics.AngleSingle object or a type
/// capable of implicit conversion to a Stride.Core.Mathematics.AngleSingle value, and
/// its value is equal to the value of the current Stride.Core.Mathematics.Angle
/// object; otherwise, false.
/// </returns>
public override bool Equals(object obj)
{
return (obj is AngleSingle) && (this == (AngleSingle)obj);
}
}
}