Skip to content

Commit

Permalink
fix: get correct scale
Browse files Browse the repository at this point in the history
  • Loading branch information
SimbiozizV committed Jan 10, 2025
1 parent 26c3724 commit 352fc05
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions src/services/camera/CameraService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,15 @@ export class CameraService extends Emitter {
});
}

public getScaleRelativeDimensions(width: number, height: number) {
let scale = 1;

if (width > height) {
const calculatedScale = Number((this.state.width / width).toFixed(3));

if (calculatedScale > this.state.scaleMax) {
scale = this.state.scaleMax;
} else if (calculatedScale < this.state.scaleMin) {
scale = this.state.scaleMin;
} else {
scale = calculatedScale;
}
} else {
const calculatedScale = Number((this.state.height / height).toFixed(3));

if (calculatedScale > this.state.scaleMax) {
scale = this.state.scaleMax;
} else if (calculatedScale < this.state.scaleMin) {
scale = this.state.scaleMin;
} else {
scale = calculatedScale;
}
}
public getScaleRelativeDimensionsBySide(size: number, axis: "width" | "height") {
return clamp(Number(this.state[axis] / size), this.state.scaleMin, this.state.scaleMax);
}

return scale;
public getScaleRelativeDimensions(width: number, height: number) {
return Math.min(
this.getScaleRelativeDimensionsBySide(width, "width"),
this.getScaleRelativeDimensionsBySide(height, "height")
);
}

public getXYRelativeCenterDimensions(dimensions: TRect, scale: number) {
Expand Down

0 comments on commit 352fc05

Please sign in to comment.