SGraphAreaGroupItem.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SGraphItem } from "../SGraphItem";
  27. import {
  28. SPainter,
  29. SPath,
  30. SPoint,
  31. SPolygonUtil,
  32. SRect
  33. } from "@persagy-web/draw/lib";
  34. import { SGraphShape } from "./SGraphShape";
  35. import { AreaGroup } from "../types/AreaGroup";
  36. /**
  37. * 区域组
  38. *
  39. * @author 郝建龙
  40. */
  41. export class SGraphAreaGroupItem extends SGraphShape {
  42. /** X坐标最小值 */
  43. private minX = Number.MAX_SAFE_INTEGER;
  44. /** X坐标最大值 */
  45. private maxX = Number.MIN_SAFE_INTEGER;
  46. /** Y坐标最小值 */
  47. private minY = Number.MAX_SAFE_INTEGER;
  48. /** Y坐标最大值 */
  49. private maxY = Number.MIN_SAFE_INTEGER;
  50. /** 墙轮廓线坐标list */
  51. private readonly pointList: SPoint[][][] = [];
  52. /** path对象 */
  53. private pathList: SPath[] = [];
  54. /**
  55. * 构造函数
  56. *
  57. * @param parent 父类
  58. * @param data 轮廓线及风格数据
  59. * */
  60. constructor(parent: SGraphItem | null, data: AreaGroup) {
  61. super(parent, data.Style);
  62. if (data.OutLine.length && data.OutLine[0] && data.OutLine[0].length) {
  63. let tempArr = data.OutLine;
  64. this.minX = tempArr[0][0][0].X;
  65. this.maxX = this.minX;
  66. this.minY = -tempArr[0][0][0].Y;
  67. this.maxY = this.minY;
  68. // 处理轮廓点数组,同时计算最大最小值
  69. this.pointList = tempArr.map((t): SPoint[][] => {
  70. let sPath = new SPath();
  71. let tempArr = t.map((it): SPoint[] => {
  72. let array = it.map(
  73. (item): SPoint => {
  74. let x = item.X,
  75. y = -item.Y;
  76. if (x < this.minX) {
  77. this.minX = x;
  78. }
  79. if (y < this.minY) {
  80. this.minY = y;
  81. }
  82. if (x > this.maxX) {
  83. this.maxX = x;
  84. }
  85. if (y > this.maxY) {
  86. this.maxY = y;
  87. }
  88. return new SPoint(x, y);
  89. }
  90. );
  91. sPath.polygon(array);
  92. return array;
  93. });
  94. this.pathList.push(sPath);
  95. return tempArr;
  96. });
  97. }
  98. } // Constructor
  99. /**
  100. * Item对象边界区域
  101. *
  102. * @return SRect
  103. */
  104. boundingRect(): SRect {
  105. return new SRect(
  106. this.minX,
  107. this.minY,
  108. this.maxX - this.minX,
  109. this.maxY - this.minY
  110. );
  111. } // Function boundingRect()
  112. /**
  113. * 判断点是否在区域内
  114. *
  115. * @param x
  116. * @param y
  117. * @return boolean
  118. */
  119. contains(x: number, y: number): boolean {
  120. for (let j = 0; j < this.pointList.length; j++) {
  121. let arr = this.pointList[j];
  122. if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
  123. continue;
  124. }
  125. if (arr.length == 1) {
  126. return true;
  127. }
  128. let flag = false;
  129. for (let i = 1; i < arr.length; i++) {
  130. if (SPolygonUtil.pointIn(x, y, arr[i])) {
  131. flag = true;
  132. break;
  133. }
  134. }
  135. if (flag) {
  136. continue;
  137. }
  138. return true;
  139. }
  140. return false;
  141. } // Function contains()
  142. /**
  143. * Item绘制操作
  144. *
  145. * @param painter painter对象
  146. */
  147. onDraw(painter: SPainter): void {
  148. super.onDraw(painter);
  149. this.pathList.forEach((t): void => {
  150. painter.drawPath(t);
  151. });
  152. } // Function onDraw()
  153. } // Class SGraphAreaGroupItem