//using System; //using System.Collections.Generic; //using System.Diagnostics; //using System.Linq; //using Teigha.Geometry; //using DwgExtractorManual.Models; //namespace DwgExtractorManual //{ // /// // /// 콘솔에서 실행할 수 있는 교차점 테스트 프로그램 // /// // class IntersectionTestConsole // { // static void Main(string[] args) // { // Console.WriteLine("=== 교차점 테스트 프로그램 시작 ==="); // try // { // RunSimpleIntersectionTest(); // } // catch (Exception ex) // { // Console.WriteLine($"오류 발생: {ex.Message}"); // Console.WriteLine(ex.StackTrace); // } // Console.WriteLine("테스트 완료. 아무 키나 누르세요..."); // Console.ReadKey(); // } // static void RunSimpleIntersectionTest() // { // Console.WriteLine("테스트 시작: 3x4 그리드 생성"); // // 간단한 3x4 테이블 시뮬레이션 (실제 DWG 없이) // var intersections = new List(); // // 수동으로 교차점 생성 (3행 x 4열 = 12개 교차점) // for (int row = 1; row <= 4; row++) // 4개 행 // { // for (int col = 1; col <= 5; col++) // 5개 열 // { // double x = (col - 1) * 10.0; // 0, 10, 20, 30, 40 // double y = (row - 1) * 10.0; // 0, 10, 20, 30 // int directionBits = CalculateDirectionBits(row, col, 4, 5); // var intersection = new IntersectionPoint // { // Position = new Point3d(x, y, 0), // DirectionBits = directionBits, // Row = row, // Column = col // }; // intersections.Add(intersection); // Console.WriteLine($"교차점 R{row}C{col}: ({x:F0},{y:F0}) - DirectionBits: {directionBits}"); // } // } // Console.WriteLine($"\n총 {intersections.Count}개 교차점 생성됨"); // // DirectionBits 검증 // TestDirectionBitsValidation(intersections); // // 셀 추출 시뮬레이션 // TestCellExtraction(intersections); // } // static int CalculateDirectionBits(int row, int col, int maxRow, int maxCol) // { // int bits = 0; // // Right: 1 - 오른쪽에 더 많은 열이 있으면 // if (col < maxCol) bits |= 1; // // Up: 2 - 위쪽에 더 많은 행이 있으면 // if (row < maxRow) bits |= 2; // // Left: 4 - 왼쪽에 열이 있으면 // if (col > 1) bits |= 4; // // Down: 8 - 아래쪽에 행이 있으면 // if (row > 1) bits |= 8; // return bits; // } // static void TestDirectionBitsValidation(List intersections) // { // Console.WriteLine("\n=== DirectionBits 검증 ==="); // var mappingData = new MappingTableData(); // var fieldMapper = new FieldMapper(mappingData); // var extractor = new DwgDataExtractor(fieldMapper); // foreach (var intersection in intersections) // { // bool isTopLeft = extractor.IsValidTopLeft(intersection.DirectionBits); // bool isBottomRight = extractor.IsValidBottomRight(intersection.DirectionBits); // Console.WriteLine($"R{intersection.Row}C{intersection.Column} (bits: {intersection.DirectionBits:D2}) - " + // $"TopLeft: {isTopLeft}, BottomRight: {isBottomRight}"); // } // } // static void TestCellExtraction(List intersections) // { // Console.WriteLine("\n=== 셀 추출 테스트 ==="); // var mappingData = new MappingTableData(); // var fieldMapper = new FieldMapper(mappingData); // var extractor = new DwgDataExtractor(fieldMapper); // // topLeft 후보들 찾기 // var topLeftCandidates = intersections.Where(i => extractor.IsValidTopLeft(i.DirectionBits)).ToList(); // Console.WriteLine($"TopLeft 후보: {topLeftCandidates.Count}개"); // foreach (var topLeft in topLeftCandidates) // { // Console.WriteLine($"\nTopLeft R{topLeft.Row}C{topLeft.Column} 처리 중..."); // // bottomRight 찾기 시뮬레이션 // var bottomRight = FindBottomRightSimulation(topLeft, intersections, extractor); // if (bottomRight != null) // { // Console.WriteLine($" -> BottomRight 발견: R{bottomRight.Row}C{bottomRight.Column}"); // Console.WriteLine($" 셀 생성: ({topLeft.Position.X:F0},{bottomRight.Position.Y:F0}) to ({bottomRight.Position.X:F0},{topLeft.Position.Y:F0})"); // } // else // { // Console.WriteLine(" -> BottomRight을 찾지 못함"); // } // } // } // static IntersectionPoint? FindBottomRightSimulation(IntersectionPoint topLeft, List intersections, DwgDataExtractor extractor) // { // // 교차점들을 Row/Column으로 딕셔너리 구성 // var intersectionLookup = intersections // .GroupBy(i => i.Row) // .ToDictionary(g => g.Key, g => g.ToDictionary(i => i.Column, i => i)); // int maxRow = intersectionLookup.Keys.Max(); // int maxColumn = intersectionLookup.Values.SelectMany(row => row.Keys).Max(); // for (int targetRow = topLeft.Row + 1; targetRow <= maxRow + 1; targetRow++) // { // if (!intersectionLookup.ContainsKey(targetRow)) continue; // var rowIntersections = intersectionLookup[targetRow]; // var availableColumns = rowIntersections.Keys.Where(col => col >= topLeft.Column).OrderBy(col => col); // foreach (int targetColumn in availableColumns) // { // var candidate = rowIntersections[targetColumn]; // // bottomRight 검증 또는 테이블 경계 조건 // if (extractor.IsValidBottomRight(candidate.DirectionBits) || // (targetRow == maxRow && targetColumn == maxColumn)) // { // return candidate; // } // } // } // return null; // } // } //}