Skip to content

Commit

Permalink
fix: 浮点数精度丢失导致画布缩放卡死 (#4356)
Browse files Browse the repository at this point in the history
* fix: 浮点数精度丢失导致画布缩放卡死

* chore: 移除多余的代码
  • Loading branch information
ch1ny committed Jul 8, 2024
1 parent f966327 commit 78179da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions packages/x6/src/graph/mousewheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export class MouseWheel extends Base {
// webkit and to avoid rounding errors for zoom steps
this.cumulatedFactor =
Math.round(this.currentScale * factor * 20) / 20 / this.currentScale
if (this.cumulatedFactor === 1) {
this.cumulatedFactor = 1.05
}
}
if (this.cumulatedFactor <= 1) {
this.cumulatedFactor = 1.05
}
} else {
// zoomout
Expand All @@ -98,9 +98,9 @@ export class MouseWheel extends Base {
Math.round(this.currentScale * (1 / factor) * 20) /
20 /
this.currentScale
if (this.cumulatedFactor === 1) {
this.cumulatedFactor = 0.95
}
}
if (this.cumulatedFactor >= 1) {
this.cumulatedFactor = 0.95
}
}

Expand All @@ -114,6 +114,7 @@ export class MouseWheel extends Base {
let targetScale = this.graph.transform.clampScale(
currentScale * this.cumulatedFactor,
)

const minScale = this.widgetOptions.minScale || Number.MIN_SAFE_INTEGER
const maxScale = this.widgetOptions.maxScale || Number.MAX_SAFE_INTEGER
targetScale = NumberExt.clamp(targetScale, minScale, maxScale)
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78179da

Please sign in to comment.