/* Circular1D Histogram
173952
function circularHistogram1D(length, init){
        var circularHist1D; 
        if(length instanceof Array){
            circularHist1D = length;
        }else {
            init = typeof init !== 'undefined' ? init : 0;
            circularHist1D = [];
            for(var x = 0; x< length; ++x){
                circularHist1D[x] = init;   
            }
        }
        
        circularHist1D.circularIndex = circularHistogram1DFunctions.circularIndex;
        circularHist1D.max = circularHistogram1DFunctions.max;
        circularHist1D.min = circularHistogram1DFunctions.min;
        circularHist1D.cv = circularHistogram1DFunctions.cv;
        circularHist1D.medianSmoothing = circularHistogram1DFunctions.medianSmoothing;
        circularHist1D.gaussianSmoothing = circularHistogram1DFunctions.gaussianSmoothing;
        circularHist1D.flatten = circularHistogram1DFunctions.flatten;
        circularHist1D.findPeaks = circularHistogram1DFunctions.findPeaks;
        circularHist1D.normalize = circularHistogram1DFunctions.normalize;
        
        return circularHist1D;
    }
505876
function(seg, n, d)
{
    var a = vdot(n, seg.ta) - seg.r;
    var b = vdot(n, seg.tb) - seg.r;
    return min(a, b) - d;
}
408007
def circular_mask(size):
    
    r = size/2
    c = (r,r)
    y,x = np.ogrid[-c[0]:size-c[0], -c[1]:size-c[1]]
    mask = ~(x*x + y*y <= r*r)
    return mask
138178
def hist2d(self, da, **kwargs):
        """"""
        if self.value is None or self.value == 'counts':
            normed = False
        else:
            normed = True
        y = da.values
        x = da.coords[da.dims[0]].values
        counts, xedges, yedges = np.histogram2d(
            x, y, normed=normed, **kwargs)
        if self.value == 'counts':
            counts = counts / counts.sum().astype(float)
        return counts, xedges, yedges
322684
def scatter(h1: Histogram1D, **kwargs) -> dict:
    
    shape = kwargs.pop("shape", DEFAULT_SCATTER_SHAPE)
    # size = kwargs.pop("size", DEFAULT_SCATTER_SIZE)

    mark_template = [{
        "type": "symbol",
        "from": {"data": "series"},
        "encode": {
            "enter": {
                "x": {"scale": "xscale", "field": "x"},
                "y": {"scale": "yscale", "field": "y"},
                "shape": {"value": shape},
                # "size": {"value": size},
                "fill": {"scale": "series", "field": "c"},
            },
        }
    }]
    vega = _scatter_or_line(h1, mark_template=mark_template, kwargs=kwargs)
    return vega
73981
private function readCircularString(WKBBuffer $buffer, CoordinateSystem $cs) : CircularString
    {
        $numPoints = $buffer->readUnsignedLong();

        $points = [];

        for ($i = 0; $i < $numPoints; $i++) {
            $points[] = $this->readPoint($buffer, $cs);
        }

        return new CircularString($cs, ...$points);
    }
1014533
def hist2d(x, y, label=None, opacity=None):
    
    x = np.atleast_1d(x)
    y = np.atleast_1d(y)
    data = [go.Histogram2d(x=x, y=y, opacity=opacity, name=label)]
    return Chart(data=data)
1317574
def euclidean(h1, h2): # 9 us @array, 33 us @list \w 100 bins
    
    """
    h1, h2 = __prepare_histogram(h1, h2)
    return math.sqrt(scipy.sum(scipy.square(scipy.absolute(h1 - h2))))
1108871
function Histogram( canvas, width, height, left, top ) {

		var graph, data, histogram, edges, axes, annotations, title, text;

		// [1] Instantiate a new graph generator and configure:
		graph = xfig.graph( canvas )
			.width( width )
			.height( height )
			.position({
				'left': left,
				'top': top
			})
			.xMin( 0 )
			.xMax( 1 )
			.yMin( 0 );

		// Create the graph:
		graph.create( 'histogram' );

		// Get data:
		d3.json( 'data/histogram.data.json', function ( error, json ) {

			// [2] Instantiate a new data generator and configure:
			data = xfig.data( json )
				.accessors( 'x', function ( d ) {
					return d[ 0 ];
				})
				.accessors( 'y', function ( d ) {
					return d[ 1 ];
				});

			// Create edges to define our histogram bins:
			edges = xfig.vector.linspace( -0.025, 1.025, 0.05 );
			
			// Format the data and histogram the data:
			data.format( [ 'x', 'y' ] )
				.histc(
					function ( d ) {
						return d[ 1 ];
					},
					edges
				);

			// Bind the data instance to the graph:
			graph.data( data )
				.yMax( data.max( function ( d ) {
					return d[ 1 ];
				}));

			// [3] Instantiate a new histogram generator and configure:
			histogram = xfig.histogram( graph )
				.labels( [ 'data 0' ] );

			// Create the histogram:
			histogram.create();

			// [4] Instantiate a new axes generator and configure:
			axes = xfig.axes( graph )
				.yLabel( 'counts' );

			// Create the axes:
			axes.create();

			// [5] Instantiate a new annotations generator and configure:
			annotations = xfig.annotations( graph );

			// Create the annotations element:
			annotations.create();

			// [5.1] Instantiate a new title instance and configure:
			title = annotations.title()
				.top( -30 )
				.left( 250 );

			// Add a (sub)title:
			title.create( 'Subtitle' );

			// [5.2] Instantiate a new text instance and configure:
			text = annotations.text()
				.width( 200 )
				.height( 100 )
				.top( 50 )
				.left( 310 );

			// Add a text annotation:
			text.create( 'This is another text annotation, which may run multiple lines.' );

		});

	}
196613
function distEuclidean(rgb0, rgb1) {
		var rd = rgb1[0]-rgb0[0],
			gd = rgb1[1]-rgb0[1],
			bd = rgb1[2]-rgb0[2];

		return Math.sqrt(Pr*rd*rd + Pg*gd*gd + Pb*bd*bd) / euclMax;
	}
1060211
function genCircles(width, height, N = 500) {
  const minR = 1;
  const maxR = Math.sqrt(width * height / N) * 0.5;

  return [...Array(N)].map((_, idx) => ({
    id: idx,
    x: Math.round(Math.random() * width),
    y: Math.round(Math.random() * height),
    r: Math.max(minR, Math.round(Math.random() * maxR))
  }));
}
552955
function parseCircular(object) {
  // if circular references are disabled, just return the refs object
  if (!config().circularRefs) {
    return object;
  }

  let pointerPath = parsePointer(object.$ref);

  // validate whether the path corresponds with current stack
  for (let i = 0; i < pointerPath.length; i++) {
    if (pointerPath[i] !== path[i]) {
      throw new Error('Invalid circular reference "' +  object.$ref + '"');
    }
  }

  return stack[pointerPath.length];
}
431512
def _areadist(ax, v, xr, c, bins=100, by=None, alpha=1, label=None):
    
    y, x = np.histogram(v[~np.isnan(v)], bins)
    x = x[:-1]

    if by is None:
        by = np.zeros((bins,))

    ax.fill_between(x, y, by, facecolor=c, alpha=alpha, label=label)
    return y
732067
public static int[] imageOffsets(double radius, int imgWidth) {


		double PI2 = Math.PI * 2.0;

		double circumference = PI2 * radius;
		int num = (int) Math.ceil(circumference);
		num = num - num % 4;

		double angleStep = PI2 / num;


		int temp[] = new int[(int) Math.ceil(circumference)];
		int i = 0;

		int prev = 0;

		for (double ang = 0; ang < PI2; ang += angleStep) {
			int x = (int) Math.round(Math.cos(ang) * radius);
			int y = (int) Math.round(Math.sin(ang) * radius);

			int pixel = y * imgWidth + x;

			if (pixel != prev) {
//                System.out.println("i = "+i+"  x = "+x+"  y = "+y);
				temp[i++] = pixel;
			}
			prev = pixel;
		}

		if (i == temp.length)
			return temp;
		else {
			int ret[] = new int[i];
			System.arraycopy(temp, 0, ret, 0, i);

			return ret;
		}
	}
642121
def _histogram_digitize(a, w, edges, normed):
    
    weighted = w is not None
    nbin = edges.shape[0] + 1
    if weighted:
        count = zeros(nbin, dtype=w.dtype)
        if normed:
            count = zeros(nbin, dtype=float)
            w = w / w.mean()
    else:
        count = zeros(nbin, int)

    binindex = digitize(a, edges)

    # Count the number of identical indices.
    flatcount = bincount(binindex, w)

    # Place the count in the histogram array.
    count[:len(flatcount)] = flatcount

    return count
729698
function (x, y, r) {
		return this.symbol('circle').attr({ x: x, y: y, r: r});
	}
1291862
def vec2pix(nside, x, y, z, nest=False):
    """"""
    theta, phi = vec2ang(np.transpose([x, y, z]))
    # hp.vec2ang() returns raveled arrays, which are 1D.
    if np.isscalar(x):
        theta = theta.item()
        phi = phi.item()
    else:
        shape = np.shape(x)
        theta = theta.reshape(shape)
        phi = phi.reshape(shape)
    lon, lat = _healpy_to_lonlat(theta, phi)
    return lonlat_to_healpix(lon, lat, nside, order='nested' if nest else 'ring')