more fixed math stuff
							parent
							
								
									41d1c593cf
								
							
						
					
					
						commit
						85f21b7859
					
				|  | @ -28,7 +28,7 @@ namespace MoonWorks.Collision.Fixed | ||||||
| 
 | 
 | ||||||
| 		private (int, int) Hash(Vector2 position) | 		private (int, int) Hash(Vector2 position) | ||||||
| 		{ | 		{ | ||||||
| 			return ((int) Fix64.Floor(position.X / cellSize), (int) Fix64.Floor(position.Y / cellSize)); | 			return ((int) (position.X / cellSize), (int) (position.Y / cellSize)); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		/// <summary> | 		/// <summary> | ||||||
|  |  | ||||||
|  | @ -30,6 +30,9 @@ namespace MoonWorks.Math.Fixed | ||||||
| 		const int LUT_SIZE = (int)(PI_OVER_2 >> 15); | 		const int LUT_SIZE = (int)(PI_OVER_2 >> 15); | ||||||
| 		static readonly Fix64 LutInterval = (Fix64)(LUT_SIZE - 1) / PiOver2; | 		static readonly Fix64 LutInterval = (Fix64)(LUT_SIZE - 1) / PiOver2; | ||||||
| 
 | 
 | ||||||
|  | 		public bool IsFractional => (RawValue & 0x00000000FFFFFFFF) != 0; | ||||||
|  | 		public bool IsIntegral => (RawValue & 0x00000000FFFFFFFF) == 0; | ||||||
|  | 
 | ||||||
| 		private Fix64(long value) | 		private Fix64(long value) | ||||||
| 		{ | 		{ | ||||||
| 			RawValue = value; | 			RawValue = value; | ||||||
|  | @ -95,8 +98,7 @@ namespace MoonWorks.Math.Fixed | ||||||
|         /// </summary> |         /// </summary> | ||||||
| 		public static Fix64 Ceiling(Fix64 value) | 		public static Fix64 Ceiling(Fix64 value) | ||||||
| 		{ | 		{ | ||||||
| 			var hasFractionalPart = (value.RawValue & 0x00000000FFFFFFFF) != 0; | 			return value.IsFractional ? Floor(value) + One : value; | ||||||
| 			return hasFractionalPart ? Floor(value) + One : value; |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|  | @ -697,12 +699,12 @@ namespace MoonWorks.Math.Fixed | ||||||
| 
 | 
 | ||||||
| 		public static bool operator >(Fix64 x, int y) | 		public static bool operator >(Fix64 x, int y) | ||||||
| 		{ | 		{ | ||||||
| 			return ((int) x) > y; | 			return x > ((Fix64) y); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public static bool operator <(Fix64 x, int y) | 		public static bool operator <(Fix64 x, int y) | ||||||
| 		{ | 		{ | ||||||
| 			return ((int) x) < y; | 			return x < ((Fix64) y); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public static bool operator >=(Fix64 x, Fix64 y) | 		public static bool operator >=(Fix64 x, Fix64 y) | ||||||
|  | @ -717,12 +719,12 @@ namespace MoonWorks.Math.Fixed | ||||||
| 
 | 
 | ||||||
| 		public static bool operator >=(Fix64 x, int y) | 		public static bool operator >=(Fix64 x, int y) | ||||||
| 		{ | 		{ | ||||||
| 			return ((int) x) >= y; | 			return x >= ((Fix64) y); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public static bool operator <=(Fix64 x, int y) | 		public static bool operator <=(Fix64 x, int y) | ||||||
| 		{ | 		{ | ||||||
| 			return ((int) x) <= y; | 			return x <= ((Fix64) y); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// Casting | 		// Casting | ||||||
|  |  | ||||||
|  | @ -6,7 +6,21 @@ namespace MoonWorks.Math.Fixed | ||||||
| 		public Fix64 Rotation { get; } | 		public Fix64 Rotation { get; } | ||||||
| 		public Vector2 Scale { get; } | 		public Vector2 Scale { get; } | ||||||
| 
 | 
 | ||||||
| 		public Matrix3x2 TransformMatrix { get; } | 		private bool transformMatrixCalculated = false; | ||||||
|  | 		private Matrix3x2 transformMatrix = Matrix3x2.Identity; | ||||||
|  | 		public Matrix3x2 TransformMatrix | ||||||
|  | 		{ | ||||||
|  | 			get | ||||||
|  | 			{ | ||||||
|  | 				if (!transformMatrixCalculated) | ||||||
|  | 				{ | ||||||
|  | 					transformMatrix = CreateTransformMatrix(Position, Rotation, Scale); | ||||||
|  | 					transformMatrixCalculated = true; | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				return transformMatrix; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		public bool IsAxisAligned => Rotation % Fix64.PiOver2 == Fix64.Zero; | 		public bool IsAxisAligned => Rotation % Fix64.PiOver2 == Fix64.Zero; | ||||||
| 		public bool IsUniformScale => Scale.X == Scale.Y; | 		public bool IsUniformScale => Scale.X == Scale.Y; | ||||||
|  | @ -18,7 +32,6 @@ namespace MoonWorks.Math.Fixed | ||||||
| 			Position = Vector2.Zero; | 			Position = Vector2.Zero; | ||||||
| 			Rotation = Fix64.Zero; | 			Rotation = Fix64.Zero; | ||||||
| 			Scale = Vector2.One; | 			Scale = Vector2.One; | ||||||
| 			TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public Transform2D(Vector2 position) | 		public Transform2D(Vector2 position) | ||||||
|  | @ -26,7 +39,6 @@ namespace MoonWorks.Math.Fixed | ||||||
| 			Position = position; | 			Position = position; | ||||||
| 			Rotation = Fix64.Zero; | 			Rotation = Fix64.Zero; | ||||||
| 			Scale = Vector2.One; | 			Scale = Vector2.One; | ||||||
| 			TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public Transform2D(Vector2 position, Fix64 rotation) | 		public Transform2D(Vector2 position, Fix64 rotation) | ||||||
|  | @ -34,7 +46,6 @@ namespace MoonWorks.Math.Fixed | ||||||
| 			Position = position; | 			Position = position; | ||||||
| 			Rotation = rotation; | 			Rotation = rotation; | ||||||
| 			Scale = Vector2.One; | 			Scale = Vector2.One; | ||||||
| 			TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public Transform2D(Vector2 position, Fix64 rotation, Vector2 scale) | 		public Transform2D(Vector2 position, Fix64 rotation, Vector2 scale) | ||||||
|  | @ -42,7 +53,6 @@ namespace MoonWorks.Math.Fixed | ||||||
| 			Position = position; | 			Position = position; | ||||||
| 			Rotation = rotation; | 			Rotation = rotation; | ||||||
| 			Scale = scale; | 			Scale = scale; | ||||||
| 			TransformMatrix = CreateTransformMatrix(Position, Rotation, Scale); |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public Transform2D Compose(Transform2D other) | 		public Transform2D Compose(Transform2D other) | ||||||
|  |  | ||||||
|  | @ -218,6 +218,14 @@ namespace MoonWorks.Math.Fixed | ||||||
| 			return Fix64.Atan2(Y, X); | 			return Fix64.Atan2(Y, X); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		/// <summary> | ||||||
|  | 		/// Returns this Vector2 with the fractional components cut off. | ||||||
|  | 		/// </summary> | ||||||
|  | 		public Vector2 Truncated() | ||||||
|  | 		{ | ||||||
|  | 			return new Vector2((int) X, (int) Y); | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		/// <summary> | 		/// <summary> | ||||||
| 		/// Returns a <see cref="String"/> representation of this <see cref="Vector2"/> in the format: | 		/// Returns a <see cref="String"/> representation of this <see cref="Vector2"/> in the format: | ||||||
| 		/// {X:[<see cref="X"/>] Y:[<see cref="Y"/>]} | 		/// {X:[<see cref="X"/>] Y:[<see cref="Y"/>]} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue