function getEnclosedElements(elements, bbox) {

  var filteredElements = {};

  forEach(elements, function(element) {

    var e = element;

    if (e.waypoints) {
      e = getBBox(e);
    }

    if (!isNumber(bbox.y) && (e.x > bbox.x)) {
      filteredElements[element.id] = element;
    }
    if (!isNumber(bbox.x) && (e.y > bbox.y)) {
      filteredElements[element.id] = element;
    }
    if (e.x > bbox.x && e.y > bbox.y) {
      if (isNumber(bbox.width) && isNumber(bbox.height) &&
          e.width + e.x < bbox.width + bbox.x &&
          e.height + e.y < bbox.height + bbox.y) {

        filteredElements[element.id] = element;
      } else if (!isNumber(bbox.width) || !isNumber(bbox.height)) {
        filteredElements[element.id] = element;
      }
    }
  });

  return filteredElements;
}
Returns all elements that are enclosed from the bounding box.

  * If bbox.(width|height) is not specified the method returns
    all elements with element.x/y > bbox.x/y
  * If only bbox.x or bbox.y is specified, method return all elements with
    e.x > bbox.x or e.y > bbox.y

@param {Element[]} elements List of Elements to search through
@param {Rect} bbox the enclosing bbox.

@return {Element[]} enclosed elements