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

@@ -1,4 +1,6 @@
namespace OpenNest
using OpenNest.Math;
namespace OpenNest
{
public class Box
{

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest.CNC
{
@@ -398,10 +399,10 @@ namespace OpenNest.CNC
if (Angle.IsBetweenRad(Angle.HalfPI, startAngle, endAngle))
maxY1 = centerpt.Y + radius;
if (Angle.IsBetweenRad(Math.PI, startAngle, endAngle))
if (Angle.IsBetweenRad(System.Math.PI, startAngle, endAngle))
minX1 = centerpt.X - radius;
const double oneHalfPI = Math.PI * 1.5;
const double oneHalfPI = System.Math.PI * 1.5;
if (Angle.IsBetweenRad(oneHalfPI, startAngle, endAngle))
minY1 = centerpt.Y - radius;

View File

@@ -1,4 +1,6 @@
namespace OpenNest.CNC
using OpenNest.Math;
namespace OpenNest.CNC
{
public class SubProgramCall : ICode
{

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using OpenNest.CNC;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
{
@@ -99,7 +100,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 layer = ConvertLayer(arcMove.Layer);
if (startAngle.IsEqualTo(endAngle))

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using OpenNest.Math;
namespace OpenNest.Geometry
{
@@ -139,8 +140,8 @@ namespace OpenNest.Geometry
public Vector StartPoint()
{
return new Vector(
Center.X + Radius * Math.Cos(StartAngle),
Center.Y + Radius * Math.Sin(StartAngle));
Center.X + Radius * System.Math.Cos(StartAngle),
Center.Y + Radius * System.Math.Sin(StartAngle));
}
/// <summary>
@@ -150,8 +151,8 @@ namespace OpenNest.Geometry
public Vector EndPoint()
{
return new Vector(
Center.X + Radius * Math.Cos(EndAngle),
Center.Y + Radius * Math.Sin(EndAngle));
Center.X + Radius * System.Math.Cos(EndAngle),
Center.Y + Radius * System.Math.Sin(EndAngle));
}
/// <summary>
@@ -201,8 +202,8 @@ namespace OpenNest.Geometry
var angle = stepAngle * i + StartAngle;
points.Add(new Vector(
Math.Cos(angle) * Radius + Center.X,
Math.Sin(angle) * Radius + Center.Y));
System.Math.Cos(angle) * Radius + Center.X,
System.Math.Sin(angle) * Radius + Center.Y));
}
return points;
@@ -213,7 +214,7 @@ namespace OpenNest.Geometry
/// </summary>
public override double Length
{
get { return Diameter * Math.PI * SweepAngle() / Angle.TwoPI; }
get { return Diameter * System.Math.PI * SweepAngle() / Angle.TwoPI; }
}
/// <summary>
@@ -356,10 +357,10 @@ namespace OpenNest.Geometry
if (Angle.IsBetweenRad(Angle.HalfPI, angle1, angle2))
maxY = Center.Y + Radius;
if (Angle.IsBetweenRad(Math.PI, angle1, angle2))
if (Angle.IsBetweenRad(System.Math.PI, angle1, angle2))
minX = Center.X - Radius;
const double oneHalfPI = Math.PI * 1.5;
const double oneHalfPI = System.Math.PI * 1.5;
if (Angle.IsBetweenRad(oneHalfPI, angle1, angle2))
minY = Center.Y - Radius;
@@ -405,8 +406,8 @@ namespace OpenNest.Geometry
if (Angle.IsBetweenRad(angle, StartAngle, EndAngle, IsReversed))
{
return new Vector(
Math.Cos(angle) * Radius + Center.X,
Math.Sin(angle) * Radius + Center.Y);
System.Math.Cos(angle) * Radius + Center.X,
System.Math.Sin(angle) * Radius + Center.Y);
}
else
{

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using OpenNest.Math;
namespace OpenNest.Geometry
{
@@ -84,7 +85,7 @@ namespace OpenNest.Geometry
/// <returns></returns>
public double Area()
{
return Math.PI * Radius * Radius;
return System.Math.PI * Radius * Radius;
}
/// <summary>
@@ -93,7 +94,7 @@ namespace OpenNest.Geometry
/// <returns></returns>
public double Circumference()
{
return Math.PI * Diameter;
return System.Math.PI * Diameter;
}
/// <summary>
@@ -131,8 +132,8 @@ namespace OpenNest.Geometry
var angle = stepAngle * i;
points.Add(new Vector(
Math.Cos(angle) * Radius + Center.X,
Math.Sin(angle) * Radius + Center.Y));
System.Math.Cos(angle) * Radius + Center.X,
System.Math.Sin(angle) * Radius + Center.Y));
}
return points;
@@ -290,8 +291,8 @@ namespace OpenNest.Geometry
var angle = Center.AngleTo(pt);
return new Vector(
Math.Cos(angle) * Radius + Center.X,
Math.Sin(angle) * Radius + Center.Y);
System.Math.Cos(angle) * Radius + Center.X,
System.Math.Sin(angle) * Radius + Center.Y);
}
/// <summary>
@@ -324,7 +325,7 @@ namespace OpenNest.Geometry
public override bool Intersects(Circle circle)
{
var dist = Center.DistanceTo(circle.Center);
return (dist < (Radius + circle.Radius) && dist > Math.Abs(Radius - circle.Radius));
return (dist < (Radius + circle.Radius) && dist > System.Math.Abs(Radius - circle.Radius));
}
/// <summary>

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using OpenNest.Math;
namespace OpenNest.Geometry
{

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using OpenNest.Math;
namespace OpenNest.Geometry
{
@@ -219,7 +220,7 @@ namespace OpenNest.Geometry
{
var m1 = Slope();
var m2 = line.Slope();
return Math.Atan(Math.Abs((m2 - m1) / (1 + m2 * m1)));
return System.Math.Atan(System.Math.Abs((m2 - m1) / (1 + m2 * m1)));
}
/// <summary>
@@ -252,7 +253,7 @@ namespace OpenNest.Geometry
{
var x = EndPoint.X - StartPoint.X;
var y = EndPoint.Y - StartPoint.Y;
return Math.Sqrt(x * x + y * y);
return System.Math.Sqrt(x * x + y * y);
}
}
@@ -391,10 +392,10 @@ namespace OpenNest.Geometry
public override Entity OffsetEntity(double distance, OffsetSide side)
{
var angle = OpenNest.Angle.NormalizeRad(Angle() + OpenNest.Angle.HalfPI);
var angle = OpenNest.Math.Angle.NormalizeRad(Angle() + OpenNest.Math.Angle.HalfPI);
var x = Math.Cos(angle) * distance;
var y = Math.Sin(angle) * distance;
var x = System.Math.Cos(angle) * distance;
var y = System.Math.Sin(angle) * distance;
var pt = new Vector(x, y);

View File

@@ -73,7 +73,7 @@ namespace OpenNest.Geometry
if (Vertices.Count < 3)
return 0.0;
return Math.Abs(CalculateArea());
return System.Math.Abs(CalculateArea());
}
/// <summary>

View File

@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
{
@@ -17,7 +18,7 @@ namespace OpenNest
/// <returns></returns>
public static double RoundDownToNearest(double num, double factor)
{
return factor.IsEqualTo(0) ? num : Math.Floor(num / factor) * factor;
return factor.IsEqualTo(0) ? num : System.Math.Floor(num / factor) * factor;
}
/// <summary>
@@ -28,7 +29,7 @@ namespace OpenNest
/// <returns></returns>
public static double RoundUpToNearest(double num, double factor)
{
return factor.IsEqualTo(0) ? num : Math.Ceiling(num / factor) * factor;
return factor.IsEqualTo(0) ? num : System.Math.Ceiling(num / factor) * factor;
}
/// <summary>
@@ -39,7 +40,7 @@ namespace OpenNest
/// <returns></returns>
public static double RoundToNearest(double num, double factor)
{
return factor.IsEqualTo(0) ? num : Math.Round(num / factor) * factor;
return factor.IsEqualTo(0) ? num : System.Math.Round(num / factor) * factor;
}
public static void Optimize(IList<Arc> arcs)
@@ -483,7 +484,7 @@ namespace OpenNest
}
// check if one circle contains the other
if (distance < Math.Abs(circle1.Radius - circle2.Radius))
if (distance < System.Math.Abs(circle1.Radius - circle2.Radius))
{
pts = new List<Vector>();
return false;
@@ -491,7 +492,7 @@ namespace OpenNest
var d = circle2.Center - circle1.Center;
var a = (circle1.Radius * circle1.Radius - circle2.Radius * circle2.Radius + distance * distance) / (2.0 * distance);
var h = Math.Sqrt(circle1.Radius * circle1.Radius - a * a);
var h = System.Math.Sqrt(circle1.Radius * circle1.Radius - a * a);
var pt = new Vector(
circle1.Center.X + (a * d.X) / distance,
@@ -541,13 +542,13 @@ namespace OpenNest
return true;
}
t = (-b + Math.Sqrt(det)) / (2 * a);
t = (-b + System.Math.Sqrt(det)) / (2 * a);
var pt2 = new Vector(line.StartPoint.X + t * d1.X, line.StartPoint.Y + t * d1.Y);
if (line.BoundingBox.Contains(pt2))
pts.Add(pt2);
t = (-b - Math.Sqrt(det)) / (2 * a);
t = (-b - System.Math.Sqrt(det)) / (2 * a);
var pt3 = new Vector(line.StartPoint.X + t * d1.X, line.StartPoint.Y + t * d1.Y);
if (line.BoundingBox.Contains(pt3))

View File

@@ -1,28 +1,28 @@
using System;
namespace OpenNest
namespace OpenNest.Math
{
public static class Angle
{
/// <summary>
/// Number of radians equal to 1 degree.
/// </summary>
public const double RadPerDeg = Math.PI / 180.0;
public const double RadPerDeg = System.Math.PI / 180.0;
/// <summary>
/// Number of degrees equal to 1 radian.
/// </summary>
public const double DegPerRad = 180.0 / Math.PI;
public const double DegPerRad = 180.0 / System.Math.PI;
/// <summary>
/// Half of PI.
/// </summary>
public const double HalfPI = Math.PI * 0.5;
public const double HalfPI = System.Math.PI * 0.5;
/// <summary>
/// 2 x PI
/// </summary>
public const double TwoPI = Math.PI * 2.0;
public const double TwoPI = System.Math.PI * 2.0;
/// <summary>
/// Converts radians to degrees.

View File

@@ -1,4 +1,4 @@
namespace OpenNest
namespace OpenNest.Math
{
public static class EvenOdd
{

View File

@@ -1,4 +1,4 @@
namespace OpenNest
namespace OpenNest.Math
{
public static class Generic
{

View File

@@ -1,6 +1,6 @@
using System;
namespace OpenNest
namespace OpenNest.Math
{
public static class Tolerance
{
@@ -8,7 +8,7 @@ namespace OpenNest
public static bool IsEqualTo(this double a, double b, double tolerance = Epsilon)
{
return Math.Abs(b - a) <= tolerance;
return System.Math.Abs(b - a) <= tolerance;
}
}
}

View File

@@ -1,6 +1,6 @@
using System;
namespace OpenNest
namespace OpenNest.Math
{
public static class Trigonometry
{
@@ -12,7 +12,7 @@ namespace OpenNest
/// <returns></returns>
public static double Base(double height, double hypotenuse)
{
return Math.Sqrt(hypotenuse * hypotenuse - height * height);
return System.Math.Sqrt(hypotenuse * hypotenuse - height * height);
}
/// <summary>
@@ -23,7 +23,7 @@ namespace OpenNest
/// <returns></returns>
public static double Height(double bottom, double hypotenuse)
{
return Math.Sqrt(hypotenuse * hypotenuse - bottom * bottom);
return System.Math.Sqrt(hypotenuse * hypotenuse - bottom * bottom);
}
/// <summary>
@@ -34,7 +34,7 @@ namespace OpenNest
/// <returns></returns>
public static double Hypotenuse(double height, double bottom)
{
return Math.Sqrt(height * height + bottom * bottom);
return System.Math.Sqrt(height * height + bottom * bottom);
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using OpenNest.Math;
namespace OpenNest
{
@@ -37,7 +38,7 @@ namespace OpenNest
if (diff.IsEqualTo(Angle.TwoPI))
return false;
if ((diff > Math.PI || diff.IsEqualTo(Math.PI)) && Allow180Equivalent)
if ((diff > System.Math.PI || diff.IsEqualTo(System.Math.PI)) && Allow180Equivalent)
return false;
return true;

View File

@@ -39,7 +39,7 @@
<ItemGroup>
<Compile Include="Align.cs" />
<Compile Include="AlignType.cs" />
<Compile Include="Angle.cs" />
<Compile Include="Math\Angle.cs" />
<Compile Include="CNC\KerfType.cs" />
<Compile Include="CNC\CodeType.cs" />
<Compile Include="CNC\LayerType.cs" />
@@ -47,7 +47,7 @@
<Compile Include="CutParameters.cs" />
<Compile Include="Drawing.cs" />
<Compile Include="Collections\DrawingCollection.cs" />
<Compile Include="EvenOdd.cs" />
<Compile Include="Math\EvenOdd.cs" />
<Compile Include="ConvertGeometry.cs" />
<Compile Include="CNC\ArcMove.cs" />
<Compile Include="CNC\Comment.cs" />
@@ -58,7 +58,7 @@
<Compile Include="CNC\Feedrate.cs" />
<Compile Include="CNC\Kerf.cs" />
<Compile Include="CNC\SubProgramCall.cs" />
<Compile Include="Generic.cs" />
<Compile Include="Math\Generic.cs" />
<Compile Include="Geometry\Arc.cs" />
<Compile Include="BoundingBox.cs" />
<Compile Include="Box.cs" />
@@ -77,7 +77,7 @@
<Compile Include="RotationType.cs" />
<Compile Include="Geometry\Shape.cs" />
<Compile Include="Size.cs" />
<Compile Include="Tolerance.cs" />
<Compile Include="Math\Tolerance.cs" />
<Compile Include="Units.cs" />
<Compile Include="Vector.cs" />
<Compile Include="IPostProcessor.cs" />
@@ -93,11 +93,11 @@
<Compile Include="CNC\Program.cs" />
<Compile Include="ConvertProgram.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Quantity.cs" />
<Compile Include="DwgQty.cs" />
<Compile Include="Spacing.cs" />
<Compile Include="Timing.cs" />
<Compile Include="TimingInfo.cs" />
<Compile Include="Trigonometry.cs" />
<Compile Include="Math\Trigonometry.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.Collections;
using OpenNest.Math;
namespace OpenNest
{
@@ -113,7 +114,7 @@ namespace OpenNest
/// <param name="keepSameQuadrant"></param>
public void Rotate90(RotationType rotationDirection, bool keepSameQuadrant = true)
{
const double oneAndHalfPI = Math.PI * 1.5;
const double oneAndHalfPI = System.Math.PI * 1.5;
Size = new Size(Size.Height, Size.Width);
@@ -217,11 +218,11 @@ namespace OpenNest
return;
}
Rotate(Math.PI, centerpt);
Rotate(System.Math.PI, centerpt);
}
else
{
Rotate(Math.PI);
Rotate(System.Math.PI);
Quadrant = (Quadrant + 2) % 4;
if (Quadrant == 0)
@@ -386,23 +387,23 @@ namespace OpenNest
switch (Quadrant)
{
case 1:
width = Math.Abs(bounds.Right) + EdgeSpacing.Right;
height = Math.Abs(bounds.Top) + EdgeSpacing.Top;
width = System.Math.Abs(bounds.Right) + EdgeSpacing.Right;
height = System.Math.Abs(bounds.Top) + EdgeSpacing.Top;
break;
case 2:
width = Math.Abs(bounds.Left) + EdgeSpacing.Left;
height = Math.Abs(bounds.Top) + EdgeSpacing.Top;
width = System.Math.Abs(bounds.Left) + EdgeSpacing.Left;
height = System.Math.Abs(bounds.Top) + EdgeSpacing.Top;
break;
case 3:
width = Math.Abs(bounds.Left) + EdgeSpacing.Left;
height = Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
width = System.Math.Abs(bounds.Left) + EdgeSpacing.Left;
height = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
break;
case 4:
width = Math.Abs(bounds.Right) + EdgeSpacing.Right;
height = Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
width = System.Math.Abs(bounds.Right) + EdgeSpacing.Right;
height = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
break;
default:

View File

@@ -49,7 +49,7 @@ namespace OpenNest
public string ToString(int decimalPlaces)
{
return string.Format("{0} x {1}", Math.Round(Height, decimalPlaces), Math.Round(Width, decimalPlaces));
return string.Format("{0} x {1}", System.Math.Round(Height, decimalPlaces), System.Math.Round(Width, decimalPlaces));
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using OpenNest.Math;
namespace OpenNest
{
@@ -21,7 +22,7 @@ namespace OpenNest
var vx = pt.X - X;
var vy = pt.Y - Y;
return Math.Sqrt(vx * vx + vy * vy);
return System.Math.Sqrt(vx * vx + vy * vy);
}
public double DistanceTo(double x, double y)
@@ -29,7 +30,7 @@ namespace OpenNest
var vx = x - X;
var vy = y - Y;
return Math.Sqrt(vx * vx + vy * vy);
return System.Math.Sqrt(vx * vx + vy * vy);
}
public double DotProduct(Vector pt)
@@ -39,7 +40,7 @@ namespace OpenNest
public double Angle()
{
return OpenNest.Angle.NormalizeRad(Math.Atan2(Y, X));
return OpenNest.Math.Angle.NormalizeRad(System.Math.Atan2(Y, X));
}
/// <summary>
@@ -75,7 +76,7 @@ namespace OpenNest
var dot = v1.X * v2.X + v1.Y + v2.Y;
var det = v1.X * v2.X - v1.Y + v2.Y;
return Math.Atan2(det, dot);
return System.Math.Atan2(det, dot);
}
public static Vector operator +(Vector pt1, Vector pt2)
@@ -137,8 +138,8 @@ namespace OpenNest
{
var v = new Vector();
var cos = Math.Cos(angle);
var sin = Math.Sin(angle);
var cos = System.Math.Cos(angle);
var sin = System.Math.Sin(angle);
v.X = X * cos - Y * sin;
v.Y = X * sin + Y * cos;
@@ -151,8 +152,8 @@ namespace OpenNest
var v = new Vector();
var pt = this - origin;
var cos = Math.Cos(angle);
var sin = Math.Sin(angle);
var cos = System.Math.Cos(angle);
var sin = System.Math.Sin(angle);
v.X = pt.X * cos - pt.Y * sin + origin.X;
v.Y = pt.X * sin + pt.Y * cos + origin.Y;

View File

@@ -1,4 +1,5 @@
using System;
using OpenNest.Math;
namespace OpenNest
{
@@ -18,18 +19,18 @@ namespace OpenNest
}
count1 = 0;
count2 = (int)Math.Floor(overallLength / length2);
count2 = (int)System.Math.Floor(overallLength / length2);
return true;
}
if (length2 > overallLength)
{
count1 = (int)Math.Floor(overallLength / length1);
count1 = (int)System.Math.Floor(overallLength / length1);
count2 = 0;
return true;
}
var maxCountLength1 = (int)Math.Floor(overallLength / length1);
var maxCountLength1 = (int)System.Math.Floor(overallLength / length1);
count1 = maxCountLength1;
count2 = 0;
@@ -45,7 +46,7 @@ namespace OpenNest
if (remnant1 >= length2)
{
var countLength2 = (int)Math.Floor(remnant1 / length2);
var countLength2 = (int)System.Math.Floor(remnant1 / length2);
var remnant2 = remnant1 - length2 * countLength2;
if (!(remnant2 < remnant))

View File

@@ -1,4 +1,5 @@
using System;
using OpenNest.Math;
namespace OpenNest.CirclePacking
{
@@ -15,7 +16,7 @@ namespace OpenNest.CirclePacking
Bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
Bin.Top - item.BoundingBox.Top + Tolerance.Epsilon);
var rows = Math.Floor((Bin.Height + Tolerance.Epsilon) / (item.Diameter));
var rows = System.Math.Floor((Bin.Height + Tolerance.Epsilon) / (item.Diameter));
var diameter = item.Diameter;
var remaining = Bin.Height - diameter * rows;

View File

@@ -1,4 +1,5 @@
using System;
using OpenNest.Math;
namespace OpenNest.CirclePacking
{
@@ -33,7 +34,7 @@ namespace OpenNest.CirclePacking
bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
bin.Top - item.BoundingBox.Top + Tolerance.Epsilon);
var count = Math.Floor((bin.Width + Tolerance.Epsilon) / item.Diameter);
var count = System.Math.Floor((bin.Width + Tolerance.Epsilon) / item.Diameter);
if (count == 0)
return bin;
@@ -69,7 +70,7 @@ namespace OpenNest.CirclePacking
Bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
Bin.Top - item.BoundingBox.Top + Tolerance.Epsilon);
var count = Math.Floor((bin.Height + Tolerance.Epsilon) / item.Diameter);
var count = System.Math.Floor((bin.Height + Tolerance.Epsilon) / item.Diameter);
if (count == 0)
return bin;

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using OpenNest.Math;
using OpenNest.RectanglePacking;
namespace OpenNest
@@ -143,7 +144,7 @@ namespace OpenNest
var item = items[i];
var binItem = ConvertToRectangleItem(item, i);
int maxQty = (int)Math.Floor(Plate.Area() / binItem.Area());
int maxQty = (int)System.Math.Floor(Plate.Area() / binItem.Area());
int qty = item.Quantity < maxQty
? item.Quantity

View File

@@ -1,4 +1,5 @@
using System;
using OpenNest.Math;
namespace OpenNest.RectanglePacking
{
@@ -45,8 +46,8 @@ namespace OpenNest.RectanglePacking
if (!BestCombination.FindFrom2(item.Width, item.Height, bin.Width, out normalColumns, out rotateColumns))
return bin;
var normalRows = (int)Math.Floor((bin.Height + Tolerance.Epsilon) / item.Height);
var rotateRows = (int)Math.Floor((bin.Height + Tolerance.Epsilon) / item.Width);
var normalRows = (int)System.Math.Floor((bin.Height + Tolerance.Epsilon) / item.Height);
var rotateRows = (int)System.Math.Floor((bin.Height + Tolerance.Epsilon) / item.Width);
item.Location = bin.Location;
@@ -70,8 +71,8 @@ namespace OpenNest.RectanglePacking
if (!BestCombination.FindFrom2(item.Height, item.Width, Bin.Height, out normalRows, out rotateRows))
return bin;
var normalColumns = (int)Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
var rotateColumns = (int)Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Height);
var normalColumns = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
var rotateColumns = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Height);
item.Location = bin.Location;

View File

@@ -1,4 +1,5 @@
using System;
using OpenNest.Math;
namespace OpenNest.RectanglePacking
{
@@ -13,8 +14,8 @@ namespace OpenNest.RectanglePacking
public override void Fill(Item item)
{
var ycount = (int)Math.Floor((Bin.Height + Tolerance.Epsilon) / item.Height);
var xcount = (int)Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
var ycount = (int)System.Math.Floor((Bin.Height + Tolerance.Epsilon) / item.Height);
var xcount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
var count = ycount * xcount;
for (int i = 0; i < xcount; i++)
@@ -35,8 +36,8 @@ namespace OpenNest.RectanglePacking
public override void Fill(Item item, int maxCount)
{
var ycount = (int)Math.Floor((Bin.Height + Tolerance.Epsilon) / item.Height);
var xcount = (int)Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
var ycount = (int)System.Math.Floor((Bin.Height + Tolerance.Epsilon) / item.Height);
var xcount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
var count = ycount * xcount;
if (count <= maxCount)
@@ -50,13 +51,13 @@ namespace OpenNest.RectanglePacking
if (NestDirection == NestDirection.Vertical)
{
columns = (int)Math.Ceiling((double)maxCount / ycount);
rows = (int)Math.Ceiling((double)maxCount / columns);
columns = (int)System.Math.Ceiling((double)maxCount / ycount);
rows = (int)System.Math.Ceiling((double)maxCount / columns);
}
else
{
rows = (int)Math.Ceiling((double)maxCount / xcount);
columns = (int)Math.Ceiling((double)maxCount / rows);
rows = (int)System.Math.Ceiling((double)maxCount / xcount);
columns = (int)System.Math.Ceiling((double)maxCount / rows);
}
if (item.Width > item.Height)

View File

@@ -1,4 +1,5 @@

using OpenNest.Math;
namespace OpenNest.RectanglePacking
{
internal class FillSameRotation : FillEngine

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using OpenNest.Math;
namespace OpenNest.RectanglePacking
{

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.Math;
namespace OpenNest.RectanglePacking
{

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: