Refactor large function
This commit is contained in:
parent
7d9073eebf
commit
9f8c563c98
36
index.js
36
index.js
@ -18,41 +18,21 @@ function edgePoint(x1, y1, x2, y2, maxX, maxY) {
|
|||||||
yIntercept = x => (x - x1) * yDiff / xDiff + y1;
|
yIntercept = x => (x - x1) * yDiff / xDiff + y1;
|
||||||
|
|
||||||
if (xDiff > 0 && yDiff > 0) {
|
if (xDiff > 0 && yDiff > 0) {
|
||||||
let yWhenXisMax = yIntercept(maxX);
|
let x = xIntercept(maxY);
|
||||||
let xWhenYisMax = xIntercept(maxY);
|
|
||||||
|
|
||||||
if (xWhenYisMax <= maxX) {
|
pointCoords = x <= maxX ? [x, maxY] : [maxX, yIntercept(maxX)];
|
||||||
pointCoords = [xWhenYisMax, maxY];
|
|
||||||
} else {
|
|
||||||
pointCoords = [maxX, yWhenXisMax];
|
|
||||||
}
|
|
||||||
} else if (xDiff > 0 && yDiff < 0) {
|
} else if (xDiff > 0 && yDiff < 0) {
|
||||||
let yWhenXisMax = yIntercept(maxX);
|
let y = yIntercept(maxX);
|
||||||
let xWhenYisZero = xIntercept(0);
|
|
||||||
|
|
||||||
if (yWhenXisMax >= 0) {
|
pointCoords = y >= 0 ? [maxX, y] : [xIntercept(0), 0];
|
||||||
pointCoords = [maxX, yWhenXisMax];
|
|
||||||
} else {
|
|
||||||
pointCoords = [xWhenYisZero, 0];
|
|
||||||
}
|
|
||||||
} else if (xDiff < 0 && yDiff < 0) {
|
} else if (xDiff < 0 && yDiff < 0) {
|
||||||
let yWhenXisZero = yIntercept(0);
|
let x = xIntercept(0);
|
||||||
let xWhenYisZero = xIntercept(0);
|
|
||||||
|
|
||||||
if (xWhenYisZero >= 0) {
|
pointCoords = x >= 0 ? [x, 0] : [0, yIntercept(0)];
|
||||||
pointCoords = [xWhenYisZero, 0];
|
|
||||||
} else {
|
|
||||||
pointCoords = [0, yWhenXisZero];
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let yWhenXisZero = yIntercept(0);
|
let y = yIntercept(0);
|
||||||
let xWhenYisMax = xIntercept(maxY);
|
|
||||||
|
|
||||||
if (yWhenXisZero <= maxY) {
|
pointCoords = y <= maxY ? [0, y] : [xIntercept(maxY), maxY];
|
||||||
pointCoords = [0, yWhenXisZero];
|
|
||||||
} else {
|
|
||||||
pointCoords = [xWhenYisMax, maxY];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pointCoords;
|
return pointCoords;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user