* 获取线段和矩形的交点 * @param line
(line: Line)
| 262 | * @param line |
| 263 | */ |
| 264 | public getCollidePointsWithLine(line: Line): Vector[] { |
| 265 | const result: Vector[] = []; |
| 266 | if (this.isPointIn(line.start)) { |
| 267 | result.push(line.start); |
| 268 | } |
| 269 | if (this.isPointIn(line.end)) { |
| 270 | result.push(line.end); |
| 271 | } |
| 272 | const topResult = line.getIntersectingWithHorizontalLine(this.location.y, this.left, this.right); |
| 273 | if (topResult.intersects) { |
| 274 | result.push(topResult.point!); |
| 275 | } |
| 276 | const bottomResult = line.getIntersectingWithHorizontalLine(this.location.y + this.size.y, this.left, this.right); |
| 277 | if (bottomResult.intersects) { |
| 278 | result.push(bottomResult.point!); |
| 279 | } |
| 280 | const leftResult = line.getIntersectingWithVerticalLine(this.location.x, this.bottom, this.top); |
| 281 | if (leftResult.intersects) { |
| 282 | result.push(leftResult.point!); |
| 283 | } |
| 284 | const rightResult = line.getIntersectingWithVerticalLine(this.location.x + this.size.x, this.bottom, this.top); |
| 285 | if (rightResult.intersects) { |
| 286 | result.push(rightResult.point!); |
| 287 | } |
| 288 | |
| 289 | return result; |
| 290 | } |
| 291 | /** |
| 292 | * 是否完全在另一个矩形内 |
| 293 | * AI写的,有待测试 |
no test coverage detected