Skip to content

Commit

Permalink
Fix unit in box dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscognite committed Jun 17, 2024
1 parent 28cf5c8 commit 292a825
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions react-components/src/architecture/base/renderTarget/UnitSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ export class UnitSystem {
return value;
}

public convertFromUnit(value: number, quantity: Quantity): number {
if (!this.isMetric) {
switch (quantity) {
case Quantity.Length:
return value / METER_TO_FT;
case Quantity.Area:
return value / (METER_TO_FT * METER_TO_FT);
case Quantity.Volume:
return value / (METER_TO_FT * METER_TO_FT * METER_TO_FT);
}
}
return value;
}

// ==================================================
// INSTANCE METHODS: Convert number to string
// ==================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ export class BoxDragger extends BaseDragger {
const newSize = this._unitSystem.convertToUnit(size.getComponent(index), Quantity.Length);
// Divide the box into abound some parts and use that as the increment
const increment = roundIncrement(newSize / 25);
const roundedNewSize = round(newSize, increment);
size.setComponent(index, round(newSize, roundedNewSize));
let roundedNewSize = round(newSize, increment);
roundedNewSize = this._unitSystem.convertFromUnit(roundedNewSize, Quantity.Length);
size.setComponent(index, roundedNewSize);
}
if (size.getComponent(index) === this._sizeOfBox.getComponent(index)) {
return false; // Nothing has changed
Expand Down

0 comments on commit 292a825

Please sign in to comment.