* 自己这个矩形是否和线段有交点 * 用于节点切割检测 * * @param line
(line: Line)
| 233 | * @param line |
| 234 | */ |
| 235 | public isCollideWithLine(line: Line): boolean { |
| 236 | if (this.isPointIn(line.start) || this.isPointIn(line.end)) { |
| 237 | // 当用于切割线的时候,两个端点必定都在矩形外 |
| 238 | // 这个实际上是不可能的,但是为了保险起见,还是加上判断 |
| 239 | return true; |
| 240 | } |
| 241 | |
| 242 | if (line.isIntersectingWithHorizontalLine(this.location.y, this.left, this.right)) { |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | if (line.isIntersectingWithHorizontalLine(this.location.y + this.size.y, this.left, this.right)) { |
| 247 | return true; |
| 248 | } |
| 249 | |
| 250 | if (line.isIntersectingWithVerticalLine(this.location.x, this.bottom, this.top)) { |
| 251 | return true; |
| 252 | } |
| 253 | |
| 254 | if (line.isIntersectingWithVerticalLine(this.location.x + this.size.x, this.bottom, this.top)) { |
| 255 | return true; |
| 256 | } |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * 获取线段和矩形的交点 |
nothing calls this directly
no test coverage detected