Move math utilities to OpenNest.Math namespace

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 12:51:16 -05:00
parent 2210f60656
commit 8d9aebb83f
40 changed files with 172 additions and 140 deletions

View File

@@ -63,7 +63,7 @@ namespace OpenNest.Controls
var bounds = dwg.Program.BoundingBox();
var text1 = string.Format("{0} of {1} nested", dwg.Quantity.Nested, dwg.Quantity.Required);
var text2 = bounds.Size.ToString(4);
var text3 = string.Format("{0} sq/{1}", Math.Round(dwg.Area, 4), UnitsHelper.GetShortString(Units));
var text3 = string.Format("{0} sq/{1}", System.Math.Round(dwg.Area, 4), UnitsHelper.GetShortString(Units));
pt.Y += 22;
e.Graphics.DrawString(text1, Font, Brushes.Gray, pt);
@@ -100,7 +100,7 @@ namespace OpenNest.Controls
var x = pt2.X - pt1.X;
var y = pt2.Y - pt1.Y;
return Math.Sqrt(x * x + y * y);
return System.Math.Sqrt(x * x + y * y);
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest.Controls
{
@@ -59,12 +60,12 @@ namespace OpenNest.Controls
{
base.OnMouseWheel(e);
float multiplier = Math.Abs(e.Delta / 120.0f);
float multiplier = System.Math.Abs(e.Delta / 120.0f);
if (e.Delta > 0)
ZoomToControlPoint(e.Location, (float)Math.Pow(ZoomInFactor, multiplier));
ZoomToControlPoint(e.Location, (float)System.Math.Pow(ZoomInFactor, multiplier));
else
ZoomToControlPoint(e.Location, (float)Math.Pow(ZoomOutFactor, multiplier));
ZoomToControlPoint(e.Location, (float)System.Math.Pow(ZoomOutFactor, multiplier));
Invalidate();
}

View File

@@ -5,6 +5,7 @@ using OpenTK.Graphics.OpenGL;
using System;
using System.Drawing;
using System.Windows.Forms;
using OpenNest.Math;
namespace OpenNest.Controls
{
@@ -13,7 +14,7 @@ namespace OpenNest.Controls
private float scale;
private bool loaded = false;
private const double TwoPI = Math.PI * 2.0;
private const double TwoPI = System.Math.PI * 2.0;
private const int Resolution = 100;
private const int BorderWidth = 50;
private const float ZoomInFactor = 1.1f;
@@ -117,12 +118,12 @@ namespace OpenNest.Controls
{
base.OnMouseWheel(e);
float multiplier = Math.Abs(e.Delta / 120.0f);
float multiplier = System.Math.Abs(e.Delta / 120.0f);
if (e.Delta > 0)
ZoomToPoint(e.X, e.Y, (float)Math.Pow(ZoomInFactor, multiplier));
ZoomToPoint(e.X, e.Y, (float)System.Math.Pow(ZoomInFactor, multiplier));
else
ZoomToPoint(e.X, e.Y, (float)Math.Pow(ZoomOutFactor, multiplier));
ZoomToPoint(e.X, e.Y, (float)System.Math.Pow(ZoomOutFactor, multiplier));
Invalidate();
}
@@ -292,12 +293,12 @@ namespace OpenNest.Controls
}
// start angle in radians
var startAngle = Math.Atan2(
var startAngle = System.Math.Atan2(
curpos.Y - center.Y,
curpos.X - center.X);
// end angle in radians
var endAngle = Math.Atan2(
var endAngle = System.Math.Atan2(
endpt.Y - center.Y,
endpt.X - center.X);
@@ -312,7 +313,7 @@ namespace OpenNest.Controls
var dx = endpt.X - center.X;
var dy = endpt.Y - center.Y;
var radius = Math.Sqrt(dx * dx + dy * dy);
var radius = System.Math.Sqrt(dx * dx + dy * dy);
if (startAngle.IsEqualTo(endAngle))
{
@@ -337,8 +338,8 @@ namespace OpenNest.Controls
for (int i = 0; i <= Resolution; i++)
{
GL.Vertex2(
Math.Cos(startAngle + angle * i) * radius + center.X,
Math.Sin(startAngle + angle * i) * radius + center.Y);
System.Math.Cos(startAngle + angle * i) * radius + center.X,
System.Math.Sin(startAngle + angle * i) * radius + center.Y);
}
GL.End();
@@ -346,14 +347,14 @@ namespace OpenNest.Controls
private void DrawCircle(Vector center, double radius)
{
const float angle = (float)Math.PI * 2.0f;
const float angle = (float)System.Math.PI * 2.0f;
const float increment = angle / Resolution;
for (float i = 0; i <= angle; i += increment)
{
GL.Vertex2(
Math.Cos(i) * radius + center.X,
Math.Sin(i) * radius + center.Y);
System.Math.Cos(i) * radius + center.X,
System.Math.Sin(i) * radius + center.Y);
}
}

View File

@@ -9,6 +9,7 @@ using System.Windows.Forms;
using OpenNest.Actions;
using OpenNest.CNC;
using OpenNest.Collections;
using OpenNest.Math;
using Action = OpenNest.Actions.Action;
using Timer = System.Timers.Timer;
@@ -164,7 +165,7 @@ namespace OpenNest.Controls
{
base.OnMouseWheel(e);
var multiplier = Math.Abs(e.Delta / 120);
var multiplier = System.Math.Abs(e.Delta / 120);
if (SelectedParts.Count > 0 && ((ModifierKeys & Keys.Shift) == Keys.Shift))
{
@@ -181,9 +182,9 @@ namespace OpenNest.Controls
if (AllowZoom)
{
if (e.Delta > 0)
ZoomToControlPoint(e.Location, (float)Math.Pow(ZoomInFactor, multiplier));
ZoomToControlPoint(e.Location, (float)System.Math.Pow(ZoomInFactor, multiplier));
else
ZoomToControlPoint(e.Location, (float)Math.Pow(ZoomOutFactor, multiplier));
ZoomToControlPoint(e.Location, (float)System.Math.Pow(ZoomOutFactor, multiplier));
}
}

View File

@@ -9,6 +9,7 @@ using OpenNest.Actions;
using OpenNest.Collections;
using OpenNest.Controls;
using OpenNest.IO;
using OpenNest.Math;
using OpenNest.Properties;
using Timer = System.Timers.Timer;
@@ -292,8 +293,8 @@ namespace OpenNest.Forms
writer.WriteLine("{0}|{1},{2}|{3}",
part.BaseDrawing.Source.Path,
Math.Round(part.Location.X - pt.X, 8),
Math.Round(part.Location.Y - pt.Y, 8),
System.Math.Round(part.Location.X - pt.X, 8),
System.Math.Round(part.Location.Y - pt.Y, 8),
Angle.ToDegrees(part.Rotation));
}
}

View File

@@ -19,12 +19,12 @@ namespace OpenNest.Forms
public void SetCutDistance(double dist)
{
cutDistanceLabel.Text = string.Format("{0} {1}", Math.Round(dist, 4), UnitsHelper.GetShortString(Units));
cutDistanceLabel.Text = string.Format("{0} {1}", System.Math.Round(dist, 4), UnitsHelper.GetShortString(Units));
}
public void SetRapidDistance(double dist)
{
rapidDistanceLabel.Text = string.Format("{0} {1}", Math.Round(dist, 4), UnitsHelper.GetShortString(Units));
rapidDistanceLabel.Text = string.Format("{0} {1}", System.Math.Round(dist, 4), UnitsHelper.GetShortString(Units));
}
public void SetIntersectionCount(int count)

View File

@@ -3,6 +3,7 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using OpenNest.CNC;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
{
@@ -97,12 +98,12 @@ namespace OpenNest
}
// start angle in degrees
var startAngle = Angle.ToDegrees(Math.Atan2(
var startAngle = Angle.ToDegrees(System.Math.Atan2(
curpos.Y - center.Y,
curpos.X - center.X));
// end angle in degrees
var endAngle = Angle.ToDegrees(Math.Atan2(
var endAngle = Angle.ToDegrees(System.Math.Atan2(
endpt.Y - center.Y,
endpt.X - center.X));
@@ -117,7 +118,7 @@ namespace OpenNest
var dx = endpt.X - center.X;
var dy = endpt.Y - center.Y;
var radius = Math.Sqrt(dx * dx + dy * dy);
var radius = System.Math.Sqrt(dx * dx + dy * dy);
var pt = new PointF((float)(center.X - radius), (float)(center.Y - radius));
var size = (float)(radius * 2.0);

View File

@@ -5,6 +5,7 @@ using netDxf;
using netDxf.Entities;
using netDxf.Tables;
using OpenNest.CNC;
using OpenNest.Math;
namespace OpenNest.IO
{
@@ -13,7 +14,7 @@ namespace OpenNest.IO
public class DxfExporter
{
private const double RadToDeg = 180.0 / Math.PI;
private const double RadToDeg = 180.0 / System.Math.PI;
private DxfDocument doc;
private Vector2 curpos;
@@ -247,12 +248,12 @@ namespace OpenNest.IO
}
// start angle in radians
var startAngle = Math.Atan2(
var startAngle = System.Math.Atan2(
curpos.Y - center.Y,
curpos.X - center.X);
// end angle in radians
var endAngle = Math.Atan2(
var endAngle = System.Math.Atan2(
endpt.Y - center.Y,
endpt.X - center.X);
@@ -266,7 +267,7 @@ namespace OpenNest.IO
var dx = endpt.X - center.X;
var dy = endpt.Y - center.Y;
var radius = Math.Sqrt(dx * dx + dy * dy);
var radius = System.Math.Sqrt(dx * dx + dy * dy);
if (startAngle.IsEqualTo(endAngle))
{

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest.IO
{

View File

@@ -7,6 +7,7 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using OpenNest.CNC;
using OpenNest.Math;
namespace OpenNest.IO
{

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Xml;
using OpenNest.CNC;
using OpenNest.Math;
namespace OpenNest.IO
{
@@ -319,18 +320,18 @@ namespace OpenNest.IO
if (arcMove.Rotation == RotationType.CW)
{
sb.Append(string.Format("G02X{0}Y{1}I{2}J{3}",
Math.Round(arcMove.EndPoint.X, OutputPrecision),
Math.Round(arcMove.EndPoint.Y, OutputPrecision),
Math.Round(arcMove.CenterPoint.X, OutputPrecision),
Math.Round(arcMove.CenterPoint.Y, OutputPrecision)));
System.Math.Round(arcMove.EndPoint.X, OutputPrecision),
System.Math.Round(arcMove.EndPoint.Y, OutputPrecision),
System.Math.Round(arcMove.CenterPoint.X, OutputPrecision),
System.Math.Round(arcMove.CenterPoint.Y, OutputPrecision)));
}
else
{
sb.Append(string.Format("G03X{0}Y{1}I{2}J{3}",
Math.Round(arcMove.EndPoint.X, OutputPrecision),
Math.Round(arcMove.EndPoint.Y, OutputPrecision),
Math.Round(arcMove.CenterPoint.X, OutputPrecision),
Math.Round(arcMove.CenterPoint.Y, OutputPrecision)));
System.Math.Round(arcMove.EndPoint.X, OutputPrecision),
System.Math.Round(arcMove.EndPoint.Y, OutputPrecision),
System.Math.Round(arcMove.CenterPoint.X, OutputPrecision),
System.Math.Round(arcMove.CenterPoint.Y, OutputPrecision)));
}
if (arcMove.Layer != LayerType.Cut)
@@ -351,8 +352,8 @@ namespace OpenNest.IO
var linearMove = (LinearMove)code;
sb.Append(string.Format("G01X{0}Y{1}",
Math.Round(linearMove.EndPoint.X, OutputPrecision),
Math.Round(linearMove.EndPoint.Y, OutputPrecision)));
System.Math.Round(linearMove.EndPoint.X, OutputPrecision),
System.Math.Round(linearMove.EndPoint.Y, OutputPrecision)));
if (linearMove.Layer != LayerType.Cut)
sb.Append(GetLayerString(linearMove.Layer));
@@ -365,8 +366,8 @@ namespace OpenNest.IO
var rapidMove = (RapidMove)code;
return string.Format("G00X{0}Y{1}",
Math.Round(rapidMove.EndPoint.X, OutputPrecision),
Math.Round(rapidMove.EndPoint.Y, OutputPrecision));
System.Math.Round(rapidMove.EndPoint.X, OutputPrecision),
System.Math.Round(rapidMove.EndPoint.Y, OutputPrecision));
}
case CodeType.SetFeedrate: