square distance from a segment bounding box to the given one
326794
function sqSegBoxDist(a, b, bbox) {
    if (inside(a, bbox) || inside(b, bbox)) return 0;
    var d1 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.minY, bbox.maxX, bbox.minY);
    if (d1 === 0) return 0;
    var d2 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.minY, bbox.minX, bbox.maxY);
    if (d2 === 0) return 0;
    var d3 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.maxX, bbox.minY, bbox.maxX, bbox.maxY);
    if (d3 === 0) return 0;
    var d4 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.maxY, bbox.maxX, bbox.maxY);
    if (d4 === 0) return 0;
    return Math.min(d1, d2, d3, d4);
}
1283503
def get_bounding_box(self, maxdist):
        
        locations = [rup.hypocenter for rup in self.ruptures]
        return get_bounding_box(locations, maxdist)
1346499
def interp_box(x, y, z, box, values):
    

    # Calculate the distance to each vertex

    val = 0
    norm = 0
    for i in range(8):
        # Inv distance, or Inv-dsq weighting
        distance = sqrt((x-box[i,0])**2 + (y-box[i,1])**2 + (z-box[i, 2])**2)

        # If you happen to land on exactly a corner, you're done.
        if distance == 0:
            val = values[i]
            norm = 1.
            break

        w = 1./distance
        # w = 1./((x-box[i,0])*(x-box[i,0]) +
        #         (y-box[i,1])*(y-box[i,1]) +
        #         (z-box[i, 2])*(z-box[i, 2]))
        val += w * values[i]
        norm += w

    return val/norm
603251
def get_bounding_box(self, crs):
        """"""
        return self.from_bounds(*self.get_bounds(crs), crs=crs)
1192592
def ks_distance(a, b):
    ''''''
    if len(a.shape) == 1:
        return np.max(np.abs(a.cumsum() - b.cumsum()))
    return np.max(np.abs(a.cumsum(axis=1) - b.cumsum(axis=1)), axis=1)
724777
def bbox(self):
        """"""
        bbs = [seg.bbox() for seg in self._segments]
        xmins, xmaxs, ymins, ymaxs = list(zip(*bbs))
        xmin = min(xmins)
        xmax = max(xmaxs)
        ymin = min(ymins)
        ymax = max(ymaxs)
        return xmin, xmax, ymin, ymax
891490
def bounding_box(self):
        

        w2 = self.width / 2.
        h2 = self.height / 2.
        cos_angle = np.cos(self.angle)    # self.angle is a Quantity
        sin_angle = np.sin(self.angle)    # self.angle is a Quantity
        dx1 = abs(w2 * cos_angle - h2 * sin_angle)
        dy1 = abs(w2 * sin_angle + h2 * cos_angle)
        dx2 = abs(w2 * cos_angle + h2 * sin_angle)
        dy2 = abs(w2 * sin_angle - h2 * cos_angle)
        dx = max(dx1, dx2)
        dy = max(dy1, dy2)

        xmin = self.center.x - dx
        xmax = self.center.x + dx
        ymin = self.center.y - dy
        ymax = self.center.y + dy

        return BoundingBox.from_float(xmin, xmax, ymin, ymax)
1132164
def bounds_window(bounds, affine):
    
    w, s, e, n = bounds
    row_start, col_start = rowcol(w, n, affine)
    row_stop, col_stop = rowcol(e, s, affine, op=math.ceil)
    return (row_start, row_stop), (col_start, col_stop)
220934
def point_segment_distance(point, segment):
    
    assert isinstance(point, Point), \
        "point is not of type Point, but of %r" % type(point)
    dx = segment.p2.x - segment.p1.x
    dy = segment.p2.y - segment.p1.y
    if dx == dy == 0:  # the segment's just a point
        return point.dist_to(segment.p1)

    if dx == 0:  # It's a straight vertical line
        p_below_p1 = point.y <= segment.p1.y and segment.p1.y <= segment.p2.y
        p_below_p2 = point.y <= segment.p2.y and segment.p2.y <= segment.p1.y
        p_above_p2 = segment.p1.y <= segment.p2.y and segment.p2.y <= point.y
        p_above_p1 = segment.p2.y <= segment.p1.y and segment.p1.y <= point.y
        if p_below_p1 or p_above_p1:
            return point.dist_to(segment.p1)
        elif p_below_p2 or p_above_p2:
            return point.dist_to(segment.p2)

    if dy == 0:  # It's a straight horizontal line
        p_left_p1 = point.x <= segment.p1.x and segment.p1.x <= segment.p2.x
        p_left_p2 = point.x <= segment.p2.x and segment.p2.x <= segment.p1.x
        p_right_p2 = segment.p1.x <= segment.p2.x and segment.p2.x <= point.x
        p_right_p1 = segment.p2.x <= segment.p1.x and segment.p1.x <= point.x
        if p_left_p1 or p_right_p1:
            return point.dist_to(segment.p1)
        elif p_left_p2 or p_right_p2:
            return point.dist_to(segment.p2)

    # Calculate the t that minimizes the distance.
    t = ((point.x - segment.p1.x) * dx + (point.y - segment.p1.y) * dy) / \
        (dx * dx + dy * dy)

    # See if this represents one of the segment's
    # end points or a point in the middle.
    if t < 0:
        dx = point.x - segment.p1.x
        dy = point.y - segment.p1.y
    elif t > 1:
        dx = point.x - segment.p2.x
        dy = point.y - segment.p2.y
    else:
        near_x = segment.p1.x + t * dx
        near_y = segment.p1.y + t * dy
        dx = point.x - near_x
        dy = point.y - near_y
    return math.hypot(dx, dy)
407526
def _parse_bounding_box(bounding_box):
        '''
        
        '''
        coordinates = json.loads(bounding_box)["coordinates"]
        x_coords = [x for x, y in coordinates[0]]
        y_coords = [y for x, y in coordinates[0]]
        return min(x_coords), min(y_coords), max(x_coords), max(y_coords)
759120
def bounding_box(visible_only = true)
      maxX = atoms(visible_only).first.x
      maxY = atoms(visible_only).first.y
      maxZ = atoms(visible_only).first.z
      minX = maxX
      minY = maxY
      minZ = maxZ
      
      atoms(visible_only).each{|a|
        if a.x > maxX
          maxX = a.x
        elsif a.x < minX
          minX = a.x
        end
        
        if a.y > maxY
          maxY = a.y
        elsif a.y < minY
          minY = a.y
        end
        
        if a.z > maxZ
          maxZ = a.z
        elsif a.z < minZ
          minZ = a.z
        end
      }

      [Atom.new(maxX, maxY, maxZ), Atom.new(minX, minY, minZ)]
    end
221717
def bounds(self, thr=0):
        
        min_lat = float("inf")
        min_lon = float("inf")
        max_lat = -float("inf")
        max_lon = -float("inf")
        for segment in self.segments:
            milat, milon, malat, malon = segment.bounds(thr=thr)
            min_lat = min(milat, min_lat)
            min_lon = min(milon, min_lon)
            max_lat = max(malat, max_lat)
            max_lon = max(malon, max_lon)
        return min_lat, min_lon, max_lat, max_lon
837934
def get_closest_box(self, pos):
        """"""
        pos = np.atleast_2d(pos)
        d = np.sum((np.array(self.box_pos) - pos) ** 2, axis=1)
        idx = np.argmin(d)
        return idx
1240509
def distance(r1: 'Region', r2: 'Region'):
        
        return math.sqrt((r2.x - r1.x) ** 2 + (r2.y - r1.y) ** 2)
1373736
def bound(self, p1, p2=None):
    """"""
    r = Rect(p1, p2)
    return Point(min(max(self.x, r.l), r.r), min(max(self.y, r.t), r.b))
209771
def bounding_box(self):
        
        from . import primitives

        transform = np.eye(4)
        # translate to center of axis aligned bounds
        transform[:3, 3] = self.bounds.mean(axis=0)

        aabb = primitives.Box(transform=transform,
                              extents=self.extents,
                              mutable=False)
        return aabb
734716
private int[] getIntBounds(BoundingBox coordbounds) {
		int[] bs = new int[6];
		bs[0] = getFloor(coordbounds.xmin);
		bs[1] = getFloor(coordbounds.ymin);
		bs[2] = getFloor(coordbounds.zmin);
		bs[3] = getFloor(coordbounds.xmax);
		bs[4] = getFloor(coordbounds.ymax);
		bs[5] = getFloor(coordbounds.zmax);
		return bs;
	}