Skip to content

Commit d898dea

Browse files
authored
Merge pull request #23 from philstopford/copilot/fix-3c84cf1c-a4fd-4920-a94a-c4754596cff0
Fix structural corruption in test_ellipse_polygon_shortedge/Program.cs
2 parents c605e6f + 8c9326f commit d898dea

File tree

1 file changed

+53
-23
lines changed
  • Prototyping/test_ellipse_polygon_shortedge

1 file changed

+53
-23
lines changed

Prototyping/test_ellipse_polygon_shortedge/Program.cs

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,21 @@ public static PathsD ProcessAllCornersWithShortEdgeHandling(List<PointD> origina
157157
return processed;
158158
}
159159

160+
/// <summary>
161+
/// Processes a corner with an adaptive radius, using the enhanced algorithm.
162+
/// </summary>
163+
/// <param name="startLine">Incoming edge definition</param>
164+
/// <param name="endLine">Outgoing edge definition</param>
165+
/// <param name="adaptiveRadius">Radius adjusted for edge constraints</param>
166+
/// <param name="angular_resolution">Angular sampling threshold</param>
167+
/// <param name="edge_resolution">Edge sampling density</param>
168+
/// <returns>Processed corner curve points</returns>
169+
public static PathD ProcessCornerWithAdaptiveRadius(PathD startLine, PathD endLine,
170+
double adaptiveRadius, double angular_resolution, double edge_resolution)
171+
{
172+
return processCorner(startLine, endLine, adaptiveRadius, angular_resolution, edge_resolution, SamplingMode.ByMaxSegmentLength);
173+
}
174+
160175
/// <summary>
161176
/// Computes an adaptive radius that respects edge length constraints.
162177
///
@@ -240,27 +255,8 @@ private static PathD CreateTangentLine(List<PointD> path, int cornerIndex, bool
240255
line.Add(midPoint);
241256
return line;
242257
}
243-
midPoint = new PointD((original_path[i].x + original_path[i + 1].x) * 0.5, (original_path[i].y + original_path[i + 1].y) * 0.5);
244-
endLine.Add(midPoint);
245258

246-
double radius = convex_radius;
247-
if (corner_types[i] == (int)types.concave)
248-
radius = concave_radius;
249-
250-
PathD current_corner = processCorner(startLine, endLine, radius, angular_resolution, edge_resolution, SamplingMode.ByMaxSegmentLength);
251-
processed.Add(current_corner);
252-
}
253-
254-
// Assemble, replacing runs of short-edge corners with diagonals
255-
PathD assembled = AssembleWithDiagonals(processed, corner_types);
256-
257-
// Write SVG for inspection
258-
string svg = BuildDetailedSvg(original_path, assembled);
259-
File.WriteAllText("assembled.svg", svg, Encoding.UTF8);
260-
Console.WriteLine("Wrote assembled.svg");
261-
}
262-
263-
static int[] categorizeCorners(PathD path_, double short_edge_length)
259+
static int[] CategorizeCorners(PathD path_, double short_edge_length)
264260
{
265261
int[] status = new int[path_.Count];
266262

@@ -298,13 +294,13 @@ static int[] categorizeCorners(PathD path_, double short_edge_length)
298294

299295
if (len1 <= short_edge_length && len2 <= short_edge_length)
300296
{
301-
status[i] = (int)types.shortedge;
297+
status[i] = (int)CornerType.ShortEdge;
302298
continue;
303299
}
304300

305301
double crossZ = vx1 * vy2 - vy1 * vx2;
306302
bool isVertexConvex = isCCW ? (crossZ > 0) : (crossZ < 0);
307-
status[i] = (int)(isVertexConvex ? types.convex : types.concave);
303+
status[i] = (int)(isVertexConvex ? CornerType.Convex : CornerType.Concave);
308304
}
309305

310306
if (trimmed_path)
@@ -437,7 +433,7 @@ static PathD AssembleWithDiagonals(PathsD processedCorners, int[] corner_types)
437433
// Mark short corners (only consider first n entries of corner_types)
438434
bool[] isShort = new bool[n];
439435
for (int k = 0; k < n; k++)
440-
isShort[k] = (k < corner_types.Length && corner_types[k] == (int)types.shortedge);
436+
isShort[k] = (k < corner_types.Length && corner_types[k] == (int)CornerType.ShortEdge);
441437

442438
int i = 0;
443439
while (i < n)
@@ -501,6 +497,40 @@ static PathD AssembleWithDiagonals(PathsD processedCorners, int[] corner_types)
501497
return outPts;
502498
}
503499

500+
/// <summary>
501+
/// Assembles processed corner curves into a single continuous path.
502+
/// </summary>
503+
/// <param name="processedCorners">List of processed corner curves</param>
504+
/// <returns>Assembled continuous path</returns>
505+
static PathD AssembleProcessedCorners(PathsD processedCorners)
506+
{
507+
PathD assembled = new PathD();
508+
509+
for (int i = 0; i < processedCorners.Count; i++)
510+
{
511+
PathD corner = processedCorners[i];
512+
if (corner.Count > 0)
513+
{
514+
if (assembled.Count == 0)
515+
{
516+
assembled.AddRange(corner);
517+
}
518+
else
519+
{
520+
// Avoid duplicating points at connections
521+
PointD last = assembled[^1];
522+
PointD first = corner[0];
523+
if (Math.Abs(last.x - first.x) < 1e-9 && Math.Abs(last.y - first.y) < 1e-9)
524+
assembled.AddRange(corner.Skip(1));
525+
else
526+
assembled.AddRange(corner);
527+
}
528+
}
529+
}
530+
531+
return assembled;
532+
}
533+
504534
// --- CSV & SVG Utilities ---
505535
static void WriteCsv(string path, PathD pts)
506536
{

0 commit comments

Comments
 (0)