Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

连线重合优化 #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions WeSketch.sketchplugin/Contents/Sketch/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,36 +698,38 @@ function getLink(context,refursh){
var comparedLineCollectionCount = lineCollections.length - (lineCount - 1);

// 解决线重合问题
for (var i = 0; i < lineCount; i++) {
for (var j = 0; j < comparedLineCollectionCount; j++) {
if ((linepoint[i].direction == 't' || linepoint[i].direction == 'b')
&& (Math.abs(linepoint[i].position - lineCollections[j].position) < 3)) {
// 不是起始线重合,位于起始点左侧 || 起始线重合: 位于重合线下侧,减去 coincideOffset
if ((i != 0 && linepoint[0].x < linepoint[i].x)
|| (i == 0 && (linepoint[0].y < lineCollections[j].y))) {
linepoint[i].x -= coincideOffset;
linepoint[i+1].x -= coincideOffset;
}
else {
linepoint[i].x += coincideOffset;
linepoint[i+1].x += coincideOffset;
}
}
else if ((linepoint[i].direction == 'l' || linepoint[i].direction == 'r')
&& (Math.abs(linepoint[i].position - lineCollections[j].position) < 3)) {
// 不是起始线重合,位于起始点上侧 || 起始线重合: 位于重合线左侧,减去 coincideOffset
if ((i != 0 && linepoint[0].y < linepoint[i].y)
|| (i == 0 && linepoint[0].x < lineCollections[j].x)) {
linepoint[i].y -= coincideOffset;
linepoint[i+1].y -= coincideOffset;
}
else {
linepoint[i].y += coincideOffset;
linepoint[i+1].y += coincideOffset;
}
}
else {}
for (var i = 0; i < lineCount - 2; i++) {
for (var j = 2; j < lineCount - 2; j++) {
if ((linepoint[i].direction == 't' || linepoint[i].direction == 'b') &&
(Math.abs(linepoint[i].position - linepoint[j].position) < 3) &&
(Math.max(linepoint[i].y, linepoint[j].y) <= Math.min(linepoint[i+1].y, linepoint[j+1].y))) {
// 不是起始线重合,位于起始点左侧 || 起始线重合: 位于重合线下侧,减去 coincideOffset
if ((i != 0 && linepoint[0].x < linepoint[i].x) ||
(i == 0 && (linepoint[0].y < lineCollections[j].y))) {
linepoint[i].x -= coincideOffset;
linepoint[i+1].x -= coincideOffset;
}
else {
linepoint[i].x += coincideOffset;
linepoint[i+1].x += coincideOffset;
}
}
else if ((linepoint[i].direction == 'l' || linepoint[i].direction == 'r') &&
(Math.abs(linepoint[i].position - linepoint[j].position) < 3) &&
(Math.max(linepoint[i].x, linepoint[j].x) <= Math.min(linepoint[i+1].x, linepoint[j+1].x))) {
// 不是起始线重合,位于起始点上侧 || 起始线重合: 位于重合线左侧,减去 coincideOffset
if ((i != 0 && linepoint[0].y < linepoint[i].y) ||
(i == 0 && linepoint[0].x < lineCollections[j].x)) {
linepoint[i].y -= coincideOffset;
linepoint[i+1].y -= coincideOffset;
}
else {
linepoint[i].y += coincideOffset;
linepoint[i+1].y += coincideOffset;
}
}
else {}
}
}

for(var i = 0; i < lineCount - 1; i++){
Expand Down