| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- namespace BansheeEngine
- {
- /// <summary>
- /// Wrapper class which indicates a given angle value is in degrees. Degree values are interchangeable with radian
- /// values, and conversions will be done automatically between them.
- /// </summary>
- [StructLayout(LayoutKind.Sequential), SerializeObject]
- public struct Degree // Note: Must match C++ class Degree
- {
- readonly float value;
- /// <summary>
- /// Creates a new degree value.
- /// </summary>
- /// <param name="value">Value in degrees.</param>
- public Degree(float value = 0.0f)
- {
- this.value = value;
- }
- /// <summary>
- /// Creates a new degree value.
- /// </summary>
- /// <param name="r">Value in radians.</param>
- public Degree(Radian r)
- {
- this.value = r.Degrees;
- }
- /// <summary>
- /// Converts a undefined angle value to a degree value.
- /// </summary>
- /// <param name="value">Value in degrees.</param>
- /// <returns>Degree object wrapping the value.</returns>
- public static implicit operator Degree(float value)
- {
- return new Degree(value);
- }
- /// <summary>
- /// Converts a radian angle value to a degree value.
- /// </summary>
- /// <param name="r">Value in radians.</param>
- /// <returns>Degree object wrapping the value.</returns>
- public static implicit operator Degree(Radian r)
- {
- return new Degree(r.Degrees);
- }
- /// <summary>
- /// Converts a degree value to a regular floating point value.
- /// </summary>
- /// <param name="d">Degree value to convert.</param>
- /// <returns>Value in degrees as floating point type.</returns>
- public static explicit operator float(Degree d)
- {
- return d.value;
- }
- /// <summary>
- /// Returns the value in degrees as a floating point type.
- /// </summary>
- public float Degrees
- {
- get { return value; }
- }
- /// <summary>
- /// Returns the value in radians as a floating point type.
- /// </summary>
- public float Radians
- {
- get { return value*MathEx.Deg2Rad; }
- }
- public static Degree operator+(Degree a)
- {
- return a;
- }
- public static Degree operator+(Degree a, Degree b)
- {
- return new Degree(a.value + b.value);
- }
- public static Degree operator+(Degree a, Radian r)
- {
- return new Degree (a.value + r.Degrees);
- }
- public static Degree operator-(Degree a)
- {
- return new Degree(-a.value);
- }
- public static Degree operator-(Degree a, Degree b)
- {
- return new Degree(a.value - b.value);
- }
- public static Degree operator-(Degree a, Radian r)
- {
- return new Degree (a.value - r.Degrees);
- }
- public static Degree operator*(Degree a, float s)
- {
- return new Degree(a.value * s);
- }
- public static Degree operator*(Degree a, Degree b)
- {
- return new Degree(a.value * b.value);
- }
- public static Degree operator/(Degree a, float s)
- {
- return new Degree(a.value / s);
- }
- public static Degree operator /(Degree a, Degree b)
- {
- return new Degree(a.value / b.value);
- }
- public static bool operator<(Degree a, Degree b)
- {
- return a.value < b.value;
- }
- public static bool operator>(Degree a, Degree b)
- {
- return a.value > b.value;
- }
- public static bool operator<=(Degree a, Degree b)
- {
- return a.value <= b.value;
- }
- public static bool operator>=(Degree a, Degree b)
- {
- return a.value >= b.value;
- }
- public static bool operator==(Degree a, Degree b)
- {
- return a.value == b.value;
- }
- public static bool operator!=(Degree a, Degree b)
- {
- return a.value != b.value;
- }
- /// <inheritdoc/>
- public override bool Equals(object other)
- {
- if (!(other is Degree))
- return false;
- Degree degree = (Degree)other;
- if (value.Equals(degree.value))
- return true;
- return false;
- }
- /// <inheritdoc/>
- public override int GetHashCode()
- {
- return value.GetHashCode();
- }
- /// <inheritdoc/>
- public override string ToString()
- {
- return value.ToString();
- }
- };
- }
|