Request: Corner position and center position


#1

I have a request to add a reference to an entities corner position as well as the center position. I’ll explain my thinking:
I’ve made a collection of lights and an invisible box that contains them all. When the user does some action, I want to get the list of lights, find the closest one to the avatar, and then change the color of that light.

The issue I have is with the gathering of the objects. Here’s a sample of the code:

var containerBox = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}";

function actionHandler() {
    var closest = findClosestLight();
    if (closest) {
        turnLightOn(closest);
    }
}

function findClosestLight() {
    var containerArea = Entities.getEntityProperties(containerBox, ["position", "dimensions"]),
        entities = Entities.findEntitiesInBox(containerArea.position, containerArea.dimensions),
        closestDistance,
        closestId,
        i,
        props,
        distance;
    for (i = 0; i < entities.length; i += 1) {
        props = Entities.getEntityProperties(entities[i], ["name", "position"]);
        distance = Vec3.distance(MyAvatar.position, props.position);
        if (props.name === "Light") {
            if (!closestDistance || distance < closestDistance) {
                closestDistance = distance;
                closestId = entities[i];
            }
        }
    }

    return closestId;
}

The code works, except for these lines:

var containerArea = Entities.getEntityProperties(containerBox, ["position", "dimensions"]),
    entities = Entities.findEntitiesInBox(containerArea.position, containerArea.dimensions),

Here, Entities.getEntityProperties(..., ["position"]) returns the center of the entity, but Entities.findEntitiesInBox wants the corner of the search box. This means, I only get 1/4 of the lights, because what it expects is the corner is actually not.

I can fix this by making a centerToCorner function, but this seems like a common enough instance that having a way to get an entities corner position would be useful.

Thank you for considering it, and I’ll be happy to answer any questions.