Skip to content

Fix floor plan geometry rendering using proper RoomPlan data structures #9

@TangoEcho

Description

@TangoEcho

Problem

The floor plan rendering was showing irregular triangular/polygonal shapes instead of proper rectangular room boundaries. This was causing:

  • Assertion failures: 'boundaryCount > 1' failed
  • Malformed room shapes showing as irregular triangles
  • Coordinate misalignment between RoomPlan data and UI rendering
  • Complex geometry extraction that didn't follow Apple's intended RoomPlan usage

Root Cause

The original RoomAnalyzer.swift was attempting to reconstruct room geometry from individual wall segments instead of using Apple's CapturedRoom.Surface data directly. This led to:

  1. Over-complex wall analysis - Trying to connect individual wall segments into room boundaries
  2. Coordinate transformation issues - Manual calculations instead of using RoomPlan transforms
  3. Ignoring Apple's architecture - Not leveraging CapturedRoom.Surface polygons as intended

Solution

Completely rewrote RoomAnalyzer.swift to follow Apple's RoomPlan architecture:

Key Changes:

  1. Direct Surface Usage - Use CapturedRoom.Surface transform matrices and dimensions directly
  2. Simplified Geometry - Create room boundaries from surface data instead of reconstructing from walls
  3. Proper Transform Handling - Use RoomPlan's transform matrices for rotation and positioning
  4. Apple's Data Structures - Leverage doors, windows, openings arrays from RoomPlan

Technical Implementation:

// OLD: Complex wall reconstruction
let relevantWalls = capturedRoom.walls.filter { /* complex filtering */ }
let boundary = createOrderedRoomBoundary(walls: relevantWalls, ...)

// NEW: Direct surface usage
let center = extractSurfaceCenter(surface)
let dimensions = surface.dimensions
let transform = surface.transform
let rotation = atan2(transform.columns.0.z, transform.columns.0.x)
return corners.map { /* apply transform directly */ }

Benefits:

  • ✅ Proper rectangular room shapes
  • ✅ No more assertion failures
  • ✅ Follows Apple's intended RoomPlan usage
  • ✅ Simplified, maintainable code
  • ✅ Better coordinate alignment

Files Changed:

  • RoomPlanSimple/RoomAnalyzer.swift - Complete rewrite following Apple's architecture
  • Moved old implementation to RoomAnalyzer_Old.swift for reference

Testing:

  • App builds successfully
  • No assertion failures during geometry extraction
  • Need to test actual room rendering in simulator

Next Steps:

  • Test the simplified implementation with actual room scanning
  • Verify proper coordinate alignment with WiFi heatmap
  • Clean up any remaining geometry issues

This fix aligns the codebase with Apple's intended usage of RoomPlan as demonstrated in their documentation and WWDC sessions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions