Skip to content

Commit

Permalink
Update a single point's distance when edited
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorBurgoyne committed Sep 20, 2024
1 parent bbb6069 commit cafccb4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dist/ulabel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ulabel.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/annotation_operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export function get_point_and_line_annotations(ulabel: ULabel): [ULabelAnnotatio
* from a polyline annotation.
*
* @param ulabel ULabel object
* @param recalculate_distances whether to recalculate the distance from each point to the nearest line
* @param offset Offset of a particular annotation. Used when filter is called while an annotation is being moved
* @param override Used to filter annotations without calling the dom
*/
Expand Down
38 changes: 19 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import {
} from '../build/configuration';
import { get_gradient } from '../build/drawing_utilities'
import {
assign_distance_from_line,
filter_points_distance_from_line,
get_annotation_class_id,
get_annotation_confidence,
get_point_and_line_annotations,
mark_deprecated
} from '../build/annotation_operators';
import {
Expand Down Expand Up @@ -1524,7 +1526,7 @@ export class ULabel {
// Then verify if the annotation is a polyline
if (
force_filter ||
this.subtasks[this.state["current_subtask"]].annotations.access[annotation_id].spatial_type
this.subtasks[this.state["current_subtask"]].annotations.access[annotation_id].spatial_type === "polyline"
) {
// Filter all points
filter_points_distance_from_line(this, true);
Expand All @@ -1533,6 +1535,11 @@ export class ULabel {
if (redraw_update_items) {
this.toolbox.redraw_update_items(this);
}
} else if (this.subtasks[this.state["current_subtask"]].annotations.access[annotation_id].spatial_type === "point") {
// Update the point's distance to the nearest lines
const point = this.subtasks[this.state["current_subtask"]].annotations.access[annotation_id];
const points_and_lines = get_point_and_line_annotations(this);
assign_distance_from_line([point], points_and_lines[1]);
}
}
}
Expand Down Expand Up @@ -3044,7 +3051,6 @@ export class ULabel {
layer_idx: layer_idx,
}
}, redoing);

}
}
// Redraw when caller expects the annotation to be redrawn
Expand Down Expand Up @@ -5249,14 +5255,6 @@ export class ULabel {
this.redraw_annotation(actid);
this.suggest_edits(this.state["last_move"]);
break;
case "polyline":
this.set_with_access_string(actid, redo_payload.edit_candidate["access"], ms_loc, false);
this.rebuild_containing_box(actid);
this.redraw_annotation(actid);
this.suggest_edits(this.state["last_move"]);
// Filter points if necessary
this.update_filter_distance(actid);
break;
default:
this.set_with_access_string(actid, redo_payload.edit_candidate["access"], ms_loc, false);
this.rebuild_containing_box(actid);
Expand All @@ -5265,6 +5263,9 @@ export class ULabel {
break;

}
// Filter points if necessary
this.update_filter_distance(actid);

let frame = this.state["current_frame"];
if (MODES_3D.includes(spatial_type)) {
frame = null;
Expand Down Expand Up @@ -5518,9 +5519,6 @@ export class ULabel {
// Redraw annotation and record action
this.redraw_annotation(active_id);
record_action = true;

// Filter points if necessary
this.update_filter_distance(active_id, false);
break;
case "delete_bbox":
this.record_finish(active_id);
Expand Down Expand Up @@ -5609,6 +5607,8 @@ export class ULabel {
current_subtask["state"]["is_in_progress"] = false;
}

// Filter points if necessary
this.update_filter_distance(active_id, false);
this.toolbox.redraw_update_items(this);
}

Expand Down Expand Up @@ -5670,9 +5670,6 @@ export class ULabel {
}
break;
case "polyline":
// Filter points if necessary
this.update_filter_distance(actid);
break;
case "bbox":
case "bbox3":
case "tbar":
Expand All @@ -5688,6 +5685,9 @@ export class ULabel {
// Set mode to no active annotation
this.subtasks[this.state["current_subtask"]]["state"]["active_id"] = null;
this.subtasks[this.state["current_subtask"]]["state"]["is_in_edit"] = false;

// Filter points if necessary
this.update_filter_distance(actid);
}

move_annotation(mouse_event) {
Expand Down Expand Up @@ -5757,9 +5757,6 @@ export class ULabel {

switch (spatial_type) {
case "polyline":
// Filter points if necessary
this.update_filter_distance(active_id);
break;
case "polygon":
case "bbox":
case "bbox3":
Expand All @@ -5777,6 +5774,9 @@ export class ULabel {
this.redraw_annotation(active_id);

this.record_finish_move(diffX, diffY, diffZ);

// Filter points if necessary
this.update_filter_distance(active_id);
}

move_annotation__undo(undo_payload) {
Expand Down

0 comments on commit cafccb4

Please sign in to comment.