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

RoadLane offset approx algorithm #155

Merged
merged 3 commits into from
Feb 21, 2024
Merged

RoadLane offset approx algorithm #155

merged 3 commits into from
Feb 21, 2024

Conversation

bdog2112
Copy link
Collaborator

Curve offsets are nicely drawn. However, something must be done about Lane Transitions. They plot perfectly fine. But, the IDE freezes when the "+Next RoadPoint" and "+Prior RoadPoint" buttons are used. Said buttons don't freeze the IDE when there are no Lane Transitions.

@bdog2112 bdog2112 changed the base branch from main to dev February 17, 2024 16:13
@TheDuckCow TheDuckCow linked an issue Feb 18, 2024 that may be closed by this pull request
@TheDuckCow
Copy link
Owner

Thanks for making the PR, see my response here - if it is just due to small/0-angle continuity, perhaps we can do some very light check to see if the angles are so small that we can forgo the approximation altogether. Just an idea

@bdog2112
Copy link
Collaborator Author

The latest update fixes the IDE freezing issue and it should also fix problems where RoadLanes doubled back on themselves. It is believed that both issues were caused by the projected angles being too close to 90 degrees, which can result in point positions that are too large.

One way to re-create the problem scenario is to simply add a new RoadPoint using the buttons in the Inspector panel. The default distance and handle values are such that the resulting segment's prev and next mag handles are very close to overlapping and it doesn't take much to move them into a 90 degree orientation with one another.

Validation logic was added to see if the handles were close to 90 degrees. If the angle is 90 degrees +/- a certain "margin", then the old handle projection method is used. Otherwise, the new algorithm is used. Currently, the margin is set to 10 degrees, which prevents exceedingly high point values. But, the margin can always be increased, if needed.

@bdog2112
Copy link
Collaborator Author

Oh, and Transition Lanes should work fine!

@TheDuckCow
Copy link
Owner

Great, this is working well on my side, thanks for the quick work to address this. Do you see any outstanding work on this one @bdog2112? Feel free to flip to ready for review and add me once you do.

@bdog2112
Copy link
Collaborator Author

These changes are ready to go.

Ran GUT and 1 test failed. Traced the history of the test failure back to checkin ed79d21. All tests passed prior to that checkin. Failure doesn't appear to be related to this PR.

@TheDuckCow TheDuckCow changed the title 46 update roadsegments RoadLane offset approx algorithm Feb 20, 2024
@TheDuckCow TheDuckCow marked this pull request as ready for review February 20, 2024 01:04
@TheDuckCow
Copy link
Owner

Thanks @bdog2112, yup I'm aware of that failing test in my other PR as well, I'll take care of that one when I have a moment. Will mark this as review ready and see if I have any comments to add.

Copy link
Owner

@TheDuckCow TheDuckCow left a comment

Choose a reason for hiding this comment

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

Approving this - made two comments, but I can make the quick change and then aim to merge this shortly. Tested out in Wheel Steal, and appears to work as needed. Nice work!

var offset_s = tan(angle_s) * out_offset
var pt_f = a_gbasis.z * (vec_ab.length() + offset_q)
var pt_g = -d_gbasis.z * (vec_cd.length() + offset_s)
var rad_ninety_deg = 1.5707963267949 # 90 degrees in radians
Copy link
Owner

Choose a reason for hiding this comment

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

May as well do something like this, I think it'll be faster on runtime anyways and more exact potentially

Suggested change
var rad_ninety_deg = 1.5707963267949 # 90 degrees in radians
const rad_ninety_deg := PI/2 # 90 degrees in radians

# and distance.
func offset_curve(road_seg: Spatial, road_lane: Path, in_offset: float, out_offset: float, rp0: Spatial, rp1: Spatial):

var src = road_seg.curve
Copy link
Owner

Choose a reason for hiding this comment

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

In general here and below, would suggest implied typing or explicit where required. This is a somewhat heavy process and so having type hints will help godot make the more efficient compile choices.

Suggested change
var src = road_seg.curve
var src := road_seg.curve

@TheDuckCow TheDuckCow merged commit 6a4dc09 into dev Feb 21, 2024
@TheDuckCow TheDuckCow deleted the 46-update-roadsegments branch February 21, 2024 07:23
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.

Update LaneSegments for multi-lane highly curvy roads
2 participants