Skip to content

Commit

Permalink
Recalculate only the row that changed for now
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorBurgoyne committed Sep 20, 2024
1 parent 4ca084a commit 7b2d1bc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 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.

4 changes: 4 additions & 0 deletions src/annotation_operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ export function assign_distance_from_line(

// Create a DistanceFrom object to be assigned to this point
let distance_from: AnnotationClassDistanceData = {"single": undefined}
// Use the existing distance_from if it exists
if (current_point.distance_from !== undefined) {
distance_from = current_point.distance_from
}

// Calculate the distance from each line and populate the distance_from accordingly
line_annotations.forEach(current_line => {
Expand Down
61 changes: 37 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1518,33 +1518,46 @@ export class ULabel {
*
* @param {string} annotation_id - The annotation id of the annotation that changed
* @param {boolean} redraw_update_items - If true, redraw the toolbox items
* @param {boolean} force_filter - If true, force the filter to occur without checking the annotation type (used if annotation no longer exists)
* @param {boolean} force_filter_all - If true, force the filter to occur using all polylines
* @param {object} offset - The offset (for polyline moves)
*/
update_filter_distance(annotation_id, redraw_update_items = true, force_filter = false, offset = null) {
update_filter_distance(annotation_id, redraw_update_items = true, force_filter_all = false, offset = null) {
// First verify if the FilterDistance toolbox item is active
if (this.toolbox_order.includes(AllowedToolboxItem.FilterDistance)) {
// Then verify if the annotation is a polyline
if (
force_filter ||
this.subtasks[this.state["current_subtask"]].annotations.access[annotation_id].spatial_type === "polyline"
) {
// Add id to the offset
if (offset !== null) {
offset["id"] = annotation_id;
}
// Filter all points
filter_points_distance_from_line(this, true, offset);
// Add id to the offset
if (offset !== null) {
offset["id"] = annotation_id;
}

// Lastly, redraw the toolbox items if necessary
if (redraw_update_items) {
this.toolbox.redraw_update_items(this);
if (force_filter_all) {
// Filter all points from all lines
filter_points_distance_from_line(this, true, offset);
} else if (annotation_id in this.subtasks[this.state["current_subtask"]].annotations.access) {
// Update based on changes to a single polyline or point
let points_and_lines;
const annotation = this.subtasks[this.state["current_subtask"]].annotations.access[annotation_id];
switch (annotation.spatial_type) {
case "polyline":
// Update each point's distance to THIS polyline
points_and_lines = get_point_and_line_annotations(this);
assign_distance_from_line(points_and_lines[0], [annotation]);
// Filter all points from the updated line
filter_points_distance_from_line(this, false, offset);
break;
case "point":
// Update THIS point's distance to the nearest lines
points_and_lines = get_point_and_line_annotations(this);
assign_distance_from_line([annotation], points_and_lines[1]);
// Don't filter the point yet, since that may be unexpected for the user
break;
default:
break;
}
} 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]);
}

// Lastly, redraw the toolbox items if necessary
if (redraw_update_items) {
this.toolbox.redraw_update_items(this);
}
}
}
Expand All @@ -1555,12 +1568,12 @@ export class ULabel {
*
* @param {string} annotation_id - The annotation id of the annotation that changed
* @param {boolean} redraw_update_items - If true, redraw the toolbox items
* @param {boolean} force_filter - If true, force the filter to occur without checking the annotation type (used if annotation no longer exists)
* @param {boolean} force_filter_all - If true, force the filter to occur without checking the annotation type (used if annotation no longer exists)
* @param {object} offset - The offset (for polyline moves)
*/
update_filter_distance_during_polyline_move(annotation_id, redraw_update_items = true, force_filter = false, offset = null) {
update_filter_distance_during_polyline_move(annotation_id, redraw_update_items = true, force_filter_all = false, offset = null) {
if (this.config.distance_filter_toolbox_item.filter_during_polyline_move) {
this.update_filter_distance(annotation_id, redraw_update_items, force_filter, offset);
this.update_filter_distance(annotation_id, redraw_update_items, force_filter_all, offset);
}
}

Expand Down

0 comments on commit 7b2d1bc

Please sign in to comment.