Skip to content

Conversation

@MiguelG97
Copy link
Member

@MiguelG97 MiguelG97 commented Jan 12, 2026

Description

This PR fixes two related issues affecting area/volume measurements and their label visibility (closes #668):

BEFORE:
image

AFTER:
image

  1. Incorrect unit conversion scaling:
    Area and volume are scaled incorrectly, causing small measurements (e.g. m2 -> km2) to collapse to 0 even with high precision (5).
    The unit conversion utility already defines factors for area (m², km²) and volume (m³, km³) in the unitFactors variable.
    ```
    const unitFactors: Record<string, number> = {
    // Length
    m: 1,
    cm: 0.01,
    mm: 0.001,
    km: 1000,
    // Area
    m2: 1,
    cm2: 0.0001,
    mm2: 0.000001,
    km2: 1000000,
    // Volume
    m3: 1,
    cm3: 0.000001,
    mm3: 0.000000001,
    km3: 1000000000,
    };

However, the conversion logic applied an additional exponentiation step, effectively scaling the values twice.

```
if (fromUnit.endsWith("2") && toUnit.endsWith("2")) {
      factor **= 2;
    } else if (fromUnit.endsWith("3") && toUnit.endsWith("3")) {
      factor **= 3;
    }
```
  1. MeasureMark visibility:

    The MeasureMark visibility was determined using the area’s value property. Since value applies unit conversion and rounding (default precision: 2), small measurements (e.g. m² → km²) were converted to 0. As a result, the label were turned off, negatively affecting the user experience. The solution is to use the rawValue instead, which preserves the original area value in m².


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following:

  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Follow the Conventional Commits v1.0.0 standard for PR naming (e.g. feat(examples): add hello-world example).
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Area measurement km2 unit

1 participant