MCPcopy Create free account
hub / github.com/melonjs/melonJS / toPolygon

Method toPolygon

packages/melonjs/src/renderable/mesh.js:878–894  ·  view source on GitHub ↗

* Compute a 2D convex hull polygon from the current projected vertices. * Useful for creating collision shapes. * @returns {Polygon} a convex hull polygon in local coordinates

()

Source from the content-addressed store, hash-verified

876 * @returns {Polygon} a convex hull polygon in local coordinates
877 */
878 toPolygon() {
879 // update cached points from projected vertices
880 for (let i = 0; i < this.vertexCount; i++) {
881 this._hullPoints[i].set(this.vertices[i * 3], this.vertices[i * 3 + 1]);
882 }
883
884 // Graham scan convex hull (sorts in place, returns a subset)
885 const hull = convexHull(this._hullPoints);
886
887 if (this._hullPolygon === null) {
888 this._hullPolygon = new Polygon(0, 0, hull);
889 } else {
890 this._hullPolygon.setVertices(hull);
891 }
892
893 return this._hullPolygon;
894 }
895
896 /**
897 * Render the mesh at its current state (transforms, projection, tint) to an offscreen canvas.

Callers 7

testEllipseEllipseFunction · 0.45
testPolygonEllipseFunction · 0.45
addShapeMethod · 0.45
makeCasesFunction · 0.45
sat.spec.jsFile · 0.45
ellipse.spec.tsFile · 0.45
constructorMethod · 0.45

Calls 3

convexHullFunction · 0.90
setMethod · 0.45
setVerticesMethod · 0.45

Tested by 1

makeCasesFunction · 0.36