Boundary trace (seed point)
Click-a-point boundary detection: two overlapping rectangles are split at their crossings and CadAddBoundary / CadAddBoundPolygon returns the minimal region enclosing the seed.
// Seed-point boundary: two overlapping rectangles; the tracer must split the // edges at their crossings and return the minimal face around the seed. static void feat_boundary(bool filled) { samp_clear(); feat_rect_lines(0, 0, 60, 40); feat_rect_lines(30, 20, 90, 70); const double sx = 45, sy = 30; // seed inside the overlap int h = filled ? CadAddBoundPolygon(g_hDwg, sx, sy, 0) : CadAddBoundary(g_hDwg, sx, sy, 0); if (h) CadEntityPutColor(h, CAD_COLOR_RED); int mark = CadAddCircle(g_hDwg, sx, sy, 0, 1.2); // show the seed CadEntityPutColor(mark, CAD_COLOR_YELLOW); CadUpdate(g_hDwg); samp_zoom_ext(); set_status(h ? (filled ? L"CadAddBoundPolygon: filled minimal region around the seed (red)" : L"CadAddBoundary: traced contour around the seed (red)") : L"Boundary trace FAILED (seed not enclosed?)"); }
1, 2: // Boundary / BoundPolygon begin CadPurge(FhDwg, CAD_CLEAR_ENTITIES); FeatRectLines(0, 0, 60, 40); // two overlapping rectangles: FeatRectLines(30, 20, 90, 70); // edges split at crossings if TMenuItem(Sender).Tag = 2 then h := CadAddBoundPolygon(FhDwg, 45, 30, 0) else h := CadAddBoundary(FhDwg, 45, 30, 0); if h <> 0 then CadEntityPutColor(h, CAD_COLOR_RED); m := CadAddCircle(FhDwg, 45, 30, 0, 1.2); // show the seed CadEntityPutColor(m, CAD_COLOR_YELLOW); CadUpdate(FhDwg); CadExecute(FhDwg, FCadHwnd, CAD_CMD_ZOOM_EXT); if h <> 0 then StatusBar.SimpleText := 'CadAddBoundary/BoundPolygon: minimal region around the seed (red)' else StatusBar.SimpleText := 'Boundary trace FAILED (seed not enclosed?)'; end;
private void FeatBoundary(bool filled) { SampleClear(); FeatRectLines(0, 0, 60, 40); // two overlapping rectangles: the FeatRectLines(30, 20, 90, 70); // tracer splits edges at crossings const double sx = 45, sy = 30; // seed inside the overlap var h = filled ? YuCadApi.CadAddBoundPolygon(_hDwg, sx, sy, 0) : YuCadApi.CadAddBoundary(_hDwg, sx, sy, 0); if (h != 0) YuCadApi.CadEntityPutColor(h, YuCadApi.CAD_COLOR_RED); var mark = YuCadApi.CadAddCircle(_hDwg, sx, sy, 0, 1.2); YuCadApi.CadEntityPutColor(mark, YuCadApi.CAD_COLOR_YELLOW); YuCadApi.CadUpdate(_hDwg); SampleZoomExt(); SetStatus(h != 0 ? (filled ? "CadAddBoundPolygon: filled minimal region around the seed (red)" : "CadAddBoundary: traced contour around the seed (red)") : "Boundary trace FAILED (seed not enclosed?)"); }
This code is extracted verbatim from the shipped demo hosts (
examples/cpp, examples/delphi, examples/csharp) — run the matching menu item there to see it live.