Move math utilities to OpenNest.Math namespace
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
namespace OpenNest
|
using OpenNest.Math;
|
||||||
|
|
||||||
|
namespace OpenNest
|
||||||
{
|
{
|
||||||
public class Box
|
public class Box
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.CNC
|
namespace OpenNest.CNC
|
||||||
{
|
{
|
||||||
@@ -398,10 +399,10 @@ namespace OpenNest.CNC
|
|||||||
if (Angle.IsBetweenRad(Angle.HalfPI, startAngle, endAngle))
|
if (Angle.IsBetweenRad(Angle.HalfPI, startAngle, endAngle))
|
||||||
maxY1 = centerpt.Y + radius;
|
maxY1 = centerpt.Y + radius;
|
||||||
|
|
||||||
if (Angle.IsBetweenRad(Math.PI, startAngle, endAngle))
|
if (Angle.IsBetweenRad(System.Math.PI, startAngle, endAngle))
|
||||||
minX1 = centerpt.X - radius;
|
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))
|
if (Angle.IsBetweenRad(oneHalfPI, startAngle, endAngle))
|
||||||
minY1 = centerpt.Y - radius;
|
minY1 = centerpt.Y - radius;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace OpenNest.CNC
|
using OpenNest.Math;
|
||||||
|
|
||||||
|
namespace OpenNest.CNC
|
||||||
{
|
{
|
||||||
public class SubProgramCall : ICode
|
public class SubProgramCall : ICode
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenNest.CNC;
|
using OpenNest.CNC;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest
|
||||||
{
|
{
|
||||||
@@ -99,7 +100,7 @@ namespace OpenNest
|
|||||||
var dx = endpt.X - center.X;
|
var dx = endpt.X - center.X;
|
||||||
var dy = endpt.Y - center.Y;
|
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);
|
var layer = ConvertLayer(arcMove.Layer);
|
||||||
|
|
||||||
if (startAngle.IsEqualTo(endAngle))
|
if (startAngle.IsEqualTo(endAngle))
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.Geometry
|
namespace OpenNest.Geometry
|
||||||
{
|
{
|
||||||
@@ -139,8 +140,8 @@ namespace OpenNest.Geometry
|
|||||||
public Vector StartPoint()
|
public Vector StartPoint()
|
||||||
{
|
{
|
||||||
return new Vector(
|
return new Vector(
|
||||||
Center.X + Radius * Math.Cos(StartAngle),
|
Center.X + Radius * System.Math.Cos(StartAngle),
|
||||||
Center.Y + Radius * Math.Sin(StartAngle));
|
Center.Y + Radius * System.Math.Sin(StartAngle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -150,8 +151,8 @@ namespace OpenNest.Geometry
|
|||||||
public Vector EndPoint()
|
public Vector EndPoint()
|
||||||
{
|
{
|
||||||
return new Vector(
|
return new Vector(
|
||||||
Center.X + Radius * Math.Cos(EndAngle),
|
Center.X + Radius * System.Math.Cos(EndAngle),
|
||||||
Center.Y + Radius * Math.Sin(EndAngle));
|
Center.Y + Radius * System.Math.Sin(EndAngle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -201,8 +202,8 @@ namespace OpenNest.Geometry
|
|||||||
var angle = stepAngle * i + StartAngle;
|
var angle = stepAngle * i + StartAngle;
|
||||||
|
|
||||||
points.Add(new Vector(
|
points.Add(new Vector(
|
||||||
Math.Cos(angle) * Radius + Center.X,
|
System.Math.Cos(angle) * Radius + Center.X,
|
||||||
Math.Sin(angle) * Radius + Center.Y));
|
System.Math.Sin(angle) * Radius + Center.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
return points;
|
return points;
|
||||||
@@ -213,7 +214,7 @@ namespace OpenNest.Geometry
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override double Length
|
public override double Length
|
||||||
{
|
{
|
||||||
get { return Diameter * Math.PI * SweepAngle() / Angle.TwoPI; }
|
get { return Diameter * System.Math.PI * SweepAngle() / Angle.TwoPI; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -356,10 +357,10 @@ namespace OpenNest.Geometry
|
|||||||
if (Angle.IsBetweenRad(Angle.HalfPI, angle1, angle2))
|
if (Angle.IsBetweenRad(Angle.HalfPI, angle1, angle2))
|
||||||
maxY = Center.Y + Radius;
|
maxY = Center.Y + Radius;
|
||||||
|
|
||||||
if (Angle.IsBetweenRad(Math.PI, angle1, angle2))
|
if (Angle.IsBetweenRad(System.Math.PI, angle1, angle2))
|
||||||
minX = Center.X - Radius;
|
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))
|
if (Angle.IsBetweenRad(oneHalfPI, angle1, angle2))
|
||||||
minY = Center.Y - Radius;
|
minY = Center.Y - Radius;
|
||||||
@@ -405,8 +406,8 @@ namespace OpenNest.Geometry
|
|||||||
if (Angle.IsBetweenRad(angle, StartAngle, EndAngle, IsReversed))
|
if (Angle.IsBetweenRad(angle, StartAngle, EndAngle, IsReversed))
|
||||||
{
|
{
|
||||||
return new Vector(
|
return new Vector(
|
||||||
Math.Cos(angle) * Radius + Center.X,
|
System.Math.Cos(angle) * Radius + Center.X,
|
||||||
Math.Sin(angle) * Radius + Center.Y);
|
System.Math.Sin(angle) * Radius + Center.Y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.Geometry
|
namespace OpenNest.Geometry
|
||||||
{
|
{
|
||||||
@@ -84,7 +85,7 @@ namespace OpenNest.Geometry
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public double Area()
|
public double Area()
|
||||||
{
|
{
|
||||||
return Math.PI * Radius * Radius;
|
return System.Math.PI * Radius * Radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -93,7 +94,7 @@ namespace OpenNest.Geometry
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public double Circumference()
|
public double Circumference()
|
||||||
{
|
{
|
||||||
return Math.PI * Diameter;
|
return System.Math.PI * Diameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -131,8 +132,8 @@ namespace OpenNest.Geometry
|
|||||||
var angle = stepAngle * i;
|
var angle = stepAngle * i;
|
||||||
|
|
||||||
points.Add(new Vector(
|
points.Add(new Vector(
|
||||||
Math.Cos(angle) * Radius + Center.X,
|
System.Math.Cos(angle) * Radius + Center.X,
|
||||||
Math.Sin(angle) * Radius + Center.Y));
|
System.Math.Sin(angle) * Radius + Center.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
return points;
|
return points;
|
||||||
@@ -290,8 +291,8 @@ namespace OpenNest.Geometry
|
|||||||
var angle = Center.AngleTo(pt);
|
var angle = Center.AngleTo(pt);
|
||||||
|
|
||||||
return new Vector(
|
return new Vector(
|
||||||
Math.Cos(angle) * Radius + Center.X,
|
System.Math.Cos(angle) * Radius + Center.X,
|
||||||
Math.Sin(angle) * Radius + Center.Y);
|
System.Math.Sin(angle) * Radius + Center.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -324,7 +325,7 @@ namespace OpenNest.Geometry
|
|||||||
public override bool Intersects(Circle circle)
|
public override bool Intersects(Circle circle)
|
||||||
{
|
{
|
||||||
var dist = Center.DistanceTo(circle.Center);
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.Geometry
|
namespace OpenNest.Geometry
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.Geometry
|
namespace OpenNest.Geometry
|
||||||
{
|
{
|
||||||
@@ -219,7 +220,7 @@ namespace OpenNest.Geometry
|
|||||||
{
|
{
|
||||||
var m1 = Slope();
|
var m1 = Slope();
|
||||||
var m2 = line.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>
|
/// <summary>
|
||||||
@@ -252,7 +253,7 @@ namespace OpenNest.Geometry
|
|||||||
{
|
{
|
||||||
var x = EndPoint.X - StartPoint.X;
|
var x = EndPoint.X - StartPoint.X;
|
||||||
var y = EndPoint.Y - StartPoint.Y;
|
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)
|
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 x = System.Math.Cos(angle) * distance;
|
||||||
var y = Math.Sin(angle) * distance;
|
var y = System.Math.Sin(angle) * distance;
|
||||||
|
|
||||||
var pt = new Vector(x, y);
|
var pt = new Vector(x, y);
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace OpenNest.Geometry
|
|||||||
if (Vertices.Count < 3)
|
if (Vertices.Count < 3)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
||||||
return Math.Abs(CalculateArea());
|
return System.Math.Abs(CalculateArea());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest
|
||||||
{
|
{
|
||||||
@@ -17,7 +18,7 @@ namespace OpenNest
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static double RoundDownToNearest(double num, double factor)
|
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>
|
/// <summary>
|
||||||
@@ -28,7 +29,7 @@ namespace OpenNest
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static double RoundUpToNearest(double num, double factor)
|
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>
|
/// <summary>
|
||||||
@@ -39,7 +40,7 @@ namespace OpenNest
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static double RoundToNearest(double num, double factor)
|
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)
|
public static void Optimize(IList<Arc> arcs)
|
||||||
@@ -483,7 +484,7 @@ namespace OpenNest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if one circle contains the other
|
// 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>();
|
pts = new List<Vector>();
|
||||||
return false;
|
return false;
|
||||||
@@ -491,7 +492,7 @@ namespace OpenNest
|
|||||||
|
|
||||||
var d = circle2.Center - circle1.Center;
|
var d = circle2.Center - circle1.Center;
|
||||||
var a = (circle1.Radius * circle1.Radius - circle2.Radius * circle2.Radius + distance * distance) / (2.0 * distance);
|
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(
|
var pt = new Vector(
|
||||||
circle1.Center.X + (a * d.X) / distance,
|
circle1.Center.X + (a * d.X) / distance,
|
||||||
@@ -541,13 +542,13 @@ namespace OpenNest
|
|||||||
return true;
|
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);
|
var pt2 = new Vector(line.StartPoint.X + t * d1.X, line.StartPoint.Y + t * d1.Y);
|
||||||
|
|
||||||
if (line.BoundingBox.Contains(pt2))
|
if (line.BoundingBox.Contains(pt2))
|
||||||
pts.Add(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);
|
var pt3 = new Vector(line.StartPoint.X + t * d1.X, line.StartPoint.Y + t * d1.Y);
|
||||||
|
|
||||||
if (line.BoundingBox.Contains(pt3))
|
if (line.BoundingBox.Contains(pt3))
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest.Math
|
||||||
{
|
{
|
||||||
public static class Angle
|
public static class Angle
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of radians equal to 1 degree.
|
/// Number of radians equal to 1 degree.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const double RadPerDeg = Math.PI / 180.0;
|
public const double RadPerDeg = System.Math.PI / 180.0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of degrees equal to 1 radian.
|
/// Number of degrees equal to 1 radian.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const double DegPerRad = 180.0 / Math.PI;
|
public const double DegPerRad = 180.0 / System.Math.PI;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Half of PI.
|
/// Half of PI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const double HalfPI = Math.PI * 0.5;
|
public const double HalfPI = System.Math.PI * 0.5;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 2 x PI
|
/// 2 x PI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const double TwoPI = Math.PI * 2.0;
|
public const double TwoPI = System.Math.PI * 2.0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts radians to degrees.
|
/// Converts radians to degrees.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OpenNest
|
namespace OpenNest.Math
|
||||||
{
|
{
|
||||||
public static class EvenOdd
|
public static class EvenOdd
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace OpenNest
|
namespace OpenNest.Math
|
||||||
{
|
{
|
||||||
public static class Generic
|
public static class Generic
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest.Math
|
||||||
{
|
{
|
||||||
public static class Tolerance
|
public static class Tolerance
|
||||||
{
|
{
|
||||||
@@ -8,7 +8,7 @@ namespace OpenNest
|
|||||||
|
|
||||||
public static bool IsEqualTo(this double a, double b, double tolerance = Epsilon)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest.Math
|
||||||
{
|
{
|
||||||
public static class Trigonometry
|
public static class Trigonometry
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,7 @@ namespace OpenNest
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static double Base(double height, double hypotenuse)
|
public static double Base(double height, double hypotenuse)
|
||||||
{
|
{
|
||||||
return Math.Sqrt(hypotenuse * hypotenuse - height * height);
|
return System.Math.Sqrt(hypotenuse * hypotenuse - height * height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -23,7 +23,7 @@ namespace OpenNest
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static double Height(double bottom, double hypotenuse)
|
public static double Height(double bottom, double hypotenuse)
|
||||||
{
|
{
|
||||||
return Math.Sqrt(hypotenuse * hypotenuse - bottom * bottom);
|
return System.Math.Sqrt(hypotenuse * hypotenuse - bottom * bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -34,7 +34,7 @@ namespace OpenNest
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static double Hypotenuse(double height, double bottom)
|
public static double Hypotenuse(double height, double bottom)
|
||||||
{
|
{
|
||||||
return Math.Sqrt(height * height + bottom * bottom);
|
return System.Math.Sqrt(height * height + bottom * bottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest
|
||||||
{
|
{
|
||||||
@@ -37,7 +38,7 @@ namespace OpenNest
|
|||||||
if (diff.IsEqualTo(Angle.TwoPI))
|
if (diff.IsEqualTo(Angle.TwoPI))
|
||||||
return false;
|
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 false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Align.cs" />
|
<Compile Include="Align.cs" />
|
||||||
<Compile Include="AlignType.cs" />
|
<Compile Include="AlignType.cs" />
|
||||||
<Compile Include="Angle.cs" />
|
<Compile Include="Math\Angle.cs" />
|
||||||
<Compile Include="CNC\KerfType.cs" />
|
<Compile Include="CNC\KerfType.cs" />
|
||||||
<Compile Include="CNC\CodeType.cs" />
|
<Compile Include="CNC\CodeType.cs" />
|
||||||
<Compile Include="CNC\LayerType.cs" />
|
<Compile Include="CNC\LayerType.cs" />
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
<Compile Include="CutParameters.cs" />
|
<Compile Include="CutParameters.cs" />
|
||||||
<Compile Include="Drawing.cs" />
|
<Compile Include="Drawing.cs" />
|
||||||
<Compile Include="Collections\DrawingCollection.cs" />
|
<Compile Include="Collections\DrawingCollection.cs" />
|
||||||
<Compile Include="EvenOdd.cs" />
|
<Compile Include="Math\EvenOdd.cs" />
|
||||||
<Compile Include="ConvertGeometry.cs" />
|
<Compile Include="ConvertGeometry.cs" />
|
||||||
<Compile Include="CNC\ArcMove.cs" />
|
<Compile Include="CNC\ArcMove.cs" />
|
||||||
<Compile Include="CNC\Comment.cs" />
|
<Compile Include="CNC\Comment.cs" />
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
<Compile Include="CNC\Feedrate.cs" />
|
<Compile Include="CNC\Feedrate.cs" />
|
||||||
<Compile Include="CNC\Kerf.cs" />
|
<Compile Include="CNC\Kerf.cs" />
|
||||||
<Compile Include="CNC\SubProgramCall.cs" />
|
<Compile Include="CNC\SubProgramCall.cs" />
|
||||||
<Compile Include="Generic.cs" />
|
<Compile Include="Math\Generic.cs" />
|
||||||
<Compile Include="Geometry\Arc.cs" />
|
<Compile Include="Geometry\Arc.cs" />
|
||||||
<Compile Include="BoundingBox.cs" />
|
<Compile Include="BoundingBox.cs" />
|
||||||
<Compile Include="Box.cs" />
|
<Compile Include="Box.cs" />
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
<Compile Include="RotationType.cs" />
|
<Compile Include="RotationType.cs" />
|
||||||
<Compile Include="Geometry\Shape.cs" />
|
<Compile Include="Geometry\Shape.cs" />
|
||||||
<Compile Include="Size.cs" />
|
<Compile Include="Size.cs" />
|
||||||
<Compile Include="Tolerance.cs" />
|
<Compile Include="Math\Tolerance.cs" />
|
||||||
<Compile Include="Units.cs" />
|
<Compile Include="Units.cs" />
|
||||||
<Compile Include="Vector.cs" />
|
<Compile Include="Vector.cs" />
|
||||||
<Compile Include="IPostProcessor.cs" />
|
<Compile Include="IPostProcessor.cs" />
|
||||||
@@ -93,11 +93,11 @@
|
|||||||
<Compile Include="CNC\Program.cs" />
|
<Compile Include="CNC\Program.cs" />
|
||||||
<Compile Include="ConvertProgram.cs" />
|
<Compile Include="ConvertProgram.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Quantity.cs" />
|
<Compile Include="DwgQty.cs" />
|
||||||
<Compile Include="Spacing.cs" />
|
<Compile Include="Spacing.cs" />
|
||||||
<Compile Include="Timing.cs" />
|
<Compile Include="Timing.cs" />
|
||||||
<Compile Include="TimingInfo.cs" />
|
<Compile Include="TimingInfo.cs" />
|
||||||
<Compile Include="Trigonometry.cs" />
|
<Compile Include="Math\Trigonometry.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
+12
-11
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenNest.Collections;
|
using OpenNest.Collections;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest
|
||||||
{
|
{
|
||||||
@@ -113,7 +114,7 @@ namespace OpenNest
|
|||||||
/// <param name="keepSameQuadrant"></param>
|
/// <param name="keepSameQuadrant"></param>
|
||||||
public void Rotate90(RotationType rotationDirection, bool keepSameQuadrant = true)
|
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);
|
Size = new Size(Size.Height, Size.Width);
|
||||||
|
|
||||||
@@ -217,11 +218,11 @@ namespace OpenNest
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rotate(Math.PI, centerpt);
|
Rotate(System.Math.PI, centerpt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Rotate(Math.PI);
|
Rotate(System.Math.PI);
|
||||||
Quadrant = (Quadrant + 2) % 4;
|
Quadrant = (Quadrant + 2) % 4;
|
||||||
|
|
||||||
if (Quadrant == 0)
|
if (Quadrant == 0)
|
||||||
@@ -386,23 +387,23 @@ namespace OpenNest
|
|||||||
switch (Quadrant)
|
switch (Quadrant)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
width = Math.Abs(bounds.Right) + EdgeSpacing.Right;
|
width = System.Math.Abs(bounds.Right) + EdgeSpacing.Right;
|
||||||
height = Math.Abs(bounds.Top) + EdgeSpacing.Top;
|
height = System.Math.Abs(bounds.Top) + EdgeSpacing.Top;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
width = Math.Abs(bounds.Left) + EdgeSpacing.Left;
|
width = System.Math.Abs(bounds.Left) + EdgeSpacing.Left;
|
||||||
height = Math.Abs(bounds.Top) + EdgeSpacing.Top;
|
height = System.Math.Abs(bounds.Top) + EdgeSpacing.Top;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
width = Math.Abs(bounds.Left) + EdgeSpacing.Left;
|
width = System.Math.Abs(bounds.Left) + EdgeSpacing.Left;
|
||||||
height = Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
|
height = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
width = Math.Abs(bounds.Right) + EdgeSpacing.Right;
|
width = System.Math.Abs(bounds.Right) + EdgeSpacing.Right;
|
||||||
height = Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
|
height = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace OpenNest
|
|||||||
|
|
||||||
public string ToString(int decimalPlaces)
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest
|
||||||
{
|
{
|
||||||
@@ -21,7 +22,7 @@ namespace OpenNest
|
|||||||
var vx = pt.X - X;
|
var vx = pt.X - X;
|
||||||
var vy = pt.Y - Y;
|
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)
|
public double DistanceTo(double x, double y)
|
||||||
@@ -29,7 +30,7 @@ namespace OpenNest
|
|||||||
var vx = x - X;
|
var vx = x - X;
|
||||||
var vy = y - Y;
|
var vy = y - Y;
|
||||||
|
|
||||||
return Math.Sqrt(vx * vx + vy * vy);
|
return System.Math.Sqrt(vx * vx + vy * vy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double DotProduct(Vector pt)
|
public double DotProduct(Vector pt)
|
||||||
@@ -39,7 +40,7 @@ namespace OpenNest
|
|||||||
|
|
||||||
public double Angle()
|
public double Angle()
|
||||||
{
|
{
|
||||||
return OpenNest.Angle.NormalizeRad(Math.Atan2(Y, X));
|
return OpenNest.Math.Angle.NormalizeRad(System.Math.Atan2(Y, X));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -75,7 +76,7 @@ namespace OpenNest
|
|||||||
var dot = v1.X * v2.X + v1.Y + v2.Y;
|
var dot = v1.X * v2.X + v1.Y + v2.Y;
|
||||||
var det = 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)
|
public static Vector operator +(Vector pt1, Vector pt2)
|
||||||
@@ -137,8 +138,8 @@ namespace OpenNest
|
|||||||
{
|
{
|
||||||
var v = new Vector();
|
var v = new Vector();
|
||||||
|
|
||||||
var cos = Math.Cos(angle);
|
var cos = System.Math.Cos(angle);
|
||||||
var sin = Math.Sin(angle);
|
var sin = System.Math.Sin(angle);
|
||||||
|
|
||||||
v.X = X * cos - Y * sin;
|
v.X = X * cos - Y * sin;
|
||||||
v.Y = X * sin + Y * cos;
|
v.Y = X * sin + Y * cos;
|
||||||
@@ -151,8 +152,8 @@ namespace OpenNest
|
|||||||
var v = new Vector();
|
var v = new Vector();
|
||||||
var pt = this - origin;
|
var pt = this - origin;
|
||||||
|
|
||||||
var cos = Math.Cos(angle);
|
var cos = System.Math.Cos(angle);
|
||||||
var sin = Math.Sin(angle);
|
var sin = System.Math.Sin(angle);
|
||||||
|
|
||||||
v.X = pt.X * cos - pt.Y * sin + origin.X;
|
v.X = pt.X * cos - pt.Y * sin + origin.X;
|
||||||
v.Y = pt.X * sin + pt.Y * cos + origin.Y;
|
v.Y = pt.X * sin + pt.Y * cos + origin.Y;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest
|
||||||
{
|
{
|
||||||
@@ -18,18 +19,18 @@ namespace OpenNest
|
|||||||
}
|
}
|
||||||
|
|
||||||
count1 = 0;
|
count1 = 0;
|
||||||
count2 = (int)Math.Floor(overallLength / length2);
|
count2 = (int)System.Math.Floor(overallLength / length2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length2 > overallLength)
|
if (length2 > overallLength)
|
||||||
{
|
{
|
||||||
count1 = (int)Math.Floor(overallLength / length1);
|
count1 = (int)System.Math.Floor(overallLength / length1);
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxCountLength1 = (int)Math.Floor(overallLength / length1);
|
var maxCountLength1 = (int)System.Math.Floor(overallLength / length1);
|
||||||
|
|
||||||
count1 = maxCountLength1;
|
count1 = maxCountLength1;
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
@@ -45,7 +46,7 @@ namespace OpenNest
|
|||||||
|
|
||||||
if (remnant1 >= length2)
|
if (remnant1 >= length2)
|
||||||
{
|
{
|
||||||
var countLength2 = (int)Math.Floor(remnant1 / length2);
|
var countLength2 = (int)System.Math.Floor(remnant1 / length2);
|
||||||
var remnant2 = remnant1 - length2 * countLength2;
|
var remnant2 = remnant1 - length2 * countLength2;
|
||||||
|
|
||||||
if (!(remnant2 < remnant))
|
if (!(remnant2 < remnant))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.CirclePacking
|
namespace OpenNest.CirclePacking
|
||||||
{
|
{
|
||||||
@@ -15,7 +16,7 @@ namespace OpenNest.CirclePacking
|
|||||||
Bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
|
Bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
|
||||||
Bin.Top - item.BoundingBox.Top + 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 diameter = item.Diameter;
|
||||||
var remaining = Bin.Height - diameter * rows;
|
var remaining = Bin.Height - diameter * rows;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.CirclePacking
|
namespace OpenNest.CirclePacking
|
||||||
{
|
{
|
||||||
@@ -33,7 +34,7 @@ namespace OpenNest.CirclePacking
|
|||||||
bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
|
bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
|
||||||
bin.Top - item.BoundingBox.Top + 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)
|
if (count == 0)
|
||||||
return bin;
|
return bin;
|
||||||
@@ -69,7 +70,7 @@ namespace OpenNest.CirclePacking
|
|||||||
Bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
|
Bin.Right - item.BoundingBox.Right + Tolerance.Epsilon,
|
||||||
Bin.Top - item.BoundingBox.Top + 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)
|
if (count == 0)
|
||||||
return bin;
|
return bin;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using OpenNest.Math;
|
||||||
using OpenNest.RectanglePacking;
|
using OpenNest.RectanglePacking;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest
|
||||||
@@ -143,7 +144,7 @@ namespace OpenNest
|
|||||||
var item = items[i];
|
var item = items[i];
|
||||||
var binItem = ConvertToRectangleItem(item, 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
|
int qty = item.Quantity < maxQty
|
||||||
? item.Quantity
|
? item.Quantity
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.RectanglePacking
|
namespace OpenNest.RectanglePacking
|
||||||
{
|
{
|
||||||
@@ -45,8 +46,8 @@ namespace OpenNest.RectanglePacking
|
|||||||
if (!BestCombination.FindFrom2(item.Width, item.Height, bin.Width, out normalColumns, out rotateColumns))
|
if (!BestCombination.FindFrom2(item.Width, item.Height, bin.Width, out normalColumns, out rotateColumns))
|
||||||
return bin;
|
return bin;
|
||||||
|
|
||||||
var normalRows = (int)Math.Floor((bin.Height + Tolerance.Epsilon) / item.Height);
|
var normalRows = (int)System.Math.Floor((bin.Height + Tolerance.Epsilon) / item.Height);
|
||||||
var rotateRows = (int)Math.Floor((bin.Height + Tolerance.Epsilon) / item.Width);
|
var rotateRows = (int)System.Math.Floor((bin.Height + Tolerance.Epsilon) / item.Width);
|
||||||
|
|
||||||
item.Location = bin.Location;
|
item.Location = bin.Location;
|
||||||
|
|
||||||
@@ -70,8 +71,8 @@ namespace OpenNest.RectanglePacking
|
|||||||
if (!BestCombination.FindFrom2(item.Height, item.Width, Bin.Height, out normalRows, out rotateRows))
|
if (!BestCombination.FindFrom2(item.Height, item.Width, Bin.Height, out normalRows, out rotateRows))
|
||||||
return bin;
|
return bin;
|
||||||
|
|
||||||
var normalColumns = (int)Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
|
var normalColumns = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
|
||||||
var rotateColumns = (int)Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Height);
|
var rotateColumns = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Height);
|
||||||
|
|
||||||
item.Location = bin.Location;
|
item.Location = bin.Location;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.RectanglePacking
|
namespace OpenNest.RectanglePacking
|
||||||
{
|
{
|
||||||
@@ -13,8 +14,8 @@ namespace OpenNest.RectanglePacking
|
|||||||
|
|
||||||
public override void Fill(Item item)
|
public override void Fill(Item item)
|
||||||
{
|
{
|
||||||
var ycount = (int)Math.Floor((Bin.Height + Tolerance.Epsilon) / item.Height);
|
var ycount = (int)System.Math.Floor((Bin.Height + Tolerance.Epsilon) / item.Height);
|
||||||
var xcount = (int)Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
|
var xcount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
|
||||||
var count = ycount * xcount;
|
var count = ycount * xcount;
|
||||||
|
|
||||||
for (int i = 0; i < xcount; i++)
|
for (int i = 0; i < xcount; i++)
|
||||||
@@ -35,8 +36,8 @@ namespace OpenNest.RectanglePacking
|
|||||||
|
|
||||||
public override void Fill(Item item, int maxCount)
|
public override void Fill(Item item, int maxCount)
|
||||||
{
|
{
|
||||||
var ycount = (int)Math.Floor((Bin.Height + Tolerance.Epsilon) / item.Height);
|
var ycount = (int)System.Math.Floor((Bin.Height + Tolerance.Epsilon) / item.Height);
|
||||||
var xcount = (int)Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
|
var xcount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width);
|
||||||
var count = ycount * xcount;
|
var count = ycount * xcount;
|
||||||
|
|
||||||
if (count <= maxCount)
|
if (count <= maxCount)
|
||||||
@@ -50,13 +51,13 @@ namespace OpenNest.RectanglePacking
|
|||||||
|
|
||||||
if (NestDirection == NestDirection.Vertical)
|
if (NestDirection == NestDirection.Vertical)
|
||||||
{
|
{
|
||||||
columns = (int)Math.Ceiling((double)maxCount / ycount);
|
columns = (int)System.Math.Ceiling((double)maxCount / ycount);
|
||||||
rows = (int)Math.Ceiling((double)maxCount / columns);
|
rows = (int)System.Math.Ceiling((double)maxCount / columns);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rows = (int)Math.Ceiling((double)maxCount / xcount);
|
rows = (int)System.Math.Ceiling((double)maxCount / xcount);
|
||||||
columns = (int)Math.Ceiling((double)maxCount / rows);
|
columns = (int)System.Math.Ceiling((double)maxCount / rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.Width > item.Height)
|
if (item.Width > item.Height)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.RectanglePacking
|
namespace OpenNest.RectanglePacking
|
||||||
{
|
{
|
||||||
internal class FillSameRotation : FillEngine
|
internal class FillSameRotation : FillEngine
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.RectanglePacking
|
namespace OpenNest.RectanglePacking
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.RectanglePacking
|
namespace OpenNest.RectanglePacking
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace OpenNest.Controls
|
|||||||
var bounds = dwg.Program.BoundingBox();
|
var bounds = dwg.Program.BoundingBox();
|
||||||
var text1 = string.Format("{0} of {1} nested", dwg.Quantity.Nested, dwg.Quantity.Required);
|
var text1 = string.Format("{0} of {1} nested", dwg.Quantity.Nested, dwg.Quantity.Required);
|
||||||
var text2 = bounds.Size.ToString(4);
|
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;
|
pt.Y += 22;
|
||||||
e.Graphics.DrawString(text1, Font, Brushes.Gray, pt);
|
e.Graphics.DrawString(text1, Font, Brushes.Gray, pt);
|
||||||
@@ -100,7 +100,7 @@ namespace OpenNest.Controls
|
|||||||
var x = pt2.X - pt1.X;
|
var x = pt2.X - pt1.X;
|
||||||
var y = pt2.Y - pt1.Y;
|
var y = pt2.Y - pt1.Y;
|
||||||
|
|
||||||
return Math.Sqrt(x * x + y * y);
|
return System.Math.Sqrt(x * x + y * y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Drawing;
|
|||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.Controls
|
namespace OpenNest.Controls
|
||||||
{
|
{
|
||||||
@@ -59,12 +60,12 @@ namespace OpenNest.Controls
|
|||||||
{
|
{
|
||||||
base.OnMouseWheel(e);
|
base.OnMouseWheel(e);
|
||||||
|
|
||||||
float multiplier = Math.Abs(e.Delta / 120.0f);
|
float multiplier = System.Math.Abs(e.Delta / 120.0f);
|
||||||
|
|
||||||
if (e.Delta > 0)
|
if (e.Delta > 0)
|
||||||
ZoomToControlPoint(e.Location, (float)Math.Pow(ZoomInFactor, multiplier));
|
ZoomToControlPoint(e.Location, (float)System.Math.Pow(ZoomInFactor, multiplier));
|
||||||
else
|
else
|
||||||
ZoomToControlPoint(e.Location, (float)Math.Pow(ZoomOutFactor, multiplier));
|
ZoomToControlPoint(e.Location, (float)System.Math.Pow(ZoomOutFactor, multiplier));
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using OpenTK.Graphics.OpenGL;
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.Controls
|
namespace OpenNest.Controls
|
||||||
{
|
{
|
||||||
@@ -13,7 +14,7 @@ namespace OpenNest.Controls
|
|||||||
private float scale;
|
private float scale;
|
||||||
private bool loaded = false;
|
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 Resolution = 100;
|
||||||
private const int BorderWidth = 50;
|
private const int BorderWidth = 50;
|
||||||
private const float ZoomInFactor = 1.1f;
|
private const float ZoomInFactor = 1.1f;
|
||||||
@@ -117,12 +118,12 @@ namespace OpenNest.Controls
|
|||||||
{
|
{
|
||||||
base.OnMouseWheel(e);
|
base.OnMouseWheel(e);
|
||||||
|
|
||||||
float multiplier = Math.Abs(e.Delta / 120.0f);
|
float multiplier = System.Math.Abs(e.Delta / 120.0f);
|
||||||
|
|
||||||
if (e.Delta > 0)
|
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
|
else
|
||||||
ZoomToPoint(e.X, e.Y, (float)Math.Pow(ZoomOutFactor, multiplier));
|
ZoomToPoint(e.X, e.Y, (float)System.Math.Pow(ZoomOutFactor, multiplier));
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
@@ -292,12 +293,12 @@ namespace OpenNest.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start angle in radians
|
// start angle in radians
|
||||||
var startAngle = Math.Atan2(
|
var startAngle = System.Math.Atan2(
|
||||||
curpos.Y - center.Y,
|
curpos.Y - center.Y,
|
||||||
curpos.X - center.X);
|
curpos.X - center.X);
|
||||||
|
|
||||||
// end angle in radians
|
// end angle in radians
|
||||||
var endAngle = Math.Atan2(
|
var endAngle = System.Math.Atan2(
|
||||||
endpt.Y - center.Y,
|
endpt.Y - center.Y,
|
||||||
endpt.X - center.X);
|
endpt.X - center.X);
|
||||||
|
|
||||||
@@ -312,7 +313,7 @@ namespace OpenNest.Controls
|
|||||||
var dx = endpt.X - center.X;
|
var dx = endpt.X - center.X;
|
||||||
var dy = endpt.Y - center.Y;
|
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))
|
if (startAngle.IsEqualTo(endAngle))
|
||||||
{
|
{
|
||||||
@@ -337,8 +338,8 @@ namespace OpenNest.Controls
|
|||||||
for (int i = 0; i <= Resolution; i++)
|
for (int i = 0; i <= Resolution; i++)
|
||||||
{
|
{
|
||||||
GL.Vertex2(
|
GL.Vertex2(
|
||||||
Math.Cos(startAngle + angle * i) * radius + center.X,
|
System.Math.Cos(startAngle + angle * i) * radius + center.X,
|
||||||
Math.Sin(startAngle + angle * i) * radius + center.Y);
|
System.Math.Sin(startAngle + angle * i) * radius + center.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
GL.End();
|
GL.End();
|
||||||
@@ -346,14 +347,14 @@ namespace OpenNest.Controls
|
|||||||
|
|
||||||
private void DrawCircle(Vector center, double radius)
|
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;
|
const float increment = angle / Resolution;
|
||||||
|
|
||||||
for (float i = 0; i <= angle; i += increment)
|
for (float i = 0; i <= angle; i += increment)
|
||||||
{
|
{
|
||||||
GL.Vertex2(
|
GL.Vertex2(
|
||||||
Math.Cos(i) * radius + center.X,
|
System.Math.Cos(i) * radius + center.X,
|
||||||
Math.Sin(i) * radius + center.Y);
|
System.Math.Sin(i) * radius + center.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System.Windows.Forms;
|
|||||||
using OpenNest.Actions;
|
using OpenNest.Actions;
|
||||||
using OpenNest.CNC;
|
using OpenNest.CNC;
|
||||||
using OpenNest.Collections;
|
using OpenNest.Collections;
|
||||||
|
using OpenNest.Math;
|
||||||
using Action = OpenNest.Actions.Action;
|
using Action = OpenNest.Actions.Action;
|
||||||
using Timer = System.Timers.Timer;
|
using Timer = System.Timers.Timer;
|
||||||
|
|
||||||
@@ -164,7 +165,7 @@ namespace OpenNest.Controls
|
|||||||
{
|
{
|
||||||
base.OnMouseWheel(e);
|
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))
|
if (SelectedParts.Count > 0 && ((ModifierKeys & Keys.Shift) == Keys.Shift))
|
||||||
{
|
{
|
||||||
@@ -181,9 +182,9 @@ namespace OpenNest.Controls
|
|||||||
if (AllowZoom)
|
if (AllowZoom)
|
||||||
{
|
{
|
||||||
if (e.Delta > 0)
|
if (e.Delta > 0)
|
||||||
ZoomToControlPoint(e.Location, (float)Math.Pow(ZoomInFactor, multiplier));
|
ZoomToControlPoint(e.Location, (float)System.Math.Pow(ZoomInFactor, multiplier));
|
||||||
else
|
else
|
||||||
ZoomToControlPoint(e.Location, (float)Math.Pow(ZoomOutFactor, multiplier));
|
ZoomToControlPoint(e.Location, (float)System.Math.Pow(ZoomOutFactor, multiplier));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using OpenNest.Actions;
|
|||||||
using OpenNest.Collections;
|
using OpenNest.Collections;
|
||||||
using OpenNest.Controls;
|
using OpenNest.Controls;
|
||||||
using OpenNest.IO;
|
using OpenNest.IO;
|
||||||
|
using OpenNest.Math;
|
||||||
using OpenNest.Properties;
|
using OpenNest.Properties;
|
||||||
using Timer = System.Timers.Timer;
|
using Timer = System.Timers.Timer;
|
||||||
|
|
||||||
@@ -292,8 +293,8 @@ namespace OpenNest.Forms
|
|||||||
|
|
||||||
writer.WriteLine("{0}|{1},{2}|{3}",
|
writer.WriteLine("{0}|{1},{2}|{3}",
|
||||||
part.BaseDrawing.Source.Path,
|
part.BaseDrawing.Source.Path,
|
||||||
Math.Round(part.Location.X - pt.X, 8),
|
System.Math.Round(part.Location.X - pt.X, 8),
|
||||||
Math.Round(part.Location.Y - pt.Y, 8),
|
System.Math.Round(part.Location.Y - pt.Y, 8),
|
||||||
Angle.ToDegrees(part.Rotation));
|
Angle.ToDegrees(part.Rotation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ namespace OpenNest.Forms
|
|||||||
|
|
||||||
public void SetCutDistance(double dist)
|
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)
|
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)
|
public void SetIntersectionCount(int count)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Drawing;
|
|||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using OpenNest.CNC;
|
using OpenNest.CNC;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest
|
namespace OpenNest
|
||||||
{
|
{
|
||||||
@@ -97,12 +98,12 @@ namespace OpenNest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start angle in degrees
|
// start angle in degrees
|
||||||
var startAngle = Angle.ToDegrees(Math.Atan2(
|
var startAngle = Angle.ToDegrees(System.Math.Atan2(
|
||||||
curpos.Y - center.Y,
|
curpos.Y - center.Y,
|
||||||
curpos.X - center.X));
|
curpos.X - center.X));
|
||||||
|
|
||||||
// end angle in degrees
|
// end angle in degrees
|
||||||
var endAngle = Angle.ToDegrees(Math.Atan2(
|
var endAngle = Angle.ToDegrees(System.Math.Atan2(
|
||||||
endpt.Y - center.Y,
|
endpt.Y - center.Y,
|
||||||
endpt.X - center.X));
|
endpt.X - center.X));
|
||||||
|
|
||||||
@@ -117,7 +118,7 @@ namespace OpenNest
|
|||||||
var dx = endpt.X - center.X;
|
var dx = endpt.X - center.X;
|
||||||
var dy = endpt.Y - center.Y;
|
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 pt = new PointF((float)(center.X - radius), (float)(center.Y - radius));
|
||||||
var size = (float)(radius * 2.0);
|
var size = (float)(radius * 2.0);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using netDxf;
|
|||||||
using netDxf.Entities;
|
using netDxf.Entities;
|
||||||
using netDxf.Tables;
|
using netDxf.Tables;
|
||||||
using OpenNest.CNC;
|
using OpenNest.CNC;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.IO
|
namespace OpenNest.IO
|
||||||
{
|
{
|
||||||
@@ -13,7 +14,7 @@ namespace OpenNest.IO
|
|||||||
|
|
||||||
public class DxfExporter
|
public class DxfExporter
|
||||||
{
|
{
|
||||||
private const double RadToDeg = 180.0 / Math.PI;
|
private const double RadToDeg = 180.0 / System.Math.PI;
|
||||||
|
|
||||||
private DxfDocument doc;
|
private DxfDocument doc;
|
||||||
private Vector2 curpos;
|
private Vector2 curpos;
|
||||||
@@ -247,12 +248,12 @@ namespace OpenNest.IO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start angle in radians
|
// start angle in radians
|
||||||
var startAngle = Math.Atan2(
|
var startAngle = System.Math.Atan2(
|
||||||
curpos.Y - center.Y,
|
curpos.Y - center.Y,
|
||||||
curpos.X - center.X);
|
curpos.X - center.X);
|
||||||
|
|
||||||
// end angle in radians
|
// end angle in radians
|
||||||
var endAngle = Math.Atan2(
|
var endAngle = System.Math.Atan2(
|
||||||
endpt.Y - center.Y,
|
endpt.Y - center.Y,
|
||||||
endpt.X - center.X);
|
endpt.X - center.X);
|
||||||
|
|
||||||
@@ -266,7 +267,7 @@ namespace OpenNest.IO
|
|||||||
var dx = endpt.X - center.X;
|
var dx = endpt.X - center.X;
|
||||||
var dy = endpt.Y - center.Y;
|
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))
|
if (startAngle.IsEqualTo(endAngle))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.IO
|
namespace OpenNest.IO
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using OpenNest.CNC;
|
using OpenNest.CNC;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.IO
|
namespace OpenNest.IO
|
||||||
{
|
{
|
||||||
|
|||||||
+13
-12
@@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using OpenNest.CNC;
|
using OpenNest.CNC;
|
||||||
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.IO
|
namespace OpenNest.IO
|
||||||
{
|
{
|
||||||
@@ -319,18 +320,18 @@ namespace OpenNest.IO
|
|||||||
if (arcMove.Rotation == RotationType.CW)
|
if (arcMove.Rotation == RotationType.CW)
|
||||||
{
|
{
|
||||||
sb.Append(string.Format("G02X{0}Y{1}I{2}J{3}",
|
sb.Append(string.Format("G02X{0}Y{1}I{2}J{3}",
|
||||||
Math.Round(arcMove.EndPoint.X, OutputPrecision),
|
System.Math.Round(arcMove.EndPoint.X, OutputPrecision),
|
||||||
Math.Round(arcMove.EndPoint.Y, OutputPrecision),
|
System.Math.Round(arcMove.EndPoint.Y, OutputPrecision),
|
||||||
Math.Round(arcMove.CenterPoint.X, OutputPrecision),
|
System.Math.Round(arcMove.CenterPoint.X, OutputPrecision),
|
||||||
Math.Round(arcMove.CenterPoint.Y, OutputPrecision)));
|
System.Math.Round(arcMove.CenterPoint.Y, OutputPrecision)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb.Append(string.Format("G03X{0}Y{1}I{2}J{3}",
|
sb.Append(string.Format("G03X{0}Y{1}I{2}J{3}",
|
||||||
Math.Round(arcMove.EndPoint.X, OutputPrecision),
|
System.Math.Round(arcMove.EndPoint.X, OutputPrecision),
|
||||||
Math.Round(arcMove.EndPoint.Y, OutputPrecision),
|
System.Math.Round(arcMove.EndPoint.Y, OutputPrecision),
|
||||||
Math.Round(arcMove.CenterPoint.X, OutputPrecision),
|
System.Math.Round(arcMove.CenterPoint.X, OutputPrecision),
|
||||||
Math.Round(arcMove.CenterPoint.Y, OutputPrecision)));
|
System.Math.Round(arcMove.CenterPoint.Y, OutputPrecision)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arcMove.Layer != LayerType.Cut)
|
if (arcMove.Layer != LayerType.Cut)
|
||||||
@@ -351,8 +352,8 @@ namespace OpenNest.IO
|
|||||||
var linearMove = (LinearMove)code;
|
var linearMove = (LinearMove)code;
|
||||||
|
|
||||||
sb.Append(string.Format("G01X{0}Y{1}",
|
sb.Append(string.Format("G01X{0}Y{1}",
|
||||||
Math.Round(linearMove.EndPoint.X, OutputPrecision),
|
System.Math.Round(linearMove.EndPoint.X, OutputPrecision),
|
||||||
Math.Round(linearMove.EndPoint.Y, OutputPrecision)));
|
System.Math.Round(linearMove.EndPoint.Y, OutputPrecision)));
|
||||||
|
|
||||||
if (linearMove.Layer != LayerType.Cut)
|
if (linearMove.Layer != LayerType.Cut)
|
||||||
sb.Append(GetLayerString(linearMove.Layer));
|
sb.Append(GetLayerString(linearMove.Layer));
|
||||||
@@ -365,8 +366,8 @@ namespace OpenNest.IO
|
|||||||
var rapidMove = (RapidMove)code;
|
var rapidMove = (RapidMove)code;
|
||||||
|
|
||||||
return string.Format("G00X{0}Y{1}",
|
return string.Format("G00X{0}Y{1}",
|
||||||
Math.Round(rapidMove.EndPoint.X, OutputPrecision),
|
System.Math.Round(rapidMove.EndPoint.X, OutputPrecision),
|
||||||
Math.Round(rapidMove.EndPoint.Y, OutputPrecision));
|
System.Math.Round(rapidMove.EndPoint.Y, OutputPrecision));
|
||||||
}
|
}
|
||||||
|
|
||||||
case CodeType.SetFeedrate:
|
case CodeType.SetFeedrate:
|
||||||
|
|||||||
Reference in New Issue
Block a user