123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- /**
- *
- * @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;
- }
- }
- }
|