refactor(PepLib.Core): reorganize files into logical folder structure

Move 38 files from root directory into organized subfolders:
- Enums/ (7 files): StatusType, ApplicationType, DrawingType, etc.
- Geometry/ (5 files): Vector, Box, Size, Spacing, Node
- Models/ (15 files): Nest, Plate, Part, Program, Report, etc.
- Utilities/ (7 files): MathHelper, Tolerance, ZipHelper, etc.
- Extensions/ (2 files): PartListExtensions, PlateListExtensions
- Interfaces/ (1 file): IMovable

Update namespaces to follow folder hierarchy (e.g., PepLib.Models).
Add GlobalUsings.cs for internal backward compatibility.
Update Codes/ and IO/ files with new using statements.
Update PepApi.Core consumers to reference new namespaces.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-23 09:29:13 -05:00
parent c5be48a807
commit 9088af52de
55 changed files with 137 additions and 76 deletions

149
PepLib.Core/Geometry/Box.cs Normal file
View File

@@ -0,0 +1,149 @@
namespace PepLib.Geometry
{
public class Box
{
public Box()
: this(0, 0, 0, 0)
{
}
public Box(double x, double y, double w, double h)
{
Location = new Vector(x, y);
Size = new Size(0, 0);
Width = w;
Height = h;
}
public Vector Location;
public Vector Center
{
get { return new Vector(X + Width * 0.5, Y + Height * 0.5); }
}
public Size Size;
public double X
{
get { return Location.X; }
set { Location.X = value; }
}
public double Y
{
get { return Location.Y; }
set { Location.Y = value; }
}
public double Width
{
get { return Size.Width; }
set { Size.Width = value; }
}
public double Height
{
get { return Size.Height; }
set { Size.Height = value; }
}
public void MoveTo(double x, double y)
{
X = x;
Y = y;
}
public void MoveTo(Vector pt)
{
X = pt.X;
Y = pt.Y;
}
public void Offset(double x, double y)
{
X += x;
Y += y;
}
public void Offset(Vector voffset)
{
Location += voffset;
}
public double Left
{
get { return X; }
}
public double Right
{
get { return X + Width; }
}
public double Top
{
get { return Y + Height; }
}
public double Bottom
{
get { return Y; }
}
public double Area()
{
return Width * Height;
}
public double Perimeter()
{
return Width * 2 + Height * 2;
}
public bool IsIntersecting(Box box)
{
if (Left >= box.Right)
return false;
if (Right >= box.Left)
return false;
if (Top <= box.Bottom)
return false;
if (Bottom <= box.Top)
return false;
return true;
}
public bool Contains(Box box)
{
if (box.Left < Left)
return false;
if (box.Right > Right)
return false;
if (box.Bottom < Bottom)
return false;
if (box.Top > Top)
return false;
return true;
}
public bool Contains(Vector pt)
{
return pt.X >= Left && pt.X <= Right
&& pt.Y >= Bottom && pt.Y <= Top;
}
public override string ToString()
{
return string.Format("[Box: X={0}, Y={1}, Width={2}, Height={3}]", X, Y, Width, Height);
}
}
}

View File

@@ -0,0 +1,82 @@
namespace PepLib.Geometry
{
public class Node
{
private Node parent;
public List<Node> Children;
public Node()
{
Children = new List<Node>();
}
public Node Parent
{
get { return parent; }
set
{
parent = value;
UpdateDepth();
}
}
public string Value { get; set; }
private void UpdateDepth()
{
if (Parent != null)
Level = Parent.Level + 1;
else
Level = 0;
foreach (var node in Children)
node.Parent = this;
}
public int Level { get; protected set; }
public void AddChild(Node node)
{
node.Parent = this;
Children.Add(node);
}
public void Write(TextWriter writer)
{
writer.WriteLine("".PadLeft(Level * 2) + this.ToString());
foreach (var node in Children)
node.Write(writer);
}
public override string ToString()
{
return Value;
}
}
public class KeyNode : Node
{
public string Name;
public static KeyNode Parse(Node node)
{
var index = node.Value.IndexOf('=');
if (index == -1)
return null;
return new KeyNode()
{
Name = node.Value.Remove(index),
Value = node.Value.Remove(0, index + 1).Trim()
};
}
public override string ToString()
{
return string.Format("{0}={1}", Name, Value);
}
}
}

View File

@@ -0,0 +1,45 @@
namespace PepLib.Geometry
{
public class Size
{
public Size(double height, double width)
{
Height = height;
Width = width;
}
public double Height { get; set; }
public double Width { get; set; }
public static Size Parse(string size)
{
var a = size.ToUpper().Split('X');
var height = double.Parse(a[0]);
var width = double.Parse(a[1]);
return new Size(height, width);
}
public static bool TryParse(string s, out Size size)
{
try
{
size = Parse(s);
}
catch
{
size = new Size(0, 0);
return false;
}
return true;
}
public override string ToString()
{
return string.Format("{0} x {1}", Height, Width);
}
}
}

View File

@@ -0,0 +1,27 @@
namespace PepLib.Geometry
{
public class Spacing
{
public Spacing()
: this(0, 0, 0, 0)
{
}
public Spacing(double l, double b, double r, double t)
{
Left = l;
Bottom = b;
Right = r;
Top = t;
}
public double Left { get; set; }
public double Bottom { get; set; }
public double Right { get; set; }
public double Top { get; set; }
}
}

View File

@@ -0,0 +1,124 @@
using PepLib.Utilities;
namespace PepLib.Geometry
{
public struct Vector
{
public double X;
public double Y;
public Vector(double x, double y)
{
X = x;
Y = y;
}
public double DistanceTo(Vector pt)
{
double vx = pt.X - this.X;
double vy = pt.Y - this.Y;
return Math.Sqrt(vx * vx + vy * vy);
}
public double DistanceTo(double x, double y)
{
double vx = x - this.X;
double vy = y - this.Y;
return Math.Sqrt(vx * vx + vy * vy);
}
public double Angle()
{
return MathHelper.NormalizeAngleRad(Math.Atan2(Y, X));
}
public double AngleTo(Vector pt)
{
return (pt - this).Angle();
}
public double AngleFrom(Vector pt)
{
return (this - pt).Angle();
}
public static Vector operator +(Vector pt1, Vector pt2)
{
return new Vector(pt1.X + pt2.X, pt1.Y + pt2.Y);
}
public static Vector operator -(Vector pt1, Vector pt2)
{
return new Vector(pt1.X - pt2.X, pt1.Y - pt2.Y);
}
public static Vector operator -(Vector pt)
{
return new Vector(-pt.X, -pt.Y);
}
public static bool operator ==(Vector pt1, Vector pt2)
{
return pt1.DistanceTo(pt2) <= Tolerance.Epsilon;
}
public static bool operator !=(Vector pt1, Vector pt2)
{
return !(pt1 == pt2);
}
public Vector Rotate(double angle)
{
var v = new Vector();
double cos = Math.Cos(angle);
double sin = Math.Sin(angle);
v.X = X * cos - Y * sin;
v.Y = X * sin + Y * cos;
return v;
}
public Vector Rotate(double angle, Vector origin)
{
var v = new Vector();
var pt = this - origin;
double cos = Math.Cos(angle);
double sin = Math.Sin(angle);
v.X = pt.X * cos - pt.Y * sin + origin.X;
v.Y = pt.X * sin + pt.Y * cos + origin.Y;
return v;
}
public Vector Clone()
{
return new Vector(X, Y);
}
public override bool Equals(object obj)
{
if (!(obj is Vector))
return false;
var pt = (Vector)obj;
return (X.IsEqualTo(pt.X)) && (Y.IsEqualTo(pt.Y));
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override string ToString()
{
return string.Format("[Vector: X:{0}, Y:{1}]", X, Y);
}
}
}