MCPcopy Create free account
hub / github.com/esengine/esengine / calculateCenter

Method calculateCenter

packages/pathfinding/src/navmesh/NavMesh.ts:249–259  ·  view source on GitHub ↗

* @zh 计算多边形中心 * @en Calculate polygon center

(vertices: readonly IPoint[])

Source from the content-addressed store, hash-verified

247 * @en Calculate polygon center
248 */
249 private calculateCenter(vertices: readonly IPoint[]): IPoint {
250 let x = 0;
251 let y = 0;
252
253 for (const v of vertices) {
254 x += v.x;
255 y += v.y;
256 }
257
258 return createPoint(x / vertices.length, y / vertices.length);
259 }
260
261 /**
262 * @zh 查找包含点的多边形

Callers 1

addPolygonMethod · 0.95

Calls 1

createPointFunction · 0.90

Tested by

no test coverage detected