Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update logarithmic calculations to use base 10 for distance scaling #320

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/custom-material/src/grid/GridControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ export class GridControl extends Script {
material.nearClipPlane = camera.nearClipPlane;
material.farClipPlane = camera.farClipPlane;

const logDistance = Math.log2(this.distance);
const upperDistance = Math.pow(2, Math.floor(logDistance) + 1);
const lowerDistance = Math.pow(2, Math.floor(logDistance));
const logDistance = Math.log10(this.distance);
const upperDistance = Math.pow(10, Math.floor(logDistance) + 1);
const lowerDistance = Math.pow(10, Math.floor(logDistance));
Comment on lines +67 to +69
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Breaking change: Base-2 to Base-10 logarithm switch requires major version bump

While the change to base-10 logarithms improves intuition, this is a breaking change that will affect the visual output of existing applications. Based on the codebase analysis:

  • Bump the major version number (current: 1.3.9)
  • Add documentation explaining the new distance scaling behavior
  • Consider adding tests to validate the grid scaling behavior
🔗 Analysis chain

Switching to base-10 logarithms improves distance visualization intuition.

The change from base-2 to base-10 logarithms makes the distance scaling more intuitive as it aligns with the decimal system. However, this is potentially a breaking change that could affect existing visualizations.

Please verify:

  1. The impact on existing visualizations
  2. Whether this requires a major version bump
  3. Update documentation to reflect this change in behavior
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any documentation files that might need updates
fd -e md -e mdx . | xargs rg -l "grid.*distance|distance.*scaling"

Length of output: 68


Script:

#!/bin/bash
# Find all files referencing GridControl
rg -l "GridControl" --type ts --type tsx

# Find test files related to grid
fd -e test.ts -e spec.ts . | xargs rg -l "grid|distance"

# Check package version management
cat packages/custom-material/package.json

Length of output: 888


Script:

#!/bin/bash
# Try different approach to find related files
rg -l "GridControl" --type ts

# Look for test files with .ts extension
fd "Grid.*\.(test|spec)\.ts$"

# Check if there are any examples or demos
fd -e ts . | xargs rg -l "new GridControl"

Length of output: 198

material.fade = (this.distance - lowerDistance) / (upperDistance - lowerDistance);

const level = -Math.floor(logDistance);
material.primaryScale = Math.pow(2, level);
material.secondaryScale = Math.pow(2, level + 1);
material.primaryScale = Math.pow(10, level);
material.secondaryScale = Math.pow(10, level + 1);
material.axisIntensity = 0.3 / material.primaryScale;

if (this._flipGrid) {
Expand Down
Loading