If positive, distance, in pixels, to the nearest opaque pixel.
 If negative, distance in pixels to the nearest transparent pixel.
351597
def sample_distance(x, y)
      x = [[x, width - 1].min, 0].max
      y = [[y, height - 1].min, 0].max
      # Could be checking any of red/blue/green.
      @field.red((x / @scale).round, (y / @scale).round) - ZERO_DISTANCE
    end
704443
def _count_pixels_on_line(self, y, p):
        """"""
        h = line(y, self._effective_thickness(p), 0.0)
        return h.sum()
836815
function(obj) {
                if (obj.start && obj.end) { return this.contains(obj.start) && this.contains(obj.end); }
                var dist = this.distanceFrom(obj);
                return (dist !== null && dist <= sylvester.precision);
              }
1249811
def is_outside_bounds(self, val):
    """"""
    return ((self.lower_bound is not None and val < self.lower_bound) or
            (self.upper_bound is not None and val > self.upper_bound))
1173132
def search(self, coords=None, distance_modulus=None, tolerance=1.e-2):
        
        nmoduli = len(self.distance_modulus_array)
        npixels    = len(self.roi.pixels_target)
        self.log_likelihood_sparse_array       = np.zeros([nmoduli, npixels])
        self.richness_sparse_array             = np.zeros([nmoduli, npixels])
        self.richness_lower_sparse_array       = np.zeros([nmoduli, npixels])
        self.richness_upper_sparse_array       = np.zeros([nmoduli, npixels])
        self.richness_upper_limit_sparse_array = np.zeros([nmoduli, npixels])
        self.stellar_mass_sparse_array         = np.zeros([nmoduli, npixels])
        self.fraction_observable_sparse_array  = np.zeros([nmoduli, npixels])

        # Specific pixel/distance_modulus
        coord_idx, distance_modulus_idx = None, None
        if coords is not None:
            # Match to nearest grid coordinate index
            coord_idx = self.roi.indexTarget(coords[0],coords[1])
        if distance_modulus is not None:
            # Match to nearest distance modulus index
            distance_modulus_idx=np.fabs(self.distance_modulus_array-distance_modulus).argmin()

        lon, lat = self.roi.pixels_target.lon, self.roi.pixels_target.lat
            
        logger.info('Looping over distance moduli in grid search ...')
        for ii, distance_modulus in enumerate(self.distance_modulus_array):

            # Specific pixel
            if distance_modulus_idx is not None:
                if ii != distance_modulus_idx: continue

            logger.info('  (%-2i/%i) Distance Modulus=%.1f ...'%(ii+1,nmoduli,distance_modulus))

            # Set distance_modulus once to save time
            self.loglike.set_params(distance_modulus=distance_modulus)

            for jj in range(0, npixels):
                # Specific pixel
                if coord_idx is not None:
                    if jj != coord_idx: continue

                # Set kernel location
                self.loglike.set_params(lon=lon[jj],lat=lat[jj])
                # Doesn't re-sync distance_modulus each time
                self.loglike.sync_params()
                                         
                args = (jj+1, npixels, self.loglike.source.lon, self.loglike.source.lat)
                msg = '    (%-3i/%i) Candidate at (%.2f, %.2f) ... '%(args)

                self.log_likelihood_sparse_array[ii][jj], self.richness_sparse_array[ii][jj], parabola = self.loglike.fit_richness()
                self.stellar_mass_sparse_array[ii][jj] = self.stellar_mass_conversion * self.richness_sparse_array[ii][jj]
                self.fraction_observable_sparse_array[ii][jj] = self.loglike.f
                if self.config['scan']['full_pdf']:
                    #n_pdf_points = 100
                    #richness_range = parabola.profileUpperLimit(delta=25.) - self.richness_sparse_array[ii][jj]
                    #richness = np.linspace(max(0., self.richness_sparse_array[ii][jj] - richness_range),
                    #                          self.richness_sparse_array[ii][jj] + richness_range,
                    #                          n_pdf_points)
                    #if richness[0] > 0.:
                    #    richness = np.insert(richness, 0, 0.)
                    #    n_pdf_points += 1
                    # 
                    #log_likelihood = np.zeros(n_pdf_points)
                    #for kk in range(0, n_pdf_points):
                    #    log_likelihood[kk] = self.loglike.value(richness=richness[kk])
                    #parabola = ugali.utils.parabola.Parabola(richness, 2.*log_likelihood)
                    #self.richness_lower_sparse_array[ii][jj], self.richness_upper_sparse_array[ii][jj] = parabola.confidenceInterval(0.6827)
                    self.richness_lower_sparse_array[ii][jj], self.richness_upper_sparse_array[ii][jj] = self.loglike.richness_interval(0.6827)
                    
                    self.richness_upper_limit_sparse_array[ii][jj] = parabola.bayesianUpperLimit(0.95)

                    args = (
                        2. * self.log_likelihood_sparse_array[ii][jj],
                        self.stellar_mass_conversion*self.richness_sparse_array[ii][jj],
                        self.stellar_mass_conversion*self.richness_lower_sparse_array[ii][jj],
                        self.stellar_mass_conversion*self.richness_upper_sparse_array[ii][jj],
                        self.stellar_mass_conversion*self.richness_upper_limit_sparse_array[ii][jj]
                    )
                    msg += 'TS=%.1f, Stellar Mass=%.1f (%.1f -- %.1f @ 0.68 CL, < %.1f @ 0.95 CL)'%(args)
                else:
                    args = (
                        2. * self.log_likelihood_sparse_array[ii][jj], 
                        self.stellar_mass_conversion * self.richness_sparse_array[ii][jj],
                        self.fraction_observable_sparse_array[ii][jj]
                    )
                    msg += 'TS=%.1f, Stellar Mass=%.1f, Fraction=%.2g'%(args)
                logger.debug(msg)
                
                #if coords is not None and distance_modulus is not None:
                #    results = [self.richness_sparse_array[ii][jj],
                #               self.log_likelihood_sparse_array[ii][jj],
                #               self.richness_lower_sparse_array[ii][jj],
                #               self.richness_upper_sparse_array[ii][jj],
                #               self.richness_upper_limit_sparse_array[ii][jj],
                #               richness, log_likelihood, self.loglike.p, self.loglike.f]
                #    return results

            jj_max = self.log_likelihood_sparse_array[ii].argmax()
            args = (
                jj_max+1, npixels, lon[jj_max], lat[jj_max],
                2. * self.log_likelihood_sparse_array[ii][jj_max], 
                self.stellar_mass_conversion * self.richness_sparse_array[ii][jj_max]
            )
            msg = '  (%-3i/%i) Maximum at (%.2f, %.2f) ... TS=%.1f, Stellar Mass=%.1f'%(args)
            logger.info(msg)
653594
function(x) {
        if (!x.rgba) {
            return -1;
        }
        return (x.rgba[0] === this.rgba[0] && x.rgba[1] === this.rgba[1]
                && x.rgba[2] === this.rgba[2] && x.rgba[3] === this.rgba[3]) ? 0
                : -1;
    }
1013147
public void setNearClippingDistance(float near) {
        if(leftCamera instanceof GVRCameraClippingDistanceInterface &&
           centerCamera instanceof GVRCameraClippingDistanceInterface &&
           rightCamera instanceof GVRCameraClippingDistanceInterface) {
            ((GVRCameraClippingDistanceInterface)leftCamera).setNearClippingDistance(near);
            centerCamera.setNearClippingDistance(near);
            ((GVRCameraClippingDistanceInterface)rightCamera).setNearClippingDistance(near);
        }
    }
1086315
def pixels(self, value: float) -> 'Size':
        """"""
        raise_not_number(value)
        self.maximum = '{}px'.format(value)
        return self
1112733
def pixel_bounds_based_on_center
      viewport_radius_w = @viewport_w / 2
      viewport_radius_h = @viewport_h / 2
      @pixel_bounds_based_on_center ||= {
          sw: [pixel_coords[0] + viewport_radius_h, pixel_coords[1] - viewport_radius_w],
          ne: [pixel_coords[0] - viewport_radius_h, pixel_coords[1] + viewport_radius_w]
      }
    end
812406
def pixel(self, x, y, color=None):
        """"""
        if self.rotation == 1:
            x, y = y, x
            x = self.width - x - 1
        if self.rotation == 2:
            x = self.width - x - 1
            y = self.height - y - 1
        if self.rotation == 3:
            x, y = y, x
            y = self.height - y - 1

        if x < 0 or x >= self.width or y < 0 or y >= self.height:
            return None
        if color is None:
            return self.format.get_pixel(self, x, y)
        self.format.set_pixel(self, x, y, color)
        return None
715214
def pixel_difference_filter(pixel, x, y)
      chans = []
      [:r, :b, :g].each do |chan| 
        chans << channel_difference(chan, pixel, x, y)
      end
      @images.last[x,y] = ChunkyPNG::Color.rgb(chans[0], chans[1], chans[2])
    end
940611
def nearest_neighbor(x, tSet):
    
    assert isinstance(x, tuple) and isinstance(tSet, dict)
    current_key = ()
    min_d = float('inf')
    for key in tSet:
        d = distance(x, key)
        if d < min_d:
            min_d = d
            current_key = key
    return tSet[current_key]
384716
def distance_color_labels(labels):
    '''
    
    '''
    #
    # Color labels so adjacent ones are most distant
    #
    colors = color_labels(labels, True)
    #
    # Order pixels by color, then label #
    #
    rlabels = labels.ravel()
    order = np.lexsort((rlabels, colors.ravel()))
    #
    # Construct color indices with the cumsum trick:
    # cumsum([0,0,1,0,1]) = [0,0,1,1,2]
    # and copy back into the color array, using the order.
    #
    different = np.hstack([[rlabels[order[0]] > 0],
                           rlabels[order[1:]] != rlabels[order[:-1]]])
    # We need to careful about ravel() returning a new object, but in the usual
    # case of colors having order='C', this won't create any copies.
    rcolor = colors.ravel()
    rcolor[order] = np.cumsum(different).astype(colors.dtype)
    return rcolor.reshape(colors.shape).astype(labels.dtype)
1347751
def contrast(self, value):
        
        assert(0x00 <= value <= 0xFF)
        self._brightness = value >> 4
        if self._last_image is not None:
            self.display(self._last_image)
1221009
def get_pixel_distance(self, x1, y1, x2, y2):
        
        dx = abs(x2 - x1)
        dy = abs(y2 - y1)
        dist = np.sqrt(dx * dx + dy * dy)
        dist = np.round(dist)
        return dist
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;
}
1074181
def check_bounds(self):
        """"""
        if not (self.camera_bounds == None):
            if self.__pan.X < self.camera_bounds.Left:
                self.__pan[0] = self.camera_bounds.Left

            if self.__pan.X > self.camera_bounds.Right:
                self.__pan[0] = self.camera_bounds.Right

            if self.__pan.Y < self.camera_bounds.Top:
                self.__pan[1] = self.camera_bounds.Top

            if self.__pan.Y > self.camera_bounds.Bottom:
                self.__pan[1] = self.camera_bounds.Bottom