Skip to content

Commit

Permalink
fix: 布尔运算水平线重合判断
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Jun 26, 2023
1 parent f38ff44 commit 615356a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45410,8 +45410,20 @@
overs = checkOverlapLine(ax1, ay1, ax2, ay2, seg, bx1, by1, bx2, by2, item, true);
}
} else {
var b1 = (ay2 - ay1) * ax1 / (ax2 - ax1) + ay1;
var b2 = (by2 - by1) * bx1 / (bx2 - bx1) + by1;
// 水平线默认k是0
var k1 = 0;
var k2 = 0;

if (ay2 !== ay1) {
k1 = (ax2 - ax1) / (ay2 - ay1);
}

if (by2 !== by1) {
k2 = (bx2 - bx1) / (by2 - by1);
}

var b1 = ay1 - k1 * ax1;
var b2 = by1 - k2 * bx1;

if (b1 === b2) {
overs = checkOverlapLine(ax1, ay1, ax2, ay2, seg, bx1, by1, bx2, by2, item, false);
Expand Down
2 changes: 1 addition & 1 deletion index.js.map

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/math/bo/Polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,17 @@ function findIntersection(list, compareBelong, isIntermediateA, isIntermediateB)
}
}
else {
let b1 = (ay2 - ay1) * ax1 / (ax2 - ax1) + ay1;
let b2 = (by2 - by1) * bx1 / (bx2 - bx1) + by1;
// 水平线默认k是0
let k1 = 0;
let k2 = 0;
if (ay2 !== ay1) {
k1 = (ax2 - ax1) / (ay2 - ay1);
}
if (by2 !== by1) {
k2 = (bx2 - bx1) / (by2 - by1);
}
const b1 = ay1 - k1 * ax1;
const b2 = by1 - k2 * bx1;
if(b1 === b2) {
overs = checkOverlapLine(ax1, ay1, ax2, ay2, seg,
bx1, by1, bx2, by2, item, false);
Expand Down

0 comments on commit 615356a

Please sign in to comment.