remove linq methods from AABB calculation
							parent
							
								
									0952b77761
								
							
						
					
					
						commit
						d9bc05ee32
					
				
							
								
								
									
										36
									
								
								Bonk/AABB.cs
								
								
								
								
							
							
						
						
									
										36
									
								
								Bonk/AABB.cs
								
								
								
								
							|  | @ -1,6 +1,5 @@ | |||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Numerics; | ||||
| using MoonTools.Core.Structs; | ||||
| 
 | ||||
|  | @ -21,14 +20,39 @@ namespace MoonTools.Core.Bonk | |||
| 
 | ||||
|         public static AABB FromTransformedVertices(IEnumerable<Position2D> vertices, Transform2D transform) | ||||
|         { | ||||
|             var TransformedVertices = vertices.Select(vertex => Vector2.Transform(vertex, transform.TransformMatrix)); | ||||
|             float minX = float.MaxValue; | ||||
|             float minY = float.MaxValue; | ||||
|             float maxX = float.MinValue; | ||||
|             float maxY = float.MinValue; | ||||
| 
 | ||||
|             foreach (var vertex in vertices) | ||||
|             { | ||||
|                 var transformedVertex = Vector2.Transform(vertex, transform.TransformMatrix); | ||||
| 
 | ||||
|                 if (transformedVertex.X < minX) | ||||
|                 { | ||||
|                     minX = transformedVertex.X; | ||||
|                 } | ||||
|                 if (transformedVertex.Y < minY) | ||||
|                 { | ||||
|                     minY = transformedVertex.Y; | ||||
|                 } | ||||
|                 if (transformedVertex.X > maxX) | ||||
|                 { | ||||
|                     maxX = transformedVertex.X; | ||||
|                 } | ||||
|                 if (transformedVertex.Y > maxY) | ||||
|                 { | ||||
|                     maxY = transformedVertex.Y; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return new AABB | ||||
|             { | ||||
|                 MinX = TransformedVertices.Min(vertex => vertex.X), | ||||
|                 MinY = TransformedVertices.Min(vertex => vertex.Y), | ||||
|                 MaxX = TransformedVertices.Max(vertex => vertex.X), | ||||
|                 MaxY = TransformedVertices.Max(vertex => vertex.Y) | ||||
|                 MinX = minX, | ||||
|                 MinY = minY, | ||||
|                 MaxX = maxX, | ||||
|                 MaxY = maxY | ||||
|             }; | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,8 +33,6 @@ namespace MoonTools.Core.Bonk | |||
|         /// <param name="transform2D"></param> | ||||
|         public void Insert(T id, IShape2D shape, Transform2D transform2D) | ||||
|         { | ||||
|             if (shape == null) { throw new ArgumentNullException(nameof(shape)); } | ||||
| 
 | ||||
|             var box = shape.AABB(transform2D); | ||||
|             var minHash = Hash(box.MinX, box.MinY); | ||||
|             var maxHash = Hash(box.MaxX, box.MaxY); | ||||
|  | @ -64,8 +62,6 @@ namespace MoonTools.Core.Bonk | |||
|         /// </summary> | ||||
|         public IEnumerable<(T, IShape2D, Transform2D)> Retrieve(T id, IShape2D shape, Transform2D transform2D) | ||||
|         { | ||||
|             if (shape == null) { throw new ArgumentNullException(paramName: nameof(shape)); } | ||||
| 
 | ||||
|             AABB box = shape.AABB(transform2D); | ||||
|             var minHash = Hash(box.MinX, box.MinY); | ||||
|             var maxHash = Hash(box.MaxX, box.MaxY); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue