refactor: move shared GetRectangle to Action base class

Both ActionSelect and ActionZoomWindow had identical 29-line
GetRectangle methods; consolidate into the common base class.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-28 16:16:00 -04:00
parent 17f786c9e8
commit d1a701a7f7
3 changed files with 17 additions and 60 deletions

View File

@@ -1,4 +1,6 @@
using OpenNest.Controls;
using OpenNest.Geometry;
using System.Drawing;
namespace OpenNest.Actions
{
@@ -11,6 +13,19 @@ namespace OpenNest.Actions
this.plateView = plateView;
}
protected RectangleF GetRectangle(Vector worldPt1, Vector worldPt2)
{
var pt1 = plateView.PointWorldToGraph(worldPt1);
var pt2 = plateView.PointWorldToGraph(worldPt2);
var x = pt1.X < pt2.X ? pt1.X : pt2.X;
var y = pt1.Y < pt2.Y ? pt1.Y : pt2.Y;
var w = System.Math.Abs(pt2.X - pt1.X);
var h = System.Math.Abs(pt2.Y - pt1.Y);
return new RectangleF(x, y, w, h);
}
public virtual bool SurvivesPlateChange => false;
public virtual void OnPlateChanged() { }

View File

@@ -212,36 +212,7 @@ namespace OpenNest.Actions
}
}
private RectangleF GetRectangle()
{
var rect = new RectangleF();
var pt1 = plateView.PointWorldToGraph(Point1);
var pt2 = plateView.PointWorldToGraph(Point2);
if (pt1.X < pt2.X)
{
rect.X = pt1.X;
rect.Width = pt2.X - pt1.X;
}
else
{
rect.X = pt2.X;
rect.Width = pt1.X - pt2.X;
}
if (pt1.Y < pt2.Y)
{
rect.Y = pt1.Y;
rect.Height = pt2.Y - pt1.Y;
}
else
{
rect.Y = pt2.Y;
rect.Height = pt1.Y - pt2.Y;
}
return rect;
}
private RectangleF GetRectangle() => GetRectangle(Point1, Point2);
public SelectionType SelectionType
{

View File

@@ -166,36 +166,7 @@ namespace OpenNest.Actions
plateView.Refresh();
}
private RectangleF GetRectangle()
{
var rect = new RectangleF();
var pt1 = plateView.PointWorldToGraph(Point1);
var pt2 = plateView.PointWorldToGraph(Point2);
if (pt1.X < pt2.X)
{
rect.X = pt1.X;
rect.Width = pt2.X - pt1.X;
}
else
{
rect.X = pt2.X;
rect.Width = pt1.X - pt2.X;
}
if (pt1.Y < pt2.Y)
{
rect.Y = pt1.Y;
rect.Height = pt2.Y - pt1.Y;
}
else
{
rect.Y = pt2.Y;
rect.Height = pt1.Y - pt2.Y;
}
return rect;
}
private RectangleF GetRectangle() => GetRectangle(Point1, Point2);
public enum Status
{