Skip to content

Commit 397d58c

Browse files
Address comments from code review, add docstrings
1 parent 7c9cf24 commit 397d58c

6 files changed

Lines changed: 18 additions & 6 deletions

File tree

dist/ulabel.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ulabel.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/annotation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class ULabelAnnotation {
180180
* @param {number} image_height Height of the image.
181181
* @return {ULabelAnnotation} The annotation with the updated spatial payload.
182182
*/
183-
public fit_to_image_bounds(image_width: number, image_height: number): ULabelAnnotation {
183+
public clamp_annotation_to_image_bounds(image_width: number, image_height: number): ULabelAnnotation {
184184
if (!this.is_delete_annotation()) {
185185
// Ensure each point in the payload is within the image
186186
// for polygons, we'll need to loop through all points
@@ -205,6 +205,12 @@ export class ULabelAnnotation {
205205
return this;
206206
}
207207

208+
/**
209+
* Check if the annotation is a delete annotation, e.g. annotations drawn by the `delete_polygon`
210+
* or `delete_bbox` annotation modes.
211+
*
212+
* @returns {boolean} True if the annotation is a delete annotation, false otherwise.
213+
*/
208214
public is_delete_annotation(): boolean {
209215
// Check if the annotation is a delete annotation
210216
return this.classification_payloads[0]["class_id"] === DELETE_CLASS_ID;

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2984,7 +2984,7 @@ export class ULabel {
29842984

29852985
// Snap each point to the image bounds
29862986
if (!this.config.allow_annotations_outside_image) {
2987-
new_annotation = new_annotation.fit_to_image_bounds(this.config["image_width"], this.config["image_height"]);
2987+
new_annotation = new_annotation.clamp_annotation_to_image_bounds(this.config["image_width"], this.config["image_height"]);
29882988
}
29892989

29902990
if (spatial_type === "polygon") {
@@ -5319,6 +5319,12 @@ export class ULabel {
53195319
return raw;
53205320
}
53215321

5322+
/**
5323+
* Get the mouse position, clamped to the image bounds if `allow_annotations_outside_image` is false.
5324+
*
5325+
* @param {*} mouse_event The mouse event to get the position from
5326+
* @returns {[number, number]} The (x, y) coordinates of the mouse, clamped to the image bounds if required
5327+
*/
53225328
get_image_aware_mouse_x_y(mouse_event) {
53235329
const x = this.get_global_mouse_x(mouse_event);
53245330
const y = this.get_global_mouse_y(mouse_event);

src/initializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export async function ulabel_init(
9393
const image_width = ulabel.config["image_width"];
9494
for (const subtask of Object.values(ulabel.subtasks)) {
9595
for (const anno of Object.values(subtask.annotations.access)) {
96-
anno.fit_to_image_bounds(image_width, image_height);
96+
anno.clamp_annotation_to_image_bounds(image_width, image_height);
9797
}
9898
}
9999
}

src/toolbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,7 @@ export class SubmitButtons extends ToolboxItem {
25152515

25162516
// Ensure annotation is within the image if required
25172517
if (!ulabel.config.allow_annotations_outside_image) {
2518-
annotation.fit_to_image_bounds(
2518+
annotation.clamp_annotation_to_image_bounds(
25192519
ulabel.config["image_width"],
25202520
ulabel.config["image_height"],
25212521
);

0 commit comments

Comments
 (0)