Returns X, Y coordinates containing the closest avilable CIE 1931
    based on the hex_value provided.
548900
def get_xy_from_hex(hex_value):
    '''
    
    '''
    red, green, blue = struct.unpack('BBB', codecs.decode(hex_value, 'hex'))
    r = ((red + 0.055) / (1.0 + 0.055)) ** 2.4 if (red > 0.04045) else (red / 12.92)  # pragma: noqa
    g = ((green + 0.055) / (1.0 + 0.055)) ** 2.4 if (green > 0.04045) else (green / 12.92)  # pragma: noqa
    b = ((blue + 0.055) / (1.0 + 0.055)) ** 2.4 if (blue > 0.04045) else (blue / 12.92)  # pragma: noqa

    X = r * 0.4360747 + g * 0.3850649 + b * 0.0930804
    Y = r * 0.2225045 + g * 0.7168786 + b * 0.0406169
    Z = r * 0.0139322 + g * 0.0971045 + b * 0.7141733

    if X + Y + Z == 0:
        cx = cy = 0
    else:
        cx = X / (X + Y + Z)
        cy = Y / (X + Y + Z)

    # Check if the given XY value is within the colourreach of our lamps.
    xy_point = XYPoint(cx, cy)
    is_in_reach = in_lamp_reach(xy_point)

    if not is_in_reach:
        xy_point = get_closest_point_to_point(xy_point)

    return xy_point
453570
def find_nearest_color_hexstr(hexdigits, color_table=None, method='euclid'):
    ''' 
    '''
    triplet = []
    try:
        if len(hexdigits) == 3:
            for digit in hexdigits:
                digit = int(digit, 16)
                triplet.append((digit * 16) + digit)
        elif len(hexdigits) == 6:
            triplet.extend(int(hexdigits[i:i+2], 16) for i in (0, 2, 4))
        else:
            raise ValueError('wrong length: %r' % hexdigits)
    except ValueError:
        return None

    return find_nearest_color_index(*triplet,
                                    color_table=color_table,
                                    method=method)
665545
def D(self):
        '''
        
        '''
        return Point(self.minX, self.maxY, self.origin.z)
1349246
def _component_closest_to_origin(components, glyph_set):
    
    return min(components, key=lambda comp: _distance((0, 0), _bounds(comp, glyph_set)))
619068
def ceil_nearest(x, dx=1):
    
    precision = get_sig_digits(dx)
    return round(math.ceil(float(x) / dx) * dx, precision)
217958
def xAxisIsMinor(self):
        '''
        
        '''
        return min(self.radius.x, self.radius.y) == self.radius.x
712889
def B(self):
        '''
        
        '''
        return Point(self.maxX, self.minY, self.origin.z)
700057
def get_bbox(self):
        """"""

        x_min = self.x
        x_max = x_min + self.width
        y_min = self.y
        y_max = self.y + self.height

        return x_min, x_max, y_min, y_max
54985
def get_closest_point_to_line(A, B, P):
    '''
    
    '''
    AP = XYPoint(P.x - A.x, P.y - A.y)
    AB = XYPoint(B.x - A.x, B.y - A.y)
    ab2 = AB.x * AB.x + AB.y * AB.y
    ap_ab = AP.x * AB.x + AP.y * AB.y
    t = ap_ab / ab2

    if t < 0.0:
        t = 0.0
    elif t > 1.0:
        t = 1.0

    return XYPoint(A.x + AB.x * t, A.y + AB.y * t)
937336
def closestNonZeroIndex(pt, arr, kSize=21):
    
    assert kSize % 2 == 1, 'need odd kernel size'

    hk = int(kSize / 2)
    ipt = np.asarray(pt, dtype=int)
    # array slice of shape kSize around ipt:
    r = [slice(max(0, p - hk),
               min(s, p + hk + 1)) for p, s in zip(ipt, arr.shape)]

    # sliced array:
    arrr = arr[tuple(r)]
    # all indices that are non zero:
    ind = np.transpose(np.nonzero(arrr))
    if not len(ind):
        # nothing found
        return None
    # pos of ipt within array slice:
    center = [p - s.start for p, s in zip(ipt, r)]
    ind -= center
    # index of minimum distance:
    m = np.argmin(norm(ind, axis=-1))
    return ipt + ind[m]
83906
def get(self, pos):
        """"""
        latitude = int(round(pos['latitude']))
        search_set = self.bins[latitude]
        i = 1
        if latitude - i >= -90:
            search_set += self.bins[latitude-i]
        if latitude + i <= 90:
            search_set += self.bins[latitude+i]
        while len(search_set) == 0 and i <= 200:
            if latitude - i >= -90:
                search_set += self.bins[latitude-i]
            if latitude + i <= 90:
                search_set += self.bins[latitude+i]
            i += 1
        return find_closest(search_set, pos)
887138
def closest_values(L):
    
    assert len(L) >= 2
    L.sort()
    valmin, argmin = min((L[i] - L[i - 1], i) for i in range(1, len(L)))
    return L[argmin - 1], L[argmin]
1281742
def get_xyz_1d(self, xcoord, x, ycoord, y, u, v):
        """"""
        xclose = xcoord.indexes[xcoord.name].get_loc(x, method='nearest')
        yclose = ycoord.indexes[ycoord.name].get_loc(y, method='nearest')
        uval = u[yclose, xclose].values
        vval = v[yclose, xclose].values
        return xcoord[xclose].values, ycoord[yclose].values, uval, vval
1009177
def _get_xk(self, yk):
        ''''''
        if yk is not None:
            return self.x0 + self.linear_system.Mr * yk
        return self.x0
1367979
private int getSourcePixel(int x,int y)
    {
        x = Math.max(0,x);
        x = Math.min(width-1,x);
        y = Math.max(0,y);
        y = Math.min(height-1,y);
        
        return srcImage[x+(y*width)];
    }
866471
function closestPoint1d(a, b, x, result) {
  var denom = 0.0;
  var numer = 0.0;
  for(var i=0; i<x.length; ++i) {
    var ai = a[i];
    var bi = b[i];
    var xi = x[i];
    var dd = ai - bi;
    numer += dd * (xi - bi);
    denom += dd * dd;
  }
  var t = 0.0;
  if(Math.abs(denom) > EPSILON) {
    t = numer / denom;
    if(t < 0.0) {
      t = 0.0;
    } else if(t > 1.0) {
      t = 1.0;
    }
  }  
  var ti = 1.0 - t;
  var d = 0;
  for(var i=0; i<x.length; ++i) {
    var r = t * a[i] + ti * b[i];
    result[i] = r;
    var s = x[i] - r;
    d += s * s;
  }
  return d;
}
1326290
public int get32u8( int x , int y ) {
		int i = startIndex + y*stride+x;
		return ((((GrayU8)bands[0]).data[i]&0xFF) << 24) |
				((((GrayU8)bands[1]).data[i]&0xFF) << 16) |
				((((GrayU8)bands[2]).data[i]&0xFF) << 8) |
				(((GrayU8)bands[3]).data[i]&0xFF);
	}