Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Convert to function (in preparation of declassing)

Manav Rathi2db8c779b44e
diff --git a/web/apps/photos/src/services/face/f-index.ts b/web/apps/photos/src/services/face/f-index.ts
index 0c899f478e..959c5c0b5a 100644
--- a/web/apps/photos/src/services/face/f-index.ts
+++ b/web/apps/photos/src/services/face/f-index.ts
@@ -4,7 +4,13 @@ import log from "@/next/log";
import { workerBridge } from "@/next/worker/worker-bridge";
import { euclidean } from "hdbscan";
import { Matrix } from "ml-matrix";
-import { Box, Dimensions, Point, enlargeBox } from "services/face/geom";
+import {
+ Box,
+ Dimensions,
+ Point,
+ enlargeBox,
+ roundBox,
+} from "services/face/geom";
import type {
Face,
FaceAlignment,
@@ -675,16 +681,18 @@ const extractFaceCrop = (
imageBitmap: ImageBitmap,
alignment: FaceAlignment,
): ImageBitmap => {
- const alignmentBox = new Box({
- x: alignment.center.x - alignment.size / 2,
- y: alignment.center.y - alignment.size / 2,
- width: alignment.size,
- height: alignment.size,
- }).round();
+ const alignmentBox = roundBox(
+ new Box({
+ x: alignment.center.x - alignment.size / 2,
+ y: alignment.center.y - alignment.size / 2,
+ width: alignment.size,
+ height: alignment.size,
+ }),
+ );
const padding = 0.25;
const scaleForPadding = 1 + padding * 2;
- const paddedBox = enlargeBox(alignmentBox, scaleForPadding).round();
+ const paddedBox = roundBox(enlargeBox(alignmentBox, scaleForPadding));
// TODO-ML: The rotation doesn't seem to be used? it's set to 0.
return cropWithRotation(imageBitmap, paddedBox, 0, 256);
@@ -696,7 +704,7 @@ const cropWithRotation = (
rotation: number,
maxDimension: number,
) => {
- const box = cropBox.round();
+ const box = roundBox(cropBox);
const outputSize = { width: box.width, height: box.height };
diff --git a/web/apps/photos/src/services/face/geom.ts b/web/apps/photos/src/services/face/geom.ts
index 7b6347490c..5f6456ca60 100644
--- a/web/apps/photos/src/services/face/geom.ts
+++ b/web/apps/photos/src/services/face/geom.ts
@@ -32,18 +32,17 @@ export class Box implements IRect {
this.width = width;
this.height = height;
}
-
- public round(): Box {
- const [x, y, width, height] = [
- this.x,
- this.y,
- this.width,
- this.height,
- ].map((val) => Math.round(val));
- return new Box({ x, y, width, height });
- }
}
+/** Round all the components of the box. */
+export const roundBox = (box: Box): Box => {
+ const [x, y, width, height] = [box.x, box.y, box.width, box.height].map(
+ (val) => Math.round(val),
+ );
+ return new Box({ x, y, width, height });
+};
+
+/** Increase the size of the given {@link box} by {@link factor}. */
export const enlargeBox = (box: Box, factor: number) => {
const center = new Point(box.x + box.width / 2, box.y + box.height / 2);
const newWidth = factor * box.width;