we normalize the area of each symbol so it is approximately the same as a circle of the given radius
774383
function(ctx, x, y, radius, shadow, fill) {
            if (!shadow) {
                ctx.moveTo(x + radius, y);
                ctx.arc(x, y, radius, 0, Math.PI * 2, false);
            }
        }
419976
def area(self):
        

        self.normalize()
        area = 0.0

        for (order, cells) in self:
            area += (len(cells) * pi) / (3 * 4 ** order)

        return area
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))
  }));
}
678411
function circleCircleIntersection(p1, p2) {
        var d = distance(p1, p2),
            r1 = p1.radius,
            r2 = p2.radius;

        // if to far away, or self contained - can't be done
        if ((d >= (r1 + r2)) || (d <= Math.abs(r1 - r2))) {
            return [];
        }

        var a = (r1 * r1 - r2 * r2 + d * d) / (2 * d),
            h = Math.sqrt(r1 * r1 - a * a),
            x0 = p1.x + a * (p2.x - p1.x) / d,
            y0 = p1.y + a * (p2.y - p1.y) / d,
            rx = -(p2.y - p1.y) * (h / d),
            ry = -(p2.x - p1.x) * (h / d);

        return [{x: x0 + rx, y : y0 - ry },
                {x: x0 - rx, y : y0 + ry }];
    }
888701
def _le_circle(self, annot, p1, p2, lr):
        
        m, im, L, R, w, scol, fcol, opacity = self._le_annot_parms(annot, p1, p2)
        shift = 2.5             # 2*shift*width = length of square edge
        d = shift * max(1, w)
        M = R - (d/2., 0) if lr else L + (d/2., 0)
        r = Rect(M, M) + (-d, -d, d, d)         # the square
        ap = "q\n" + opacity + self._oval_string(r.tl * im, r.tr * im, r.br * im, r.bl * im)
        ap += "%g w\n" % w
        ap += scol + fcol + "b\nQ\n"
        return ap
591945
def to_fits(self):
        

        max_length_coord = 1
        coord_x = []
        coord_y = []
        shapes = []
        radius = []
        rotangle_deg = []
        components = []

        reg_reverse_mapping = {value: key for key, value in
                               reg_mapping['FITS_REGION'].items()}
        reg_reverse_mapping['rectangle'] = 'ROTBOX'
        reg_reverse_mapping['circleannulus'] = 'ANNULUS'
        reg_reverse_mapping['ellipseannulus'] = 'ELLIPTANNULUS'

        for num, shape in enumerate(self):
            shapes.append(reg_reverse_mapping[shape.region_type])
            if shape.region_type == 'polygon':
                max_length_coord = max(len(shape.coord)/2, max_length_coord)
                coord = [x.value for x in shape.coord]
                coord_x.append(coord[::2])
                coord_y.append(coord[1::2])
                radius.append(0)
                rotangle_deg.append(0)
            else:
                coord_x.append(shape.coord[0].value)
                coord_y.append(shape.coord[1].value)
                if shape.region_type in ['circle', 'circleannulus', 'point']:
                    radius.append([float(val) for val in shape.coord[2:]])
                    rotangle_deg.append(0)
                else:
                    radius.append([float(x) for x in shape.coord[2:-1]])
                    rotangle_deg.append(shape.coord[-1].to('deg').value)

            tag = shape.meta.get('tag', '')
            if tag.isdigit():
                components.append(int(tag))
            else:
                components.append(num + 1)

        # padding every value with zeros at the end to make sure that all values
        # in the column have same length.
        for i in range(len(self)):
            if np.isscalar(coord_x[i]):
                coord_x[i] = np.array([coord_x[i]])
            if np.isscalar(coord_y[i]):
                coord_y[i] = np.array([coord_y[i]])
            if np.isscalar(radius[i]):
                radius[i] = np.array([radius[i]])

            coord_x[i] = np.pad(coord_x[i], (0, int(max_length_coord - len(coord_x[i]))),
                                'constant', constant_values=(0, 0))
            coord_y[i] = np.pad(coord_y[i], (0, int(max_length_coord - len(coord_y[i]))),
                                'constant', constant_values=(0, 0))
            radius[i] = np.pad(radius[i], (0, 4 - len(radius[i])), 'constant',
                               constant_values=(0, 0))

        table = Table([coord_x, coord_y, shapes, radius, rotangle_deg, components],
                       names=('X', 'Y', 'SHAPE', 'R', 'ROTANG', 'COMPONENT'))
        table['X'].unit = 'pix'
        table['Y'].unit = 'pix'
        table['R'].unit = 'pix'
        table['ROTANG'].unit = 'deg'

        return table
1003201
function _normalizedCoordinates(x, y, z, w) {
  var magnitude = Math.sqrt(x * x + y * y + z * z + w * w);
  if (magnitude === 0)
    return this;

  return {
    "x": x / magnitude,
    "y": y / magnitude,
    "z": z / magnitude,
    "w": w / magnitude};
}
601059
def approx_equal(self, center, width, height, angle, tol=1e-6):
        ""
        return abs(self.cx - center[0]) < tol and abs(self.cy - center[1]) < tol and abs(self.width - width) < tol and \
               abs(self.height - height) < tol and abs(self.angle - angle) < tol
1054675
function(coords) {
        var i, j, area = 0;
        for (i = 0; i < coords.length; i++) {
            j = (i + 1) % coords.length;
            area += coords[i][0] * coords[j][1];
            area -= coords[j][0] * coords[i][1];
        }
        return (area < 0);
    }
687319
def fitcircle(n, x, y): 
# n points, x points, y points
    """"""
    # adding in normalize vectors step
    #x = numpy.array(x) / max(x)
    #y = numpy.array(y) / max(y)
    #
    
    sx, sx2, sx3, sy, sy2, sy3, sxy, sxy2, syx2 = (0,) * 9
    print(type(sx), sx)
    for i in range(n):
        sx = sx + x[i]
        sx2 = sx2 + x[i]**2
        sx3 = sx3 + x[i]**3
        sy = sy + y[i]
        sy2 = sy2 + y[i]**2
        sy3 = sy3 + y[i]**3
        sxy = sxy + x[i] * y[i]
        sxy2 = sxy2 + x[i] * y[i]**2
        syx2 = syx2 + y[i] * x[i]**2

    A = n * sx2 - sx**2
    B = n * sxy - sx*sy
    C = n * sy2 - sy**2
    D = 0.5 * (n * sxy2 - sx * sy2 + n * sx3 - sx * sx2)
    E = 0.5 * (n * syx2 - sy * sx2 + n * sy3 - sy * sy2)
    # values check out up to here

    xo = old_div((D * C - B * E), (A * C - B**2))
    yo = old_div((A * E - B * D), (A * C - B**2))
    print("xo", xo)
    print("yo", yo)

    r = 0
    for z in range(n):
        r = r + old_div(numpy.sqrt( (x[z]-xo)**2 + (y[z]-yo)**2 ), n)

    if xo <= numpy.mean(x) and yo <= numpy.mean(y):
        k = old_div(-1.,r)
    else:
        k = old_div(1.,r)

    SSE = lib_k.get_SSE(xo, yo, r, x, y)
    print("r", r)
    return k, xo, yo, SSE
1031681
def inROI(self, Y):
        ''''''
        if Y.ndim > 1:
            area = np.zeros((Y.shape[0],4))
        else:
            area = np.zeros((1,4))
        pts = np.zeros((0,), int)
        pdist = np.zeros((0,), int)
        dist0 = 0
        for k in range(len(self.prect)):
            self.square_area = (triangle_area(self.prect[k][0,:], self.prect[k][1,:], self.prect[k][2,:]) +
                            triangle_area(self.prect[k][2,:], self.prect[k][3,:], self.prect[k][4,:]))
            for n in range(4):
                area[:,n] = triangle_area(self.prect[k][0+n,:], self.prect[k][1+n,:], Y)
            # points inside prect
            newpts = np.array((area.sum(axis=1) <= self.square_area+1e-5).nonzero()).flatten().astype(int)
            if newpts.size > 0:
                pts = np.concatenate((pts, newpts))
                newdists = self.orthproj(Y[newpts, :], k) + dist0
                pdist = np.concatenate((pdist, newdists))
            dist0 += (np.diff(self.pos[k], axis=0)[0,:]**2).sum()
            # check if in radius of circle
            if k < len(self.prect)-1:
                pcent = self.pos[k][1,:]
                dist = ((Y - pcent[np.newaxis,:])**2).sum(axis=1)**0.5
                newpts = np.array((dist<=self.d).nonzero()[0].astype(int))
                if newpts.size > 0:
                    pts = np.concatenate((pts, newpts))
                    newdists = dist0 * np.ones(newpts.shape)
                    pdist = np.concatenate((pdist, newdists))

        pts, inds = np.unique(pts, return_index=True)
        pdist = pdist[inds]
        return pts, pdist
144056
function distanceFromIntersectArea(r1, r2, overlap) {
        // handle complete overlapped circles
        if (Math.min(r1, r2) * Math.min(r1,r2) * Math.PI <= overlap + SMALL$1) {
            return Math.abs(r1 - r2);
        }

        return bisect(function(distance$$1) {
            return circleOverlap(r1, r2, distance$$1) - overlap;
        }, 0, r1 + r2);
    }
1204488
function normalize(vec3) {
    if (vec3.x === 0 && vec3.y === 0 && vec3.z === 0) {
        return vec3;
    }
    const length = Math.sqrt(vec3.x * vec3.x + vec3.y * vec3.y + vec3.z * vec3.z);
    const invScalar = 1 / length;
    vec3.x *= invScalar;
    vec3.y *= invScalar;
    vec3.z *= invScalar;
    return vec3;
}
1234798
function (x, y, r) {
            var attr = isObject(x) ?
                x :
              {
                  x: x,
                  y: y,
                  r: r
              },
              wrapper = this.createElement('circle');

            wrapper.xSetter = function (value) {
                this.element.setAttribute('cx', value);
            };
            wrapper.ySetter = function (value) {
                this.element.setAttribute('cy', value);
            };
            return wrapper.attr(attr);
        }
799072
function averageColorNormalized() {
	for (var _len = arguments.length, colors = Array(_len), _key = 0; _key < _len; _key++) {
		colors[_key] = arguments[_key];
	}

	// If a single colors array was provided as opposed to separate arguments
	// for each color, break it out.
	if (colors.length === 1 && Array.isArray(colors[0][0])) colors = colors[0];

	var N = colors.length;

	// Normalize the color components to range [0, 1].
	var normalizedColors = colors.map(function (_ref) {
		var _ref2 = _slicedToArray(_ref, 3),
		    h = _ref2[0],
		    s = _ref2[1],
		    l = _ref2[2];

		return [h / 360, s / 100, l / 100];
	});

	var cartesianAverage = normalizedColors
	// Cylindrical => Cartesian coordinates.
	.map(function (_ref3) {
		var _ref4 = _slicedToArray(_ref3, 3),
		    h = _ref4[0],
		    s = _ref4[1],
		    l = _ref4[2];

		return [s * cos(h * PI2), s * sin(h * PI2), l];
	})
	// Sum the scaled coordinates to find a centerpoint.
	.reduce(function (_ref5, _ref6) {
		var _ref8 = _slicedToArray(_ref5, 3),
		    xA = _ref8[0],
		    yA = _ref8[1],
		    zA = _ref8[2];

		var _ref7 = _slicedToArray(_ref6, 3),
		    x = _ref7[0],
		    y = _ref7[1],
		    z = _ref7[2];

		return [xA + x / N, yA + y / N, zA + z / N];
	}, [0, 0, 0]);

	// Convert the average hue value back to a positive polar angle.
	var H = (atan2(cartesianAverage[Y], cartesianAverage[X]) / PI2 + 1) % 1;

	// Take the arithmetic mean of all saturation values.
	var S = normalizedColors.map(function (_ref9) {
		var _ref10 = _slicedToArray(_ref9, 3),
		    h = _ref10[0],
		    s = _ref10[1],
		    l = _ref10[2];

		return s / N;
	}).reduce(sum);

	// Take the arithmetic mean of all lightness values.
	var L = cartesianAverage[2];

	return [H, S, L];
}
969073
function (ctx, x, y, radius, shadow) {
            // pi * r^2 = 2s^2  =>  s = r * sqrt(pi/2)
            var size = radius * Math.sqrt(Math.PI / 2);
            ctx.moveTo(x - size, y);
            ctx.lineTo(x, y - size);
            ctx.lineTo(x + size, y);
            ctx.lineTo(x, y + size);
            ctx.lineTo(x - size, y);
            ctx.lineTo(x, y - size);
        }
171171
def circle(self, clear_screen=True, x=50, y=50, radius=40, fill_color='black', outline_color='black'):
        

        if clear_screen:
            self.clear()

        x1 = x - radius
        y1 = y - radius
        x2 = x + radius
        y2 = y + radius

        return self.draw.ellipse((x1, y1, x2, y2), fill=fill_color, outline=outline_color)