Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support backward and forward snapping lines. #5811

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mohsenD98
Copy link
Collaborator

@mohsenD98 mohsenD98 commented Nov 13, 2024

PR Description:

This PR introduces support for the backward snapping feature, allowing snapping to common angles both backward (to the starting point) and forward (last digitized point).

How We Achieved This

  1. Replacing Shape with Repeater for Snapping Lines: Instead of using a static Shape {} element, we now use a Repeater {} with dynamic model data to display the snapping lines. This approach provides flexibility and allows for more efficient handling of multiple snapping lines.

Props of each list element:

ListElement {
  beginCoordX: 0
  beginCoordY: 0
  endCoordX: 0
  endCoordY: 0
  snappedToAngle: false
}

The snapping line is only visible if snappedToAngle is true or if valid endCoords are provided.

  1. Adding the forwardMode Parameter: We introduced a forwardMode parameter to three key functions:
  • calculateSnapToAngleLineEndCoords
  • snapPointToCommonAngle
  • getCommonAngleInDegrees

The forwardMode parameter helps determine the direction of the snapping line by defining a targetPoint in each of these functions. This ensures that snapping lines are correctly oriented, whether snapping forward or backward.

  1. Handling Both Forward and Backward Snapping: When both forward and backward snapping lines are present, we handle the intersection of these lines to ensure accurate snapping behavior in both directions.

Demo

You can view the feature in action in the following screencast:

Screencast.from.2024-11-14.12-39-27.webm

@mohsenD98 mohsenD98 requested a review from nirvn November 13, 2024 14:44
@mohsenD98 mohsenD98 self-assigned this Nov 13, 2024
@qfield-fairy
Copy link
Collaborator

qfield-fairy commented Nov 13, 2024

Comment on lines 491 to +492
// if the angle is null or undefined, return empty coordinate map
if (angleDegrees == null) {
if (angleDegrees === null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is dangerous unless you fix the comment above. == null will check for both null and undefined, now only checks for null.

@nirvn nirvn closed this Nov 14, 2024
@nirvn nirvn reopened this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants