Skip to content

Commit

Permalink
fix rounding problem in loop mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rcbyr committed Jun 15, 2022
1 parent ecfd9a4 commit e9f92ea
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,19 @@ export default function Track(
}

function getIndexes(pos) {
let factor = Math.floor(Math.abs(pos / length))
const positionRelative = round(((pos % length) + length) % length)
let factor = Math.floor(Math.abs(round(pos / length)))
let positionRelative = round(((pos % length) + length) % length)
if (positionRelative === length) {
positionRelative = 0
}
const positionSign = sign(pos)
const origin = relativePositions.indexOf(
[...relativePositions].reduce((a, b) =>
Math.abs(b - positionRelative) < Math.abs(a - positionRelative) ? b : a
)
)
let idx = origin
if (positionSign < 0 && positionRelative !== 0) factor++
if (positionSign < 0) factor++
if (origin === slidesCount) {
idx = 0
factor += positionSign > 0 ? 1 : -1
Expand Down Expand Up @@ -267,7 +270,7 @@ export default function Track(
return acc
}, null)
if (trackLength === 0) maxRelativeIdx = 0
relativePositions.push(length)
relativePositions.push(round(length))
}

function clampIdx(idx) {
Expand Down

0 comments on commit e9f92ea

Please sign in to comment.