Editor Utilities
Vergeo2D.Mesh includes small editor-facing helpers for tool UIs, import validation, and interactive mesh editing. These helpers do not depend on a windowing or graphics library.
Mesh Validation
Section titled “Mesh Validation”Use mesh.Validate() or MeshValidator2D.Validate() before accepting imported meshes, generated meshes, or user-edited topology.
var result = mesh.Validate();
if (!result.IsValid){ foreach (var issue in result.Issues) Console.WriteLine(issue);}MeshValidationResult2D exposes:
| Member | Purpose |
|---|---|
Issues |
Ordered diagnostics returned by the validator. |
IsValid |
true when no error-level issues were reported. |
HasErrors |
true when at least one issue has Error severity. |
HasWarnings |
true when at least one issue has Warning severity. |
Validation Issues
Section titled “Validation Issues”Each MeshValidationIssue2D includes a severity, code, message, and optional location fields.
| Member | Purpose |
|---|---|
Severity |
Warning or Error. |
Code |
Stable diagnostic code for UI filtering. |
Message |
Human-readable message. |
VertexIndex |
Related vertex index, or -1. |
FaceIndex |
Related face index, or -1. |
Edge |
Related Edge2D, when applicable. |
Validator codes include:
| Code | Meaning |
|---|---|
FaceIndexOutOfRange |
A face references a missing vertex. |
DegenerateFace |
A face references the same vertex more than once. |
SmallTriangle |
A triangle area is below the configured threshold. |
DuplicateFace |
A face duplicates another face’s vertex set. |
OrphanVertex |
A vertex is not referenced by any face. |
NonManifoldEdge |
More than two faces share the same edge. |
InconsistentWinding |
Two faces use a shared edge in the same direction. |
Validation Options
Section titled “Validation Options”Use MeshValidationOptions2D to tune what gets reported.
var result = MeshValidator2D.Validate(mesh, new MeshValidationOptions2D{ MinimumTriangleArea = 0.01f, ReportOrphanVertices = false});| Option | Purpose |
|---|---|
MinimumTriangleArea |
Area threshold used for SmallTriangle warnings. |
ReportDuplicateFaces |
Enables duplicate face diagnostics. |
ReportOrphanVertices |
Enables unused vertex diagnostics. |
ReportNonManifoldEdges |
Enables edge sharing diagnostics. |
ReportInconsistentWinding |
Enables shared-edge winding diagnostics. |
Vertex Picking
Section titled “Vertex Picking”Use MeshPicking2D.FindNearestVertex() for drag handles or vertex selection.
if (MeshPicking2D.FindNearestVertex(mesh, mousePosition, 12f, out var vertexIndex, out var distanceSquared)){ mesh.Vertices[vertexIndex].Position += dragOffset;}maxDistance is in mesh/content coordinates, not screen pixels. Convert screen coordinates first if your editor has pan or zoom.
Edge Picking
Section titled “Edge Picking”Use FindNearestEdge() for edge selection or insert tools.
if (MeshPicking2D.FindNearestEdge(mesh, mousePosition, 8f, out var edge, out var closest, out _)){ // Select edge, show a handle at closest, or split the edge.}The helper ignores stale edges whose vertex indices are outside the mesh vertex range.
Face Barycentric And UV Lookup
Section titled “Face Barycentric And UV Lookup”Use barycentric coordinates when an editor needs interpolation inside a triangle.
var faceIndex = mesh.FindFaceAt(mousePosition);
if (faceIndex >= 0 && MeshPicking2D.TryGetFaceBarycentric(mesh, faceIndex, mousePosition, out var barycentric)){ Console.WriteLine(barycentric);}Use TryGetFaceUV() when a tool needs the interpolated texture coordinate under the cursor:
if (faceIndex >= 0 && MeshPicking2D.TryGetFaceUV(mesh, faceIndex, mousePosition, out var uv)){ var pixel = mesh.Texture?.UVToPixel(uv);}Both helpers return false for invalid face indices, invalid face vertex indices, and degenerate triangles.