Skip to content
Snippets Groups Projects
Commit 34d23dfa authored by Yuriy Maksymets's avatar Yuriy Maksymets
Browse files

Avoid dividing by 0 in erasure interval computation

parent 0e2fc545
No related branches found
No related tags found
No related merge requests found
......@@ -63,16 +63,20 @@ function cap1(x) {
}
function erasureInterval(lineStart, lineEnd, erasureCenter, erasureRadius) {
const lineLength = distance(lineStart, lineEnd)
const distToLine = distanceToLine(lineStart, lineEnd, erasureCenter)
if (lineLength === 0) {
return distToLine <= erasureRadius ? [0, 1] : [0, 0]
}
const projectionPoint = interpolate(
lineStart,
lineEnd,
project(lineStart, lineEnd, erasureCenter),
)
const d = distanceToLine(lineStart, lineEnd, erasureCenter)
const halfLength = Math.sqrt(erasureRadius ** 2 - d ** 2)
const lineLength = distance(lineStart, lineEnd)
const touchFromStartDist = distance(lineStart, projectionPoint)
const halfLength = Math.sqrt(erasureRadius ** 2 - distToLine ** 2)
const touchBeginFromStarDist = touchFromStartDist - halfLength
const touchEndFromStarDist = touchFromStartDist + halfLength
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment