If your light cone is consistently less than 180 degrees, you can get away with sorting the vertices in the order of the slope of the rays joining them to the light, without any trigonometry:
getVerticesFromExtremes(shape, light){
const { position: center, vertices } = shape;
const { position } = light;
// Construct a vector pointing from the light to the object.
const axis = new Vector(center.x - position.x, center.y - position.y);
// Compute offsets to center the light in this axis-oriented coordinates system.
const onShift = position.x * axis.x + position.y * axis.y;
const offShift = position.x * axis.y - position.y * axis.x;
let minSlope = Infinity;
let maxSlope = -Infinity;
let minIndex = 0;
let maxIndex = 0;
vertices.forEach((vertex, index) => {
// Put this vertex into a light-centered coordinate system.
// First, measuring its (scaled) distance in front of the light:
const onAxis = vertex.x * axis.x + vertex.y * axis.y - onShift;
// Skip vertices behind / in the plane of the light.
if (onAxis <= 0) continue;
// Then measuring its (scaled) offset above or below the line through
// the center of this object.
const offAxis = vertex.x * axis.y - vertex.y * axis.x - offShift;
// Compute the slope of the line from the light to the vertex.
const slope = offAxis / onAxis;
if (slope < minSlope) {
minSlope = slope;
minIndex = index;
}
if (slope > maxSlope) {
maxSlope = slope;
maxIndex = index;
}
});
if(minIndex > maxIndex) return {
min: maxIndex,
max: minIndex
}
return {
min: minIndex,
max: maxIndex
}
}
This gets more complicated if you have a light with a > 180 degree span though, or complex shapes that can wrap around the light, so the object's center is on one side, but some occluding vertices might be on the other.