360° Angle Class for C#

Here is a nifty class to handle an angle. it will wrap around increments and decrements that exceed 360 or 0, e.g. adding 20 to 350 will give 10 not 370 and subtracting 10 from 5 will give 355 not -5.

  • Implicit conversion to and from double
  • ToString and GetHashCode are mapped to the inner angle
  • Operators +,-,>,>=,<,<= have been implemented.
  • Mixing this class and doubles in statements works seemlessly.

Code sample:

Angle angle = 0;
double angle2 = angle + 5;
Console.WriteLine("a1:{0) a2:{1}",angle,angle2); 
//Output: a1:0 a2:5

Files

Bookmark the permalink.

One Response to 360° Angle Class for C#

  1. Nauman Khalid says:

    really nice work.. thanks alot

Leave a Reply

Your email address will not be published. Required fields are marked *