Computes the center of the viewport's Mandelbrot-space coordinates.

    :param params: Current application parameters.
    :type params: params.Params
2850
def update_position(params):
    
    cx = params.plane_x0 + params.plane_w / 2.0
    cy = params.plane_y0 + params.plane_h / 2.0
    params.mb_cx, params.mb_cy = get_coords(cx, cy, params)
146849
def center(self, coords):
        
        x, y = round(coords[0]), round(coords[1])
        self.view_rect.center = x, y

        mw, mh = self.data.map_size
        tw, th = self.data.tile_size
        vw, vh = self._tile_view.size

        # prevent camera from exposing edges of the map
        if self.clamp_camera:
            self._anchored_view = True
            self.view_rect.clamp_ip(self.map_rect)
            x, y = self.view_rect.center

        # calc the new position in tiles and pixel offset
        left, self._x_offset = divmod(x - self._half_width, tw)
        top, self._y_offset = divmod(y - self._half_height, th)
        right = left + vw
        bottom = top + vh

        if not self.clamp_camera:
            # not anchored, so the rendered map is being offset by values larger
            # than the tile size.  this occurs when the edges of the map are inside
            # the screen.  a situation like is shows a background under the map.
            self._anchored_view = True
            dx = int(left - self._tile_view.left)
            dy = int(top - self._tile_view.top)

            if mw < vw or left < 0:
                left = 0
                self._x_offset = x - self._half_width
                self._anchored_view = False

            elif right > mw:
                left = mw - vw
                self._x_offset += dx * tw
                self._anchored_view = False

            if mh < vh or top < 0:
                top = 0
                self._y_offset = y - self._half_height
                self._anchored_view = False

            elif bottom > mh:
                top = mh - vh
                self._y_offset += dy * th
                self._anchored_view = False

        # adjust the view if the view has changed without a redraw
        dx = int(left - self._tile_view.left)
        dy = int(top - self._tile_view.top)
        view_change = max(abs(dx), abs(dy))

        if view_change and (view_change <= self._redraw_cutoff):
            self._buffer.scroll(-dx * tw, -dy * th)
            self._tile_view.move_ip(dx, dy)
            self._queue_edge_tiles(dx, dy)
            self._flush_tile_queue(self._buffer)

        elif view_change > self._redraw_cutoff:
            logger.info('scrolling too quickly.  redraw forced')
            self._tile_view.move_ip(dx, dy)
            self.redraw_tiles(self._buffer)
1293422
def compute_capture(args):
    x, y, w, h, params = args
    """"""
    return x, y, mandelbrot_capture(x, y, w, h, params)
1130846
function () {
            var cfg = this.cfg,
                fc = cfg.getProperty("fixedcenter");

            if (cfg.getProperty("visible")) {
                if (fc && (fc !== _CONTAINED || this.fitsInViewport())) {
                    this.center();
                }
            }
        }
667347
private Coordinate calcCenterFromPoint(final Coordinate worldCenter) {
		double xCenter = worldCenter.getX();
		double yCenter = worldCenter.getY();
		if (maxBounds != null) {
			Coordinate minCoordinate = maxBounds.getOrigin();
			Coordinate maxCoordinate = maxBounds.getEndPoint();

			if (BoundsLimitOption.COMPLETELY_WITHIN_MAX_BOUNDS.equals(viewBoundsLimitOption)) {
				/** View must lay completely within maxBounds. **/
				double w = getViewSpaceWidth() / 2;
				double h = getViewSpaceHeight() / 2;
	
				if ((w * 2) > maxBounds.getWidth()) {
					xCenter = maxBounds.getCenterPoint().getX();
				} else {
					if ((xCenter - w) < minCoordinate.getX()) {
						xCenter = minCoordinate.getX() + w;
					}
					if ((xCenter + w) > maxCoordinate.getX()) {
						xCenter = maxCoordinate.getX() - w;
					}
				}
				if ((h * 2) > maxBounds.getHeight()) {
					yCenter = maxBounds.getCenterPoint().getY();
				} else {
					if ((yCenter - h) < minCoordinate.getY()) {
						yCenter = minCoordinate.getY() + h;
					}
					if ((yCenter + h) > maxCoordinate.getY()) {
						yCenter = maxCoordinate.getY() - h;
					}
				}
			} else if (BoundsLimitOption.CENTER_WITHIN_MAX_BOUNDS.equals(viewBoundsLimitOption)) {
				/** Center of view must lay within maxBounds. **/
				Coordinate center = new Coordinate(xCenter, yCenter);
				if (!maxBounds.contains(center)) {
					if (xCenter < minCoordinate.getX()) {
						xCenter = minCoordinate.getX();
					} else if (xCenter > maxCoordinate.getX()) {
						xCenter = maxCoordinate.getX();
					}
					if (yCenter < minCoordinate.getY()) {
						yCenter = minCoordinate.getY();
					} else if (yCenter > maxCoordinate.getY()) {
						yCenter = maxCoordinate.getY();
					}
				}
			}
		}
		return new Coordinate(xCenter, yCenter);
	}
1125892
def get_center_offset(self):
        
        return (-self.view_rect.centerx + self._half_width,
                -self.view_rect.centery + self._half_height)
967365
function computeMirrorDimensions({source, ...args}) {
  return withPromise((resolve) => {
    const sourceRect = source.getBoundingClientRect();
    resolve({source, sourceRect, ...args});
  });
}
1033086
def center_image(self, no_reset=True):
        
        try:
            xy_mn, xy_mx = self.get_limits()
            data_x = float(xy_mn[0] + xy_mx[0]) / 2.0
            data_y = float(xy_mn[1] + xy_mx[1]) / 2.0

        except ImageViewNoDataError:
            # No data, so try to get center of any plotted objects
            canvas = self.get_canvas()
            try:
                data_x, data_y = canvas.get_center_pt()[:2]

            except Exception as e:
                self.logger.error("Can't compute center point: %s" % (str(e)))
                return

        self.panset_xy(data_x, data_y, no_reset=no_reset)

        if self.t_['autocenter'] == 'once':
            self.t_.set(autocenter='off')
1250852
def end_point_to_center_parameters(x1, y1, x2, y2, fA, fS, rx, ry, phi=0):
    '''
    
    '''
    rx = fabs(rx)
    ry = fabs(ry)

    # step 1
    if phi:
        phi_rad = radians(phi)
        sin_phi = sin(phi_rad)
        cos_phi = cos(phi_rad)
        tx = 0.5 * (x1 - x2)
        ty = 0.5 * (y1 - y2)
        x1d = cos_phi * tx - sin_phi * ty
        y1d = sin_phi * tx + cos_phi * ty
    else:
        x1d = 0.5 * (x1 - x2)
        y1d = 0.5 * (y1 - y2)

    # step 2
    # we need to calculate
    # (rx*rx*ry*ry-rx*rx*y1d*y1d-ry*ry*x1d*x1d)
    # -----------------------------------------
    #     (rx*rx*y1d*y1d+ry*ry*x1d*x1d)
    #
    # that is equivalent to
    #
    #          rx*rx*ry*ry
    # = -----------------------------  -    1
    #   (rx*rx*y1d*y1d+ry*ry*x1d*x1d)
    #
    #              1
    # = -------------------------------- - 1
    #   x1d*x1d/(rx*rx) + y1d*y1d/(ry*ry)
    #
    # = 1/r - 1
    #
    # it turns out r is what they recommend checking
    # for the negative radicand case
    r = x1d * x1d / (rx * rx) + y1d * y1d / (ry * ry)
    if r > 1:
        rr = sqrt(r)
        rx *= rr
        ry *= rr
        r = x1d * x1d / (rx * rx) + y1d * y1d / (ry * ry)
    elif r != 0:
        r = 1 / r - 1
    if -1e-10 < r < 0:
        r = 0
    r = sqrt(r)
    if fA == fS:
        r = -r
    cxd = (r * rx * y1d) / ry
    cyd = -(r * ry * x1d) / rx

    # step 3
    if phi:
        cx = cos_phi * cxd - sin_phi * cyd + 0.5 * (x1 + x2)
        cy = sin_phi * cxd + cos_phi * cyd + 0.5 * (y1 + y2)
    else:
        cx = cxd + 0.5 * (x1 + x2)
        cy = cyd + 0.5 * (y1 + y2)

    # step 4
    theta1 = vector_angle((1, 0), ((x1d - cxd) / rx, (y1d - cyd) / ry))
    dtheta = vector_angle(
        ((x1d - cxd) / rx, (y1d - cyd) / ry),
        ((-x1d - cxd) / rx, (-y1d - cyd) / ry)
    ) % 360
    if fS == 0 and dtheta > 0:
        dtheta -= 360
    elif fS == 1 and dtheta < 0:
        dtheta += 360
    return cx, cy, rx, ry, -theta1, -dtheta
1259670
function (params) {
        this.$id = 'graphic';
        this.$deps = []; // Position dependency added later if relative positioning is true.

        params = _.extend({
            alpha: 1,
            anchor: {
                x: 0.5,
                y: 0.5
            },
            relative: true,
            scale: {
                x: 1,
                y: 1
            },
            tint: 0xffffff,
            translate: {
                x: 0,
                y: 0
            },
            visible: true,
            z: 0
        }, params);

        if (params.relative) {
            this.$deps.push('position');
        }

        this.alpha = params.alpha;
        this.anchor = params.anchor;
        this.relative = params.relative;
        this.scale = params.scale;
        this.tint = params.tint;
        this.translate = params.translate;
        this.visible = params.visible;
        this.z = params.z;

    }
715927
def _map_center(self, coord, val):
        '''  '''

        if self.ppd in [4, 8, 16, 32, 64]:
            res = {'lat': 0, 'long': 360}
            return res[coord] / 2.0
        elif self.ppd in [128]:
            res = {'lat': 90, 'long': 90}
            return (val // res[coord] + 1) * res[coord] - res[coord] / 2.0
        elif self.ppd in [256]:
            res = {'lat': 60, 'long': 90}
            return (val // res[coord] + 1) * res[coord] - res[coord] / 2.0
423320
function () {
        if (!this.height) { return; }

        var cameraToCenterDistance = 0.5 / Math.tan(FOV / 2) * this.height * WORLD_SCALE;
        // Convert to radian.
        var pitch = Math.max(Math.min(this.pitch, this.maxPitch), 0) / 180 * Math.PI;

        // Find the distance from the center point [width/2, height/2] to the
        // center top point [width/2, 0] in Z units, using the law of sines.
        // 1 Z unit is equivalent to 1 horizontal px at the center of the map
        // (the distance between[width/2, height/2] and [width/2 + 1, height/2])
        var halfFov = FOV / 2;
        var groundAngle = Math.PI / 2 + pitch;
        var topHalfSurfaceDistance = Math.sin(halfFov) * cameraToCenterDistance / Math.sin(Math.PI - groundAngle - halfFov);

        // Calculate z distance of the farthest fragment that should be rendered.
        var furthestDistance = Math.cos(Math.PI / 2 - pitch) * topHalfSurfaceDistance + cameraToCenterDistance;
        // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
        var farZ = furthestDistance * 1.1;
        // Forced to be 1000
        if (this.pitch > 50) {
            farZ = 1000;
        }

        // matrix for conversion from location to GL coordinates (-1 .. 1)
        var m = [];
        mat4.perspective(m, FOV, this.width / this.height, 1, farZ);
        this.viewGL.camera.projectionMatrix.setArray(m);
        this.viewGL.camera.decomposeProjectionMatrix();

        var m = mat4.identity([]);
        var pt = this.dataToPoint(this.center);
        // Inverse
        mat4.scale(m, m, [1, -1, 1]);
        // Translate to altitude
        mat4.translate(m, m, [0, 0, -cameraToCenterDistance]);
        mat4.rotateX(m, m, pitch);
        mat4.rotateZ(m, m, -this.bearing / 180 * Math.PI);
        // Translate to center.
        mat4.translate(m, m, [-pt[0] * this.getScale() * WORLD_SCALE, -pt[1] * this.getScale() * WORLD_SCALE, 0]);

        this.viewGL.camera.viewMatrix.array = m;
        var invertM = [];
        mat4.invert(invertM, m);
        this.viewGL.camera.worldTransform.array = invertM;
        this.viewGL.camera.decomposeWorldTransform();

        // scale vertically to meters per pixel (inverse of ground resolution):
        // worldSize / (circumferenceOfEarth * cos(lat * π / 180))
        var worldSize = TILE_SIZE * this.getScale();
        var verticalScale;

        if (this.altitudeExtent && !isNaN(this.boxHeight)) {
            var range = this.altitudeExtent[1] - this.altitudeExtent[0];
            verticalScale = this.boxHeight / range * this.getScale() / Math.pow(2, this._initialZoom - this.zoomOffset);
        }
        else {
            verticalScale = worldSize / (2 * Math.PI * 6378000 * Math.abs(Math.cos(this.center[1] * (Math.PI / 180))))
                * this.altitudeScale * WORLD_SCALE;
        }
        // Include scale to avoid relayout when zooming
        // FIXME Camera scale may have problem in shadow
        this.viewGL.rootNode.scale.set(
            this.getScale() * WORLD_SCALE, this.getScale() * WORLD_SCALE, verticalScale
        );
    }
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
716535
def hyperbola(axes, **kwargs):
    
    opens_up = kwargs.pop('opens_up', True)
    center = kwargs.pop('center', defaults['center'])
    th = N.linspace(0,2*N.pi,kwargs.pop('n', 500))

    vals = [N.tan(th),1/N.cos(th)]
    if not opens_up:
        vals = vals[::-1]

    x = axes[0]*vals[0]+center[0]
    y = axes[1]*vals[1]+center[1]

    extrema = [N.argmin(x),N.argmax(x)]

    def remove_asymptotes(arr):
        arr[extrema] = N.nan
        return arr

    xy = tuple(remove_asymptotes(i) for i in (x,y))

    return xy
161646
function (x, y) {
            // Make position relative to object center point.
            x -= this.pos.x;
            y -= this.pos.y;
            // Pythagorean theorem.
            return (
                ((x * x) / this.radiusSq.x) +
                ((y * y) / this.radiusSq.y)
            ) <= 1.0;
        }
377343
def set_axis_centres(self, *args):
        
        for axis in self.axes_by_code.values():
            if isinstance(axis, CentredAxis):
                axis.centre = axis.value
586688
def LaplaceCentreWeight(self):
        """"""

        sz = [1,] * self.S.ndim
        for ax in self.axes:
            sz[ax] = self.S.shape[ax]
        lcw = 2*len(self.axes)*np.ones(sz, dtype=self.dtype)
        for ax in self.axes:
            lcw[(slice(None),)*ax + ([0, -1],)] -= 1.0
        return lcw