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

Heightmap display has a fencepost error in coordinate calculations #1520

Closed
dfinberg opened this issue Aug 15, 2023 · 2 comments · Fixed by #1533
Closed

Heightmap display has a fencepost error in coordinate calculations #1520

dfinberg opened this issue Aug 15, 2023 · 2 comments · Fixed by #1533
Labels
⚡ Type: Bug Something isn't working

Comments

@dfinberg
Copy link

Mainsail Version:

2.7.0

Browser:

Chrome

Device:

Desktop PC

Operating System:

Windows

What happened?

In looking at the heightmap mesh, it displays the coordinate points of the x/y points. my bed is configured with a min of 10, max of 270 in the Y direction, 9x9. The highest point is at the left rear, at 10,270. In the right hand panel the max point is instead showed as "Max [10, 241.1]". 241.1 = 10+(270-10)*8/9 instead of the correct divisor of 8.

What did you expect to happen instead?

coordinate should be calculated correctly.

How to reproduce this bug?

display a heightmap and look at the max/min coordinates on the right panel, assuming they are not at the first point probed.

Additional information:

No response

@dfinberg dfinberg added the ⚡ Type: Bug Something isn't working label Aug 15, 2023
@dfinberg
Copy link
Author

I've never used vue before, but something like

--- a/src/pages/Heightmap.vue
+++ b/src/pages/Heightmap.vue
@@ -985,17 +985,23 @@ export default class PageHeightmap extends Mixins(BaseMixin, ControlMixin) {
             }
         })
 
+       let x_length = this.bed_mesh.probed_matrix[0].length - 1;
+       if (x_length < 1) x_length = 1;
+
+       let y_length = this.bed_mesh.probed_matrix.length - 1;
+       if (y_length < 1) y_length = 1;
+
         const positionX =
             Math.round(
                 (this.bed_mesh.mesh_min[0] +
-                    ((this.bed_mesh.mesh_max[0] - this.bed_mesh.mesh_min[0]) / this.bed_mesh.probed_matrix[0].length) *
+                    ((this.bed_mesh.mesh_max[0] - this.bed_mesh.mesh_min[0]) / x_length) *
                         (col - 1)) *
                     10
             ) / 10
         const positionY =
             Math.round(
                 (this.bed_mesh.mesh_min[1] +
-                    ((this.bed_mesh.mesh_max[1] - this.bed_mesh.mesh_min[1]) / this.bed_mesh.probed_matrix.length) *
+                    ((this.bed_mesh.mesh_max[1] - this.bed_mesh.mesh_min[1]) / y_length) *
                         (row - 1)) *
                     10
             ) / 10
@@ -1023,17 +1029,23 @@ export default class PageHeightmap extends Mixins(BaseMixin, ControlMixin) {
             }
         })
 
+       let x_length = this.bed_mesh.probed_matrix[0].length - 1;
+       if (x_length < 1) x_length = 1;
+
+       let y_length = this.bed_mesh.probed_matrix.length - 1;
+       if (y_length < 1) y_length = 1;
+
         const positionX =
             Math.round(
                 (this.bed_mesh.mesh_min[0] +
-                    ((this.bed_mesh.mesh_max[0] - this.bed_mesh.mesh_min[0]) / this.bed_mesh.probed_matrix[0].length) *
+                    ((this.bed_mesh.mesh_max[0] - this.bed_mesh.mesh_min[0]) / x_length) *
                         (col - 1)) *
                     10
             ) / 10
         const positionY =
             Math.round(
                 (this.bed_mesh.mesh_min[1] +
-                    ((this.bed_mesh.mesh_max[1] - this.bed_mesh.mesh_min[1]) / this.bed_mesh.probed_matrix.length) *
+                    ((this.bed_mesh.mesh_max[1] - this.bed_mesh.mesh_min[1]) / y_length) *
                         (row - 1)) *
                     10
             ) / 10

@meteyou
Copy link
Member

meteyou commented Aug 27, 2023

Thx for reporting this bug and your solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants