MCPcopy Index your code
hub / github.com/graphif/project-graph / getLineIntersectionPoint

Method getLineIntersectionPoint

packages/shapes/src/Rectangle.ts:358–380  ·  view source on GitHub ↗

* 返回一个线段和这个矩形的交点,如果没有交点,就返回这个矩形的中心点 * 请确保线段和矩形只有一个交点,出现两个交点的情况还未测试

(line: Line)

Source from the content-addressed store, hash-verified

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矩形边上,则该函数可能返回任意向量。

Callers 15

renderLineShapeMethod · 0.80
getConnectedEffectsMethod · 0.80
renderShiftingStateMethod · 0.80
renderVirtualEdgeMethod · 0.80
getConnectedEffectsMethod · 0.80
renderShiftingStateMethod · 0.80
renderVirtualEdgeMethod · 0.80

Calls 3

getIntersectionMethod · 0.95
getCenterMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected