Web Dev Solutions

Catalin Mititiuc

From 7d9073eebf14e9dfb74799fa6c6658b904051ed2 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 22 Mar 2024 16:58:12 -0700 Subject: Add some symmetry to edge point calculation function --- index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 4255ca4..5d68314 100644 --- a/index.js +++ b/index.js @@ -30,21 +30,19 @@ function edgePoint(x1, y1, x2, y2, maxX, maxY) { let yWhenXisMax = yIntercept(maxX); let xWhenYisZero = xIntercept(0); - if (xWhenYisZero <= maxX) { - // yWhenXisMax - pointCoords = [xWhenYisZero, 0]; - } else { + if (yWhenXisMax >= 0) { pointCoords = [maxX, yWhenXisMax]; + } else { + pointCoords = [xWhenYisZero, 0]; } } else if (xDiff < 0 && yDiff < 0) { let yWhenXisZero = yIntercept(0); let xWhenYisZero = xIntercept(0); - if (yWhenXisZero >= 0) { - // xWhenYisZero - pointCoords = [0, yWhenXisZero]; - } else { + if (xWhenYisZero >= 0) { pointCoords = [xWhenYisZero, 0]; + } else { + pointCoords = [0, yWhenXisZero]; } } else { let yWhenXisZero = yIntercept(0); -- cgit v1.2.3