Merge pull request #4323 from larsbrubaker/master

master
This commit is contained in:
Lars Brubaker 2019-03-04 07:21:35 -08:00 committed by GitHub
commit 0c6a0fe4be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 38 deletions

View file

@ -200,6 +200,11 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
for (int regionIndex = 0; regionIndex < Regions.Count; regionIndex++)
{
var dist = (Regions[regionIndex].Center - currentDestination).LengthSquared;
if (Regions[regionIndex].PointInPolyXY(currentDestination.X, currentDestination.Y))
{
// we found the one it is in
return Regions[regionIndex];
}
if (dist < bestDist)
{
bestIndex = regionIndex;
@ -239,6 +244,34 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
return currentDestination;
}
private int FindSideOfLine(Vector2 sidePoint0, Vector2 sidePoint1, Vector2 testPosition)
{
if (Vector2.Cross(testPosition - sidePoint0, sidePoint1 - sidePoint0) < 0)
{
return 1;
}
return -1;
}
public bool PointInPolyXY(double x, double y)
{
// check the bounding rect
Vector2 vertex0 = new Vector2(V0[0], V0[1]);
Vector2 vertex1 = new Vector2(V1[0], V1[1]);
Vector2 vertex2 = new Vector2(V2[0], V2[1]);
Vector2 hitPosition = new Vector2(x, y);
int sumOfLineSides = FindSideOfLine(vertex0, vertex1, hitPosition);
sumOfLineSides += FindSideOfLine(vertex1, vertex2, hitPosition);
sumOfLineSides += FindSideOfLine(vertex2, vertex0, hitPosition);
if (sumOfLineSides == -3 || sumOfLineSides == 3)
{
return true;
}
return false;
}
}
}
}

View file

@ -53,12 +53,6 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
public class FitToCylinderObject3D : TransformWrapperObject3D, IEditorDraw
{
private AxisAlignedBoundingBox cacheAabb;
private bool rebuildAabbCache = true;
private Matrix4X4 cacheRequestedMatrix = new Matrix4X4();
public FitToCylinderObject3D()
{
Name = "Fit to Cylinder".Localize();
@ -108,7 +102,6 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
var finalAabb = fitToBounds.GetAxisAlignedBoundingBox();
fitToBounds.Translate(startingAabb.Center - finalAabb.Center);
fitToBounds.rebuildAabbCache = true;
}
return fitToBounds;
@ -128,16 +121,12 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
{
if (Children.Count == 2)
{
if (rebuildAabbCache)
AxisAlignedBoundingBox cacheAabb;
using (FitBounds.RebuildLock())
{
using (FitBounds.RebuildLock())
{
FitBounds.Visible = true;
cacheAabb = base.GetAxisAlignedBoundingBox(matrix);
FitBounds.Visible = false;
}
cacheRequestedMatrix = matrix;
rebuildAabbCache = false;
FitBounds.Visible = true;
cacheAabb = base.GetAxisAlignedBoundingBox(matrix);
FitBounds.Visible = false;
}
return cacheAabb;
@ -166,7 +155,6 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
|| invalidateType.InvalidateType.HasFlag(InvalidateType.Mesh)
|| invalidateType.InvalidateType.HasFlag(InvalidateType.Children))
{
rebuildAabbCache = true;
base.OnInvalidate(invalidateType);
}
@ -181,10 +169,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
using (new CenterAndHeightMantainer(this))
{
AdjustChildSize(null, null);
UpdateBoundsItem();
cacheRequestedMatrix = new Matrix4X4();
var after = this.GetAxisAlignedBoundingBox();
}
}
@ -323,11 +308,19 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
scale.Z = SizeZ / aabb.ZSize;
}
var minXy = Math.Min(scale.X, scale.Y);
scale.X = minXy;
scale.Y = minXy;
ItemWithTransform.Matrix = ItemWithTransform.Matrix.ApplyAtPosition(aabb.Center, Matrix4X4.CreateScale(scale));
ItemWithTransform.Matrix = Object3DExtensions.ApplyAtPosition(ItemWithTransform.Matrix, aabb.Center, Matrix4X4.CreateScale(scale));
Matrix4X4 centering;
if (AlternateCentering)
{
centering = GetCenteringTransformVisualCenter(UntransformedChildren, Diameter / 2);
}
else
{
centering = GetCenteringTransformExpandedToRadius(UntransformedChildren, Diameter / 2);
}
ItemWithTransform.Matrix = ItemWithTransform.Matrix.ApplyAtPosition(aabb.Center, centering);
}
}
@ -342,23 +335,12 @@ namespace MatterHackers.MatterControl.DesignTools.Operations
&& (fitAabb.XSize != Diameter || fitAabb.ZSize != SizeZ))
{
FitBounds.Matrix *= Matrix4X4.CreateScale(
fitAabb.XSize / Diameter,
fitAabb.YSize / Diameter,
fitAabb.ZSize / SizeZ);
Diameter / fitAabb.XSize,
Diameter / fitAabb.YSize,
SizeZ / fitAabb.ZSize);
FitBounds.Matrix *= Matrix4X4.CreateTranslation(
transformAabb.Center - FitBounds.GetAxisAlignedBoundingBox().Center);
}
if (AlternateCentering)
{
var test = GetCenteringTransformVisualCenter(UntransformedChildren, Diameter/2);
}
else
{
var test = GetCenteringTransformExpandedToRadius(UntransformedChildren, Diameter / 2);
}
rebuildAabbCache = true;
}
}
}