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

feat: add OrientableSurface struct and parsing logic for enhanced geometry handling #34

Merged
merged 4 commits into from
Nov 27, 2024

Conversation

miseyu
Copy link
Collaborator

@miseyu miseyu commented Nov 27, 2024

Summary by CodeRabbit

  • New Features

    • Introduced support for OrientableSurface in geometry handling, enhancing complex geometric representations.
    • Added new attributes to the UndergroundBuilding structure, improving data capture for building quality, disaster risk, and facilities.
  • Bug Fixes

    • Improved error handling and parsing logic for various geometry types, ensuring clearer error messages and more robust functionality.

@miseyu miseyu self-assigned this Nov 27, 2024
Copy link

coderabbitai bot commented Nov 27, 2024

Walkthrough

The pull request introduces several enhancements across multiple files, focusing on the handling of geometric data and underground building attributes. Key changes include the addition of a new struct OrientableSurface and its integration into the GeometryStore and GeometryCollector structures. The parsing logic for OrientableSurface is also updated to improve geometry parsing. Additionally, numerous fields are added to the UndergroundBuilding struct to accommodate various attributes related to building quality, disaster risk, and facilities.

Changes

File Path Change Summary
nusamai-citygml/src/geometry.rs - New struct: OrientableSurface
- Added field: pub orientable_surfaces: Vec<OrientableSurface> in GeometryStore
- Added field: pub orientable_surfaces: Vec<OrientableSurface> in GeometryCollector
- Modified into_geometries method to include orientable_surfaces.
nusamai-citygml/src/parser.rs - Added struct: OrientableSurface
- Added method: fn parse_orientable_surface(&mut self) -> Result<Option<LocalId>, ParseError> in CityGmlReader
- Updated parse_geometry_prop and parse_surface functions for OrientableSurface.
- Improved error handling in parsing functions.
nusamai-plateau/src/models/iur/uro/underground_building.rs - Added multiple fields to UndergroundBuilding struct, including attributes for quality, disaster risk, and facilities.

Possibly related PRs

🐰 In the geometry's embrace,
New surfaces find their place.
With attributes rich and bright,
Buildings stand in shared delight.
Parsing paths now clear and true,
A world of shapes, fresh and new! 🌍✨


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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (12)
nusamai-citygml/src/geometry.rs (2)

96-101: Add documentation comments to explain the OrientableSurface struct.

While the struct is well-designed, it would benefit from documentation comments explaining:

  • The purpose and use case of OrientableSurface
  • The significance of the reverse field
  • Any constraints or invariants that must be maintained

Add documentation like this:

 #[derive(Debug, Clone)]
 #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
+/// Represents a surface that can be oriented in 3D space.
+/// 
+/// # Fields
+/// * `surface_id` - Reference to the base surface being oriented
+/// * `reverse` - When true, indicates that the surface orientation should be reversed
 pub struct OrientableSurface {
     pub surface_id: LocalId,
     pub reverse: bool,
 }

121-122: Maintain documentation consistency across structs.

The orientable_surfaces field in GeometryCollector should have the same level of documentation as its counterpart in GeometryStore for consistency.

Add documentation like this:

     /// Lists of surface for composite surface
     pub composite_surfaces: Vec<LocalId>,

+    /// Orientable surfaces for each surface
     pub orientable_surfaces: Vec<OrientableSurface>,
nusamai-plateau/src/models/iur/uro/underground_building.rs (1)

Line range hint 59-89: Consider adding documentation for the new attributes

While the field names and types are clear, adding documentation comments would help users understand:

  • The purpose and expected values for each attribute
  • The relationship between fields with dual CityGML paths
  • The meaning of the Property-suffixed types and their relationships

Example documentation format:

/// Represents the quality attributes of building data.
/// 
/// # CityGML Paths
/// - `uro:buildingDataQualityAttribute/uro:BuildingDataQualityAttribute` (new format)
/// - `uro:bldgDataQualityAttribute/uro:DataQualityAttribute` (legacy format)
#[citygml(path = b"uro:buildingDataQualityAttribute/uro:BuildingDataQualityAttribute")]
#[citygml(path = b"uro:bldgDataQualityAttribute/uro:DataQualityAttribute")]
pub bldg_data_quality_attribute: Option<uro::DataQualityAttribute>,
nusamai-citygml/src/parser.rs (9)

753-753: Improve error message clarity in parse_triangulated_prop

The error message "Unexpected element <{}> by parse triangulated prop" can be enhanced for better readability. Consider rephrasing it to:

-"Unexpected element <{}> by parse triangulated prop",
+"Unexpected element <{}> while parsing triangulated property",

817-817: Enhance error message in parse_triangle_patch_array

The error message "Unexpected element <{}> by parsing triangle patch array" is slightly unclear. Rewriting it improves clarity:

-"Unexpected element <{}> by parsing triangle patch array",
+"Unexpected element <{}> while parsing triangle patch array",

846-850: Clarify error message in parse_multi_surface

The error message "Unexpected element. Because only surface member" can be made more precise:

-"Unexpected element. Because only surface member".into(),
+"Unexpected element: expected 'surfaceMember' element".into(),

889-889: Refine error message in parse_composite_surface

To enhance understanding, modify the error message to:

-"Unexpected element <{}> by parsing composite surface",
+"Unexpected element <{}> while parsing composite surface",

945-965: Refactor duplicated code for parsing OrientableSurface

The logic for parsing the OrientableSurface and handling the orientation attribute is duplicated in multiple places (lines 642-664 and 945-965). Refactoring this into a helper function enhances code maintainability and reduces duplication.

Apply this diff to extract the common logic:

+fn parse_orientation_attribute(&mut self, start: &BytesStart) -> Result<String, ParseError> {
+    let mut orientation = "+".to_string();
+    for attr in start.attributes().flatten() {
+        let (_, localname) = self.reader.resolve_attribute(attr.key);
+        if localname.as_ref() == b"orientation" {
+            let value = String::from_utf8_lossy(attr.value.as_ref()).to_string();
+            orientation = value;
+            break;
+        }
+    }
+    if orientation != "+" && orientation != "-" {
+        return Err(ParseError::InvalidValue(format!("Invalid orientation value: {}", orientation)));
+    }
+    Ok(orientation)
+}

Then replace the duplicated code with:

-let mut orientation = "+".to_string();
-for attr in start.attributes().flatten() {
-    let (_, localname) = self.reader.resolve_attribute(attr.key);
-    if localname.as_ref() == b"orientation" {
-        let value = String::from_utf8_lossy(attr.value.as_ref()).to_string();
-        orientation = value;
-        break;
-    }
-}
+let orientation = self.parse_orientation_attribute(&start)?;

973-973: Improve error message in parse_surface

To make the error message clearer, consider:

-"Unexpected element <{}> by parsing surface",
+"Unexpected element <{}> while parsing surface",

1025-1028: Clarify error message in parse_orientable_surface

The error message "Unexpected element. Because only base surface" can be made more precise:

-"Unexpected element. Because only base surface".into(),
+"Unexpected element: expected only 'baseSurface' element".into(),

1232-1232: Correct singular form in error message

The message "Unexpected elements <{}> inside <app:textureCoordinates>" should use the singular form to refer to a single element:

-"Unexpected elements <{}> inside <app:textureCoordinates>",
+"Unexpected element <{}> inside <app:textureCoordinates>",

1258-1258: Adjust error message in parse_tex_coord_list

For clarity and correctness, modify the error message to:

-"Unexpected elements <{}> inside <app:TexCoordList>",
+"Unexpected element <{}> inside <app:TexCoordList>",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fc85edd and c7c5237.

📒 Files selected for processing (3)
  • nusamai-citygml/src/geometry.rs (4 hunks)
  • nusamai-citygml/src/parser.rs (11 hunks)
  • nusamai-plateau/src/models/iur/uro/underground_building.rs (1 hunks)
🔇 Additional comments (3)
nusamai-citygml/src/geometry.rs (1)

184-184: 🛠️ Refactor suggestion

Verify surface_id references during geometry conversion.

The into_geometries method should validate that all surface_id references in orientable_surfaces point to valid surfaces in surface_spans to maintain data integrity.

Let's verify the surface references:

Consider adding validation like this:

// Add before constructing GeometryStore
for orientable in &self.orientable_surfaces {
    if !self.surface_spans.iter().any(|span| span.id == orientable.surface_id) {
        return Err(format!("Invalid surface reference: {:?}", orientable.surface_id));
    }
}
nusamai-plateau/src/models/iur/uro/underground_building.rs (1)

Line range hint 93-143: Verify surface mapping compatibility with OrientableSurface

Given that this PR introduces OrientableSurface handling, we should verify if UNDERGROUND_BUILDING_SURFACE_MAPPINGS needs to be updated to handle this new surface type.

nusamai-citygml/src/parser.rs (1)

21-21: Import of OrientableSurface is appropriate

The addition of OrientableSurface to the imports aligns with the new functionality introduced and is correctly placed.

@miseyu miseyu merged commit 1864e75 into main Nov 27, 2024
1 check passed
@miseyu miseyu deleted the feature/add-orientable-surface branch November 27, 2024 03:56
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.

1 participant