* 返回一个线段和这个矩形的交点,如果没有交点,就返回这个矩形的中心点 * 请确保线段和矩形只有一个交点,出现两个交点的情况还未测试
(line: Line)
| 356 | * 请确保线段和矩形只有一个交点,出现两个交点的情况还未测试 |
| 357 | */ |
| 358 | public getLineIntersectionPoint(line: Line) { |
| 359 | const topLine = new Line(this.location, this.location.add(new Vector(this.size.x, 0))); |
| 360 | const topIntersection = topLine.getIntersection(line); |
| 361 | if (topIntersection) { |
| 362 | return topIntersection; |
| 363 | } |
| 364 | const bottomLine = new Line(this.location.add(new Vector(0, this.size.y)), this.location.add(this.size)); |
| 365 | const bottomIntersection = bottomLine.getIntersection(line); |
| 366 | if (bottomIntersection) { |
| 367 | return bottomIntersection; |
| 368 | } |
| 369 | const leftLine = new Line(this.location, this.location.add(new Vector(0, this.size.y))); |
| 370 | const leftIntersection = leftLine.getIntersection(line); |
| 371 | if (leftIntersection) { |
| 372 | return leftIntersection; |
| 373 | } |
| 374 | const rightLine = new Line(this.location.add(new Vector(this.size.x, 0)), this.location.add(this.size)); |
| 375 | const rightIntersection = rightLine.getIntersection(line); |
| 376 | if (rightIntersection) { |
| 377 | return rightIntersection; |
| 378 | } |
| 379 | return this.getCenter(); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * 获取在this矩形边上的point的单位法向量,若point不在this矩形边上,则该函数可能返回任意向量。 |
no test coverage detected