public virtual GeoPosition convertPointToGeoPosition(Point2D paramPoint2D) { Rectangle rectangle = ViewportBounds; Point2D.Double double = new Point2D.Double(paramPoint2D.X + rectangle.X, paramPoint2D.Y + rectangle.Y); return(TileFactory.pixelToGeo(double, Zoom)); }
//############################################################################ // VECTOR MATH OPERATIONS //############################################################################ public Vector unitVector() { if (x + y != 0) { Point2D origin = new Point2D.Double(0, 0); Point2D endpoint = new Point2D.Double(x, y); double unitX = x / origin.distance(endpoint); double unitY = y / origin.distance(endpoint); return(new Vector(unitX, unitY)); } else { return(new Vector(0, 0)); } }
public static Point2D relativePointRotatedBy(Point2D p, double radians) { double returnX = p.getX(); double returnY = p.getY(); double cosineTheta = Math.cos(radians); double sineTheta = Math.sin(radians); Point2D returnPoint = new Point2D.Double( (returnX * cosineTheta - returnY * sineTheta), (returnX * sineTheta + returnY * cosineTheta) ); return(returnPoint); }
public static Line2D lineRotatedBy(Line2D line, double radians) { double returnX = line.getX2() - line.getX1(); double returnY = line.getY2() - line.getY1(); double cosineTheta = Math.cos(radians); double sineTheta = Math.sin(radians); Point2D returnPoint = new Point2D.Double( (returnX * cosineTheta - returnY * sineTheta), (returnX * sineTheta + returnY * cosineTheta) ); return(new Line2D.Double( 0, 0, returnPoint.getX(), returnPoint.getY() )); }
public virtual void calculateZoomFrom(ISet <GeoPosition> paramSet) { if (paramSet.Count < 2) { return; } int i = Zoom; Rectangle2D rectangle2D = generateBoundingRect(paramSet, i); sbyte b = 0; while (!ViewportBounds.contains(rectangle2D)) { Point2D.Double double = new Point2D.Double(rectangle2D.X + rectangle2D.Width / 2.0D, rectangle2D.Y + rectangle2D.Height / 2.0D); GeoPosition geoPosition = TileFactory.pixelToGeo(double, i); CenterPosition = geoPosition; if (++b > 30 || ViewportBounds.contains(rectangle2D) || ++i > 15) { break; } Zoom = i; rectangle2D = generateBoundingRect(paramSet, i); } }
public virtual void paintComponent(Graphics g) { Graphics2D graphics2D = (Graphics2D) g; graphics2D.setRenderingHint((RenderingHints.Key) RenderingHints.KEY_ANTIALIASING, (object) RenderingHints.VALUE_ANTIALIAS_ON); Dimension size = ((Component) this).getSize(); Insets insets = this.getInsets(); double num1 = (double) insets.left; double num2 = (double) insets.top; double num3 = size.getWidth() - (double) insets.left - (double) insets.right; double num4 = size.getHeight() - (double) insets.top - (double) insets.bottom; Point2D.Double double1 = new Point2D.Double(num1 + 6.0, num2 + num4 / 2.0); Point2D.Double double2 = new Point2D.Double(num1 + num3 - 6.0, num2 + num4 / 2.0); Ellipse2D.Double double3 = new Ellipse2D.Double(((Point2D) double1).getX() - 5.0, ((Point2D) double1).getY() - 5.0, 10.0, 10.0); Ellipse2D.Double double4 = new Ellipse2D.Double(((Point2D) double2).getX() - 6.0, ((Point2D) double2).getY() - 5.0, 10.0, 10.0); graphics2D.draw((Shape) double3); graphics2D.fill((Shape) double3); graphics2D.draw((Shape) double4); graphics2D.fill((Shape) double4); Line2D.Double double5 = new Line2D.Double((Point2D) double1, (Point2D) double2); if (this.stroke == null) return; graphics2D.setStroke(this.stroke); graphics2D.draw((Shape) double5); }
public static Point2D readPoint2D(ObjectInputStream stream) { if (stream == null) { string str = "Null 'stream' argument."; Throwable.__\u003CsuppressFillInStackTrace\u003E(); throw new IllegalArgumentException(str); } else { Point2D.Double @double = (Point2D.Double) null; if (!stream.readBoolean()) @double = new Point2D.Double(stream.readDouble(), stream.readDouble()); return (Point2D) @double; } }
public void paint(Graphics2D graphics){ Rectangle2D anchor = _shape.GetLogicalAnchor2D(); TextElement[] elem = GetTextElements((float)anchor.Width, graphics.GetFontRenderContext()); if(elem == null) return; float textHeight = 0; for (int i = 0; i < elem.Length; i++) { textHeight += elem[i].ascent + elem[i].descent; } int valign = _shape.GetVerticalAlignment(); double y0 = anchor.GetY(); switch (valign){ case TextShape.AnchorTopBaseline: case TextShape.AnchorTop: y0 += _shape.GetMarginTop(); break; case TextShape.AnchorBottom: y0 += anchor.Height - textHeight - _shape.GetMarginBottom(); break; default: case TextShape.AnchorMiddle: float delta = (float)anchor.Height - textHeight - _shape.GetMarginTop() - _shape.GetMarginBottom(); y0 += _shape.GetMarginTop() + delta/2; break; } //finally Draw the text fragments for (int i = 0; i < elem.Length; i++) { y0 += elem[i].ascent; Point2D.Double pen = new Point2D.Double(); pen.y = y0; switch (elem[i]._align) { default: case TextShape.AlignLeft: pen.x = anchor.GetX() + _shape.GetMarginLeft(); break; case TextShape.AlignCenter: pen.x = anchor.GetX() + _shape.GetMarginLeft() + (anchor.Width - elem[i].advance - _shape.GetMarginLeft() - _shape.GetMarginRight()) / 2; break; case TextShape.AlignRight: pen.x = anchor.GetX() + _shape.GetMarginLeft() + (anchor.Width - elem[i].advance - _shape.GetMarginLeft() - _shape.GetMarginRight()); break; } if(elem[i]._bullet != null){ graphics.DrawString(elem[i]._bullet.GetIterator(), (float)(pen.x + elem[i]._bulletOffset), (float)pen.y); } AttributedCharacterIterator chIt = elem[i]._text.GetIterator(); if(chIt.GetEndIndex() > chIt.GetBeginIndex()) { graphics.DrawString(chIt, (float)(pen.x + elem[i]._textOffset), (float)pen.y); } y0 += elem[i].descent; } }
public void transform(Point2D[] src, int srcOff, Point2D[] dst, int dstOff, int length) { while (--length >= 0) { Point2D srcPoint = src[srcOff++]; double x = srcPoint.getX(); double y = srcPoint.getY(); Point2D dstPoint = dst[dstOff]; if (dstPoint == null) { if (srcPoint is Point2D.Double) { dstPoint = new Point2D.Double(); } else { dstPoint = new Point2D.Float(); } } dstPoint.setLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); dst[dstOff++] = dstPoint; } }
public Point2D transform(Point2D src, Point2D dst) { if (dst == null) { if (src is Point2D.Double) { dst = new Point2D.Double(); } else { dst = new Point2D.Float(); } } double x = src.getX(); double y = src.getY(); dst.setLocation(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12); return dst; }
public Point2D inverseTransform(Point2D src, Point2D dst) { //throws NoninvertibleTransformException { double det = getDeterminant(); if (java.lang.Math.abs(det) < ZERO) { // awt.204=Determinant is zero throw new NoninvertibleTransformException("Determinant is zero"); //$NON-NLS-1$ } if (dst == null) { if (src is Point2D.Double) { dst = new Point2D.Double(); } else { dst = new Point2D.Float(); } } double x = src.getX() - m02; double y = src.getY() - m12; dst.setLocation((x * m11 - y * m01) / det, (y * m00 - x * m10) / det); return dst; }
public GradientPaintContext(ColorModel cm, Point2D p1, Point2D p2, AffineTransform xform, Color c1, Color c2, bool cyclic) { // First calculate the distance moved in user space when // we move a single unit along the X & Y axes in device space. Point2D xvec = new Point2D.Double(1, 0); Point2D yvec = new Point2D.Double(0, 1); try { AffineTransform inverse = xform.CreateInverse(); inverse.DeltaTransform(xvec, xvec); inverse.DeltaTransform(yvec, yvec); } catch (NoninvertibleTransformException) { xvec.SetLocation(0, 0); yvec.SetLocation(0, 0); } // Now calculate the (square of the) user space distance // between the anchor points. This value equals: // (UserVec . UserVec) double udx = p2.X - p1.X; double udy = p2.Y - p1.Y; double ulenSq = udx * udx + udy * udy; if (ulenSq <= Double.Epsilon) { Dx = 0; Dy = 0; } else { // Now calculate the proportional distance moved along the // vector from p1 to p2 when we move a unit along X & Y in // device space. // // The length of the projection of the Device Axis Vector is // its dot product with the Unit User Vector: // (DevAxisVec . (UserVec / Len(UserVec)) // // The "proportional" length is that length divided again // by the length of the User Vector: // (DevAxisVec . (UserVec / Len(UserVec))) / Len(UserVec) // which simplifies to: // ((DevAxisVec . UserVec) / Len(UserVec)) / Len(UserVec) // which simplifies to: // (DevAxisVec . UserVec) / LenSquared(UserVec) Dx = (xvec.X * udx + xvec.Y * udy) / ulenSq; Dy = (yvec.X * udx + yvec.Y * udy) / ulenSq; if (cyclic) { Dx = Dx % 1.0; Dy = Dy % 1.0; } else { // We are acyclic if (Dx < 0) { // If we are using the acyclic form below, we need // dx to be non-negative for simplicity of scanning // across the scan lines for the transition points. // To ensure that constraint, we negate the dx/dy // values and swap the points and colors. Point2D p = p1; p1 = p2; p2 = p; Color c = c1; c1 = c2; c2 = c; Dx = -Dx; Dy = -Dy; } } } Point2D dp1 = xform.Transform(p1, null); this.X1 = dp1.X; this.Y1 = dp1.Y; this.Cyclic = cyclic; int rgb1 = c1.RGB; int rgb2 = c2.RGB; int a1 = (rgb1 >> 24) & 0xff; int r1 = (rgb1 >> 16) & 0xff; int g1 = (rgb1 >> 8) & 0xff; int b1 = (rgb1) & 0xff; int da = ((rgb2 >> 24) & 0xff) - a1; int dr = ((rgb2 >> 16) & 0xff) - r1; int dg = ((rgb2 >> 8) & 0xff) - g1; int db = ((rgb2) & 0xff) - b1; if (a1 == 0xff && da == 0) { Model = Xrgbmodel; if (cm is DirectColorModel) { DirectColorModel dcm = (DirectColorModel)cm; int tmp = dcm.AlphaMask; if ((tmp == 0 || tmp == 0xff) && dcm.RedMask == 0xff && dcm.GreenMask == 0xff00 && dcm.BlueMask == 0xff0000) { Model = Xbgrmodel; tmp = r1; r1 = b1; b1 = tmp; tmp = dr; dr = db; db = tmp; } } } else { Model = ColorModel.RGBdefault; } Interp = new int[cyclic ? 513 : 257]; for (int i = 0; i <= 256; i++) { float rel = i / 256.0f; int rgb = (((int)(a1 + da * rel)) << 24) | (((int)(r1 + dr * rel)) << 16) | (((int)(g1 + dg * rel)) << 8) | (((int)(b1 + db * rel))); Interp[i] = rgb; if (cyclic) { Interp[512 - i] = rgb; } } }