diff --git a/src/DotRecast.Recast/PolyUtils.cs b/src/DotRecast.Recast/PolyUtils.cs index 7aa61bd..304a860 100644 --- a/src/DotRecast.Recast/PolyUtils.cs +++ b/src/DotRecast.Recast/PolyUtils.cs @@ -95,7 +95,7 @@ namespace DotRecast.Recast if (bevel && cross < 0.0f) { - if (n + 2 >= maxOutVerts) + if (n + 2 > maxOutVerts) { return 0; } @@ -112,7 +112,7 @@ namespace DotRecast.Recast } else { - if (n + 1 >= maxOutVerts) + if (n + 1 > maxOutVerts) { return 0; } diff --git a/src/DotRecast.Recast/RecastArea.cs b/src/DotRecast.Recast/RecastArea.cs index 5504155..5efa778 100644 --- a/src/DotRecast.Recast/RecastArea.cs +++ b/src/DotRecast.Recast/RecastArea.cs @@ -430,84 +430,6 @@ namespace DotRecast.Recast ctx.StopTimer("MARK_CONVEXPOLY_AREA"); } - public static int OffsetPoly(float[] verts, int nverts, float offset, float[] outVerts, int maxOutVerts) - { - float MITER_LIMIT = 1.20f; - - int n = 0; - - for (int i = 0; i < nverts; i++) - { - int a = (i + nverts - 1) % nverts; - int b = i; - int c = (i + 1) % nverts; - int va = a * 3; - int vb = b * 3; - int vc = c * 3; - float dx0 = verts[vb] - verts[va]; - float dy0 = verts[vb + 2] - verts[va + 2]; - float d0 = dx0 * dx0 + dy0 * dy0; - if (d0 > 1e-6f) - { - d0 = (float)(1.0f / Math.Sqrt(d0)); - dx0 *= d0; - dy0 *= d0; - } - - float dx1 = verts[vc] - verts[vb]; - float dy1 = verts[vc + 2] - verts[vb + 2]; - float d1 = dx1 * dx1 + dy1 * dy1; - if (d1 > 1e-6f) - { - d1 = (float)(1.0f / Math.Sqrt(d1)); - dx1 *= d1; - dy1 *= d1; - } - - float dlx0 = -dy0; - float dly0 = dx0; - float dlx1 = -dy1; - float dly1 = dx1; - float cross = dx1 * dy0 - dx0 * dy1; - float dmx = (dlx0 + dlx1) * 0.5f; - float dmy = (dly0 + dly1) * 0.5f; - float dmr2 = dmx * dmx + dmy * dmy; - bool bevel = dmr2 * MITER_LIMIT * MITER_LIMIT < 1.0f; - if (dmr2 > 1e-6f) - { - float scale = 1.0f / dmr2; - dmx *= scale; - dmy *= scale; - } - - if (bevel && cross < 0.0f) - { - if (n + 2 >= maxOutVerts) - return 0; - float d = (1.0f - (dx0 * dx1 + dy0 * dy1)) * 0.5f; - outVerts[n * 3 + 0] = verts[vb] + (-dlx0 + dx0 * d) * offset; - outVerts[n * 3 + 1] = verts[vb + 1]; - outVerts[n * 3 + 2] = verts[vb + 2] + (-dly0 + dy0 * d) * offset; - n++; - outVerts[n * 3 + 0] = verts[vb] + (-dlx1 - dx1 * d) * offset; - outVerts[n * 3 + 1] = verts[vb + 1]; - outVerts[n * 3 + 2] = verts[vb + 2] + (-dly1 - dy1 * d) * offset; - n++; - } - else - { - if (n + 1 >= maxOutVerts) - return 0; - outVerts[n * 3 + 0] = verts[vb] - dmx * offset; - outVerts[n * 3 + 1] = verts[vb + 1]; - outVerts[n * 3 + 2] = verts[vb + 2] - dmy * offset; - n++; - } - } - - return n; - } - /// @par /// /// The value of spacial parameters are in world units.