| 252 | } |
| 253 | |
| 254 | void addPoint(Vec2f vtx) |
| 255 | { |
| 256 | s32 vtxIndex = (s32)s_vertices.size(); |
| 257 | s_vertices.push_back(vtx); |
| 258 | |
| 259 | const size_t count = s_triangles.size(); |
| 260 | Triangle* tri = s_triangles.data(); |
| 261 | s_edges.clear(); |
| 262 | |
| 263 | f32 smallestDiff = FLT_MAX; |
| 264 | for (size_t t = 0; t < count; t++, tri++) |
| 265 | { |
| 266 | if (!tri->allocated) { continue; } |
| 267 | |
| 268 | // Is the point inside the circumcircle? |
| 269 | const Vec2f offset = { vtx.x - tri->circle.x, vtx.z - tri->circle.z }; |
| 270 | const f32 distSq = offset.x*offset.x + offset.z*offset.z; |
| 271 | |
| 272 | const f32 diff = fabsf(distSq - tri->radiusSq); |
| 273 | smallestDiff = std::min(smallestDiff, diff); |
| 274 | |
| 275 | if (distSq <= tri->radiusSq + eps) |
| 276 | { |
| 277 | // Add triangle edges for later processing. |
| 278 | addEdge(tri->idx[0], tri->idx[1]); |
| 279 | addEdge(tri->idx[1], tri->idx[2]); |
| 280 | addEdge(tri->idx[2], tri->idx[0]); |
| 281 | // Delete the parent triangle. |
| 282 | deleteTriangle(tri); |
| 283 | } |
| 284 | } |
| 285 | PolyAssert(!s_edges.empty()); |
| 286 | |
| 287 | // Fix up triangle adjacency. |
| 288 | tri = s_triangles.data(); |
| 289 | for (size_t t = 0; t < count; t++, tri++) |
| 290 | { |
| 291 | if (!tri->allocated) { continue; } |
| 292 | if (tri->adj[0] >= 0 && !s_triangles[tri->adj[0]].allocated) { tri->adj[0] = -1; } |
| 293 | if (tri->adj[1] >= 0 && !s_triangles[tri->adj[1]].allocated) { tri->adj[1] = -1; } |
| 294 | if (tri->adj[2] >= 0 && !s_triangles[tri->adj[2]].allocated) { tri->adj[2] = -1; } |
| 295 | } |
| 296 | |
| 297 | // Form a new triangle between the vertex and any edge with adjacency. |
| 298 | const size_t edgeCount = s_edges.size(); |
| 299 | const TriEdge* edge = s_edges.data(); |
| 300 | for (size_t e = 0; e < edgeCount; e++, edge++) |
| 301 | { |
| 302 | if (edge->refCount) { continue; } |
| 303 | |
| 304 | // Form a triangle from vtxIndex -> edge indices. |
| 305 | addTriangle(vtxIndex, edge->idx[0], edge->idx[1]); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // The original DF algorithm. |
| 310 | enum PointSegSide |
no test coverage detected