Files
manual_wpf/NoteDetectionRefactor.md

2.7 KiB
Raw Permalink Blame History

Project: Refactor the NOTE Content Box Detection Algorithm

  1. High-Level Goal: The primary objective is to replace the current, fragile “horizontal search line” algorithm in Models/DwgDataExtractor.cs with a more robust and accurate method that reliably finds the content box for any “NOTE” text, regardless of its position or the composition of its bounding box.

  2. Core Strategy: “Vertical Ray-Casting” We will implement a new algorithm that emulates how a human would visually locate the content. This involves a “gradual downward scan” (or vertical ray-cast) from the NOTEs position.

  3. Implementation Plan (TODO List):

  • Step 1: Unify All Geometry into Line Segments

    • Create a single helper method, GetAllLineSegments, that processes all Line and Polyline entities from the drawing.
    • This method will decompose every Polyline into its constituent Line segments.
    • It will return a single, unified List containing every potential boundary segment in the drawing.
    • Crucially: This method must ensure all temporary Line objects created during the process are properly disposed of to prevent memory leaks.
  • Step 2: Implement the Ray-Casting Logic in FindNoteBox

    • The FindNoteBox method will be completely rewritten.
    • It will first call GetAllLineSegments to get the unified geometry list.
    • It will then perform the vertical ray-cast starting from the NOTEs X-coordinate and scanning downwards.
    • It will find all horizontal lines that intersect the ray and sort them by their Y-coordinate (from top to bottom).
    • It will identify the second line in this sorted list as the top edge of the content box (the first is assumed to be the NOTEs own bounding box).
  • Step 3: Implement Smart Box Tracing

    • Create a new helper method, TraceBoxFromTopLine.
    • This method will take the identified top line segment as its starting point.
    • It will intelligently trace the remaining three sides of the rectangle by searching the unified list of line segments for the nearest connecting corners.
    • This tracing logic must be tolerant of small gaps between the endpoints of the lines forming the box.
  • Step 4: Final Cleanup

    • Once the new ray-casting algorithm is fully implemented and validated, all of the old, obsolete methods related to the previous search-line approach must be deleted to keep the code clean. This includes:
      • FindIntersectingLineSegments
      • TraceRectangleFromLineSegments
      • FindNextConnectedLineSegment
      • DoesLineIntersectPolyline
      • GetPolylineBounds