Skip to content

Commit

Permalink
feat: added option to fit the width, rather than the height, to Layer…
Browse files Browse the repository at this point in the history
…edTranslator
  • Loading branch information
DanielSturk committed Oct 18, 2021
1 parent d77812b commit 9715552
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lib/engines/layerCompositor/LayerCompositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,19 @@ export function makeColorMipmapAttachment(
);
}

export enum ImageFitMode {
FitWidth = "fitWidth",
FitHeight = "fitHeight",
}

export class LayerCompositor {
context: RenderingContext;
layerImageCache: LayerImageMap = {};
texImage2DPromiseCache: TexImage2DPromiseMap = {};
#bufferGeometry: BufferGeometry;
#program: Program;
imageSize = new Vector2(0, 0);
imageFitMode: ImageFitMode = ImageFitMode.FitHeight;
zoomScale = 1.0; // no zoom
panPosition: Vector2 = new Vector2(0.5, 0.5); // center
#layers: Layer[] = [];
Expand Down Expand Up @@ -232,7 +238,11 @@ export class LayerCompositor {
const canvasSize = canvasFramebuffer.size;
const canvasAspectRatio = canvasSize.width / canvasSize.height;

const imageToCanvasScale = canvasSize.height / this.imageSize.height;
const imageToCanvasScale =
this.imageFitMode === ImageFitMode.FitWidth
? canvasSize.width / this.imageSize.width
: canvasSize.height / this.imageSize.height;

const canvasImageSize = this.imageSize.clone().multiplyByScalar(imageToCanvasScale);
const canvasImageCenter = canvasImageSize.clone().multiplyByScalar(0.5);

Expand Down

0 comments on commit 9715552

Please sign in to comment.