Skip to content

Commit

Permalink
Improve return type of intersection2
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed May 17, 2024
1 parent 1bdf5ce commit 56285f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions packages/core/util/calculateDynamicBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,14 @@ export default function calculateDynamicBlocks(
const regionWidthPx = (regionEnd - regionStart) / bpPerPx
const parentRegion = isStateTreeNode(region) ? getSnapshot(region) : region

if (
displayedRegionLeftPx < windowRightPx &&
displayedRegionRightPx > windowLeftPx
) {
const [leftPx, rightPx] = intersection2(
windowLeftPx,
windowRightPx,
displayedRegionLeftPx,
displayedRegionRightPx,
)
if (leftPx !== undefined && rightPx !== undefined) {
// this displayed region overlaps the view, so make a record for it
const [leftPx, rightPx] = intersection2(
windowLeftPx,
windowRightPx,
displayedRegionLeftPx,
displayedRegionRightPx,
)
let start: number
let end: number
let isLeftEndOfDisplayedRegion: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/core/util/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function intersection2(
right1: number,
left2: number,
right2: number,
) {
): [number, number] | [] {
// this code is verbose because "if" statements are faster than Math.min and Math.max
if (right1 > left2 && left1 < right2 && right2 - left2 && right1 - left1) {
if (left1 > left2) {
Expand Down

0 comments on commit 56285f3

Please sign in to comment.