From 2be90fe6f91fa18fff7f4e503756368beb831791 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Tue, 30 Jun 2020 18:17:56 -0700 Subject: [PATCH] fixing corruption of aabb during arrange all --- .../PartPreviewWindow/PlatingHelper.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/PlatingHelper.cs b/MatterControlLib/PartPreviewWindow/PlatingHelper.cs index aaa73ed1e..a24d7495e 100644 --- a/MatterControlLib/PartPreviewWindow/PlatingHelper.cs +++ b/MatterControlLib/PartPreviewWindow/PlatingHelper.cs @@ -29,24 +29,23 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; +using System.Linq; using ClipperLib; using MatterHackers.Agg; using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; using MatterHackers.PolygonMesh; using MatterHackers.VectorMath; +using Polygon = System.Collections.Generic.List; +using Polygons = System.Collections.Generic.List>; namespace MatterHackers.MatterControl { - using System.Linq; - using DataConverters3D; - using Polygon = List; - using Polygons = List>; - public static class PlatingHelper { public static VertexStorage PolygonToPathStorage(this Polygons polygons) { - VertexStorage output = new VertexStorage(); + var output = new VertexStorage(); foreach (Polygon polygon in polygons) { @@ -66,6 +65,7 @@ namespace MatterHackers.MatterControl output.ClosePolygon(); } + output.Add(0, 0, ShapePath.FlagsAndCommand.Stop); return output; @@ -165,25 +165,26 @@ namespace MatterHackers.MatterControl /// /// Moves the target object to the first non-colliding position, starting at the initial position of the target object /// - /// The object to position + /// The object to position /// The objects to hit test against public static void MoveToOpenPosition(IObject3D itemToMove, IEnumerable itemsToAvoid) { // find a place to put it that doesn't hit anything - AxisAlignedBoundingBox itemToMoveBounds = itemToMove.GetAxisAlignedBoundingBox(); + var currentBounds = itemToMove.GetAxisAlignedBoundingBox(); + var itemToMoveBounds = new AxisAlignedBoundingBox(currentBounds.MinXYZ, currentBounds.MaxXYZ); // add in a few mm so that it will not be touching itemToMoveBounds.MinXYZ -= new Vector3(2, 2, 0); itemToMoveBounds.MaxXYZ += new Vector3(2, 2, 0); - Matrix4X4 transform = Matrix4X4.Identity; + var transform = Matrix4X4.Identity; int currentSize = 1; bool partPlaced = false; while (!partPlaced && itemToMove != null) { - int yStep = 0; int xStep = currentSize; + int yStep; // check far right edge for (yStep = 0; yStep < currentSize; yStep++) { @@ -228,7 +229,7 @@ namespace MatterHackers.MatterControl double xStepAmount = 5; double yStepAmount = 5; - Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(xStep * xStepAmount, yStep * yStepAmount, 0); + var positionTransform = Matrix4X4.CreateTranslation(xStep * xStepAmount, yStep * yStepAmount, 0); Vector3 newPosition = Vector3Ex.Transform(Vector3.Zero, positionTransform); transform = Matrix4X4.CreateTranslation(newPosition); @@ -240,7 +241,7 @@ namespace MatterHackers.MatterControl if (meshToTest != itemToMove) { AxisAlignedBoundingBox existingMeshBounds = meshToTest.GetAxisAlignedBoundingBox(); - AxisAlignedBoundingBox intersection = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds); + var intersection = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds); if (intersection.XSize > 0 && intersection.YSize > 0) { return false;