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

Improved Persisting Placement #579

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

maurhofer-ubique
Copy link
Contributor

@maurhofer-ubique maurhofer-ubique commented Jan 24, 2024

Summary by CodeRabbit

  • New Features

    • Introduced an option to persist symbol placements on map layers, enhancing visual consistency.
  • Improvements

    • Improved collision detection logic for map symbols, allowing for more dynamic symbol placement and interaction.
  • Refactor

    • Streamlined handling of symbol object collisions for better performance and readability.
  • Bug Fixes

    • Adjusted symbol comparison logic to ensure correct ordering and visibility at different zoom levels.
  • Removed

    • Eliminated unused zoom level variables from map symbols to simplify the codebase.

Copy link
Contributor

coderabbitai bot commented Jan 24, 2024

Walkthrough

The codebase has undergone a series of updates primarily focused on collision detection functionality. A new alwaysInsert parameter has been added to constructors and methods to dictate whether objects should be inserted regardless of collisions. Return types and logic have been adjusted accordingly. Comparison logic in symbol objects has been simplified by removing certain conditions, and zoom-related logic has been streamlined with changes to method signatures and member variables.

Changes

File Path Change Summary
.../public/CollisionGrid.h Added alwaysInsert parameter to constructor; changed addAndCheckCollisionCircles return type to uint8_t; added private methods for rectangle and circle insertions.
.../vector/Tiled2dMapVectorLayer.cpp Included persistingPlacement parameter in update method's lambda for collisionManager.syncAccess.
.../vector/symbol/SymbolObjectCollisionWrapper.h Modified operator< method by removing isColliding and smallestVisibleZoom checks.
.../vector/symbol/...SymbolCollisionManager.cpp, ...SymbolCollisionManager.h Added persistingPlacement parameter to collisionDetection function and constructor call.
.../vector/symbol/...SymbolDataManager.cpp Simplified collisionDetection method by removing persistingPlacement conditional logic.
.../vector/symbol/Tiled2dMapVectorSymbolObject.cpp, Tiled2dMapVectorSymbolObject.h Revised collision checking approach in collisionDetection and removed smallestVisibleZoom and largestCollisionZoom variables; updated evaluateStyleProperties method signature.

🐇✨
In the realm of code, where the grid lines trace,
A rabbit hopped through, leaving changes in space.
With collisions and zooms, now sleek and concise,
The code rabbit's touch, a developer's delight. 🌟
🐇💻

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c185fae and 33b4ea9.
Files selected for processing (8)
  • shared/public/CollisionGrid.h (5 hunks)
  • shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/SymbolObjectCollisionWrapper.h (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolCollisionManager.cpp (2 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolCollisionManager.h (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1 hunks)
Files skipped from review due to trivial changes (1)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp
Additional comments: 11
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolCollisionManager.h (1)
  • 21-21: The addition of the persistingPlacement parameter to the collisionDetection method signature is consistent with the PR objectives to enhance object placement within the collision grid system.
shared/src/map/layers/tiled/vector/symbol/SymbolObjectCollisionWrapper.h (1)
  • 42-47: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [14-18]

The removal of conditional checks for isColliding and smallestVisibleZoom in the operator< method simplifies the comparison logic. Ensure that this change aligns with the intended collision logic and does not introduce any unintended side effects.

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolCollisionManager.cpp (1)
  • 11-17: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [14-24]

The collisionDetection function now correctly accepts the persistingPlacement parameter, and the CollisionGrid constructor has been updated accordingly. This change is in line with the PR's objectives.

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1)
  • 110-115: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [14-18]

The removal of smallestVisibleZoom and largestCollisionZoom and the addition of zoomIdentifier parameter in the evaluateStyleProperties method reflect a refactoring of zoom level management. Ensure that all references to these variables are updated to use the new parameter.

Verification successful

The search for the evaluateStyleProperties method signature in the codebase has produced output indicating that the method exists in two files and includes the zoomIdentifier parameter. This confirms that the zoomIdentifier parameter has been added to the evaluateStyleProperties method as intended.

Since there were no references found to the removed member variables smallestVisibleZoom and largestCollisionZoom, and the zoomIdentifier parameter is present in the method signatures, the changes mentioned in the review comment appear to have been correctly implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for any remaining references to the removed member variables.
rg "smallestVisibleZoom|largestCollisionZoom" --type cpp

Length of output: 58



Script:

#!/bin/bash
# Expand the search to include header files for the removed member variables.
rg "smallestVisibleZoom|largestCollisionZoom" --type cpp --type h

# Check for the correct implementation of the `zoomIdentifier` parameter in the `evaluateStyleProperties` method.
ast-grep --lang cpp --pattern 'method_definition[identifier="evaluateStyleProperties"] arguments: (parameter_list (parameter_declaration (declarator (identifier) @param)))' | rg "zoomIdentifier"

Length of output: 825



Script:

#!/bin/bash
# Correct the ast-grep pattern to properly search for the evaluateStyleProperties method and its parameters.
ast-grep --lang cpp --pattern 'method_definition[identifier="evaluateStyleProperties"] (parameter_list (parameter_declaration (declarator (identifier) @param)))' | rg "zoomIdentifier"

Length of output: 183



Script:

#!/bin/bash
# Use rg to search directly for the evaluateStyleProperties method signature in the codebase.
rg "void evaluateStyleProperties\(" --type cpp --type h

Length of output: 334

shared/public/CollisionGrid.h (5)
  • 52-56: The constructor of the CollisionGrid class has been updated to include the alwaysInsert parameter, which is consistent with the PR's objectives to control the insertion behavior based on collision status.
  • 103-106: The logic in addAndCheckCollisionAlignedRect has been restructured to handle the alwaysInsert parameter. Ensure that the new methods checkRectInsertAlways and checkRectInsertOnCollision are correctly implemented and tested.
  • 114-117: The addAndCheckCollisionCircles method's return type has been changed to uint8_t to accommodate multiple return states. This change should be reflected wherever the method is called.
Verification successful

The usage of addAndCheckCollisionCircles in Tiled2dMapVectorSymbolObject.cpp correctly handles the uint8_t return type by checking for specific return values and assigning them to boolean variables. This suggests that the change in the method's return type has been properly reflected in this instance.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for proper handling of the new return type.
rg "addAndCheckCollisionCircles" --type cpp

Length of output: 323



Script:

#!/bin/bash
# Inspect the usage of addAndCheckCollisionCircles in Tiled2dMapVectorSymbolObject.cpp
rg "addAndCheckCollisionCircles" shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp -C 5

Length of output: 629

* 159-163: The logic in `addAndCheckCollisionCircles` has been updated to handle the `alwaysInsert` parameter with new methods `checkCirclesInsertAlways` and `checkCirclesInsertOnCollision`. Verify that these methods are correctly implemented and tested. * 381-381: The `alwaysInsert` member variable has been added to the `CollisionGrid` class. Confirm that it is being used appropriately throughout the class.
Verification successful

The alwaysInsert variable is used within conditional statements to determine the behavior of the CollisionGrid class, specifically choosing between functions for insertion based on the state of alwaysInsert. This indicates that the variable is being used to control the flow of the program, which is consistent with the expected use of a boolean member variable in a class.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for the usage of the alwaysInsert variable.
rg "alwaysInsert" --type cpp

Length of output: 417



Script:

#!/bin/bash
# Extract the surrounding code for the conditional checks of the alwaysInsert variable.
rg -C 5 "if \(alwaysInsert\)" --type cpp

Length of output: 1281

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp (1)
  • 876-881: The collisionDetection method has been refactored to use a new variable check to store the result of collision checks and then determine the willCollide and outside flags based on this result. This change seems to be in line with the PR objectives to enhance collision detection logic.
shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp (1)
  • 564-569: The collisionManager.syncAccess lambda captures persistingPlacement from mapDescription->persistingSymbolPlacement. Ensure that mapDescription is valid and not null before accessing its member to avoid potential dereferencing of a null pointer.

@maurhofer-ubique maurhofer-ubique merged commit 88d6458 into develop Jan 24, 2024
2 checks passed
@maurhofer-ubique maurhofer-ubique deleted the feature/improved-persisting-placement branch January 24, 2024 16:51
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.

2 participants