From 107eab90fa18c777a79418d97e40405cff6c91e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=8A=B9=EC=9A=B0=EC=9A=B0?= Date: Thu, 31 Jul 2025 10:29:56 +0900 Subject: [PATCH] NoteDetectionRefactor plan --- NoteDetectionRefactor.md | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 NoteDetectionRefactor.md diff --git a/NoteDetectionRefactor.md b/NoteDetectionRefactor.md new file mode 100644 index 0000000..eecabc7 --- /dev/null +++ b/NoteDetectionRefactor.md @@ -0,0 +1,48 @@ +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 NOTE's 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 NOTE's 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 NOTE's 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 \ No newline at end of file