GasLine.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. *
  3. * @author seagle
  4. * @date 2024-7-22
  5. * @Description 管路图元件对象封装
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace MECF.Framework.UI.Core.DxfScript
  13. {
  14. public class GasLine : GasBaseShape
  15. {
  16. public double X1 { get; set; }
  17. public double Y1 { get; set; }
  18. public double X2 { get; set; }
  19. public double Y2 { get; set; }
  20. public bool IsHorizental { get; set; } = false;
  21. public bool IsVertical { get; set; } = false;
  22. public string Tag { get; set; }
  23. public GasLine(double x1,double y1,double x2,double y2)
  24. {
  25. X1 = x1;
  26. X2 = x2;
  27. Y1 = y1;
  28. Y2 = y2;
  29. double x_space = (x1 >= x2) ? x1 - x2 : x2 - x1;
  30. double y_space = (y1 >= y2) ? y1 - y2 : y2 - y1;
  31. if (y_space <= GasBaseShape.E)
  32. {
  33. IsHorizental = true;
  34. Id = CreateId(ShapeType.HLINE, Math.Min(x1,x2), Math.Max(y1,y2));
  35. }
  36. else if (x_space <= GasBaseShape.E)
  37. {
  38. IsVertical = true;
  39. Id = CreateId(ShapeType.VLINE, Math.Min(x1, x2), Math.Max(y1, y2));
  40. }
  41. else
  42. {
  43. double k = (y1 - y2) / (x1 - x2);
  44. if (k > E)
  45. {
  46. //锐角
  47. Id = CreateId(ShapeType.ACUTE, Math.Min(x1, x2), Math.Max(y1, y2));
  48. }
  49. else
  50. {
  51. //钝角
  52. Id = CreateId(ShapeType.OBTUSE, Math.Min(x1, x2), Math.Max(y1, y2));
  53. }
  54. }
  55. }
  56. public override bool Contains(double x,double y)
  57. {
  58. double e = GasBaseShape.E;
  59. if(IsVertical )
  60. {
  61. //竖线
  62. double y1, y2;
  63. if((Y1-Y2) > 0)
  64. {
  65. y1 = Y2; ;
  66. y2 = Y1;
  67. }
  68. else
  69. {
  70. y1 = Y1;
  71. y2 = Y2;
  72. }
  73. if (y < y1-e || y > y2+e)
  74. {
  75. return false;
  76. }
  77. if(x-X1<=e && x - X1 >= -e)
  78. {
  79. return true;
  80. }
  81. else
  82. {
  83. return false;
  84. }
  85. }
  86. else if(IsHorizental)
  87. {
  88. //横线
  89. double x1, x2;
  90. if ((X1 - X2) > 0)
  91. {
  92. x1 = X2;
  93. x2 = X1;
  94. }
  95. else
  96. {
  97. x1 = X1;
  98. x2 = X2;
  99. }
  100. if (x < x1 - e || x > x2 + e)
  101. {
  102. return false;
  103. }
  104. if (y - Y1 <= e && y - Y1 >= -e)
  105. {
  106. return true;
  107. }
  108. else
  109. {
  110. return false;
  111. }
  112. }
  113. return false;
  114. }
  115. public bool CornerAt(GasLine otherLine)
  116. {
  117. //是否两条线段直角拐角相连
  118. if (IsHorizental)
  119. {
  120. if (!otherLine.IsVertical)
  121. {
  122. return false;
  123. }
  124. if(IsSamePoint(X1,Y1,otherLine.X1,otherLine.Y1) || IsSamePoint(X1, Y1, otherLine.X2, otherLine.Y2)||
  125. IsSamePoint(X2, Y2, otherLine.X1, otherLine.Y1) || IsSamePoint(X2, Y2, otherLine.X2, otherLine.Y2))
  126. {
  127. return true;
  128. }
  129. else
  130. {
  131. return false;
  132. }
  133. }else if (IsVertical)
  134. {
  135. if (!otherLine.IsHorizental)
  136. {
  137. return false;
  138. }
  139. if (IsSamePoint(X1, Y1, otherLine.X1, otherLine.Y1) || IsSamePoint(X1, Y1, otherLine.X2, otherLine.Y2) ||
  140. IsSamePoint(X2, Y2, otherLine.X1, otherLine.Y1) || IsSamePoint(X2, Y2, otherLine.X2, otherLine.Y2))
  141. {
  142. return true;
  143. }
  144. else
  145. {
  146. return false;
  147. }
  148. }
  149. return false;
  150. }
  151. public bool ParallelAt(GasLine otherLine)
  152. {
  153. if (IsHorizental)
  154. {
  155. if (!otherLine.IsHorizental)
  156. {
  157. return false;
  158. }
  159. if(Math.Abs(Y1-otherLine.Y1) <= E){
  160. return false;//重合的不叫平行
  161. }
  162. else
  163. {
  164. double xMinSpace = Math.Abs(Math.Min(X1, X2) - Math.Min(otherLine.X1, otherLine.X2));
  165. double xMaxSpace= Math.Abs(Math.Max(X1, X2) - Math.Max(otherLine.X1, otherLine.X2));
  166. if(xMinSpace<=E && xMaxSpace <= E)
  167. {
  168. return true;
  169. }
  170. else
  171. {
  172. return false;
  173. }
  174. }
  175. }
  176. else if(IsVertical)
  177. {
  178. if (!otherLine.IsVertical)
  179. {
  180. return false;
  181. }
  182. if (Math.Abs(X1 - otherLine.X1) <= E)
  183. {
  184. return false;//重合的不叫平行
  185. }
  186. else
  187. {
  188. double yMinSpace = Math.Abs(Math.Min(Y1, Y2) - Math.Min(otherLine.Y1, otherLine.Y2));
  189. double yMaxSpace = Math.Abs(Math.Max(Y1, Y2) - Math.Max(otherLine.Y1, otherLine.Y2));
  190. if (yMinSpace <= E && yMaxSpace <= E)
  191. {
  192. return true;
  193. }
  194. else
  195. {
  196. return false;
  197. }
  198. }
  199. }
  200. return false;
  201. }
  202. public override void Move(double x, double y)
  203. {
  204. X1 = X1 + x;
  205. X2 = X2 + x;
  206. Y1 = Y1 + y;
  207. Y2 = Y2 + y;
  208. }
  209. }
  210. }