/** * * @author seagle * @date 2024-7-22 * @Description 管路图元件对象封装 */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.UI.Core.DxfScript { public class GasLine : GasBaseShape { public double X1 { get; set; } public double Y1 { get; set; } public double X2 { get; set; } public double Y2 { get; set; } public bool IsHorizental { get; set; } = false; public bool IsVertical { get; set; } = false; public string Tag { get; set; } public GasLine(double x1,double y1,double x2,double y2) { X1 = x1; X2 = x2; Y1 = y1; Y2 = y2; double x_space = (x1 >= x2) ? x1 - x2 : x2 - x1; double y_space = (y1 >= y2) ? y1 - y2 : y2 - y1; if (y_space <= GasBaseShape.E) { IsHorizental = true; Id = CreateId(ShapeType.HLINE, Math.Min(x1,x2), Math.Max(y1,y2)); } else if (x_space <= GasBaseShape.E) { IsVertical = true; Id = CreateId(ShapeType.VLINE, Math.Min(x1, x2), Math.Max(y1, y2)); } else { double k = (y1 - y2) / (x1 - x2); if (k > E) { //锐角 Id = CreateId(ShapeType.ACUTE, Math.Min(x1, x2), Math.Max(y1, y2)); } else { //钝角 Id = CreateId(ShapeType.OBTUSE, Math.Min(x1, x2), Math.Max(y1, y2)); } } } public override bool Contains(double x,double y) { double e = GasBaseShape.E; if(IsVertical ) { //竖线 double y1, y2; if((Y1-Y2) > 0) { y1 = Y2; ; y2 = Y1; } else { y1 = Y1; y2 = Y2; } if (y < y1-e || y > y2+e) { return false; } if(x-X1<=e && x - X1 >= -e) { return true; } else { return false; } } else if(IsHorizental) { //横线 double x1, x2; if ((X1 - X2) > 0) { x1 = X2; x2 = X1; } else { x1 = X1; x2 = X2; } if (x < x1 - e || x > x2 + e) { return false; } if (y - Y1 <= e && y - Y1 >= -e) { return true; } else { return false; } } return false; } public bool CornerAt(GasLine otherLine) { //是否两条线段直角拐角相连 if (IsHorizental) { if (!otherLine.IsVertical) { return false; } if(IsSamePoint(X1,Y1,otherLine.X1,otherLine.Y1) || IsSamePoint(X1, Y1, otherLine.X2, otherLine.Y2)|| IsSamePoint(X2, Y2, otherLine.X1, otherLine.Y1) || IsSamePoint(X2, Y2, otherLine.X2, otherLine.Y2)) { return true; } else { return false; } }else if (IsVertical) { if (!otherLine.IsHorizental) { return false; } if (IsSamePoint(X1, Y1, otherLine.X1, otherLine.Y1) || IsSamePoint(X1, Y1, otherLine.X2, otherLine.Y2) || IsSamePoint(X2, Y2, otherLine.X1, otherLine.Y1) || IsSamePoint(X2, Y2, otherLine.X2, otherLine.Y2)) { return true; } else { return false; } } return false; } public bool ParallelAt(GasLine otherLine) { if (IsHorizental) { if (!otherLine.IsHorizental) { return false; } if(Math.Abs(Y1-otherLine.Y1) <= E){ return false;//重合的不叫平行 } else { double xMinSpace = Math.Abs(Math.Min(X1, X2) - Math.Min(otherLine.X1, otherLine.X2)); double xMaxSpace= Math.Abs(Math.Max(X1, X2) - Math.Max(otherLine.X1, otherLine.X2)); if(xMinSpace<=E && xMaxSpace <= E) { return true; } else { return false; } } } else if(IsVertical) { if (!otherLine.IsVertical) { return false; } if (Math.Abs(X1 - otherLine.X1) <= E) { return false;//重合的不叫平行 } else { double yMinSpace = Math.Abs(Math.Min(Y1, Y2) - Math.Min(otherLine.Y1, otherLine.Y2)); double yMaxSpace = Math.Abs(Math.Max(Y1, Y2) - Math.Max(otherLine.Y1, otherLine.Y2)); if (yMinSpace <= E && yMaxSpace <= E) { return true; } else { return false; } } } return false; } public override void Move(double x, double y) { X1 = X1 + x; X2 = X2 + x; Y1 = Y1 + y; Y2 = Y2 + y; } } }