internal void FillMultiPath(com.epl.geometry.SimpleRasterizer rasterizer, com.epl.geometry.Transformation2D trans, com.epl.geometry.MultiPathImpl polygon, bool isWinding) { com.epl.geometry.SegmentIteratorImpl segIter = polygon.QuerySegmentIterator(); com.epl.geometry.Point2D p1 = new com.epl.geometry.Point2D(); com.epl.geometry.Point2D p2 = new com.epl.geometry.Point2D(); while (segIter.NextPath()) { while (segIter.HasNextSegment()) { com.epl.geometry.Segment seg = segIter.NextSegment(); if (seg.GetType() != com.epl.geometry.Geometry.Type.Line) { throw com.epl.geometry.GeometryException.GeometryInternalError(); } // TODO: // densify // the // segment // here trans.Transform(seg.GetStartXY(), p1); trans.Transform(seg.GetEndXY(), p2); m_rasterizer.AddEdge(p1.x, p1.y, p2.x, p2.y); } } m_rasterizer.RenderEdges(isWinding ? com.epl.geometry.SimpleRasterizer.WINDING : com.epl.geometry.SimpleRasterizer.EVEN_ODD); }
/// <summary>Sets this transformation to be a rotation around point rotationCenter.</summary> /// <remarks> /// Sets this transformation to be a rotation around point rotationCenter. /// When the axis Y is directed up and X is directed to the right, the /// positive angle corresponds to the anti-clockwise rotation. When the axis /// Y is directed down and X is directed to the right, the positive angle /// corresponds to the clockwise rotation. /// </remarks> /// <param name="cosA">The cos of the rotation angle.</param> /// <param name="sinA">The sin of the rotation angle.</param> /// <param name="rotationCenter">The center point of the rotation.</param> internal void SetRotate(double cosA, double sinA, com.epl.geometry.Point2D rotationCenter) { SetShift(-rotationCenter.x, -rotationCenter.y); com.epl.geometry.Transformation2D temp = new com.epl.geometry.Transformation2D(); temp.SetRotate(cosA, sinA); Multiply(temp); Shift(rotationCenter.x, rotationCenter.y); }
public override void ApplyTransformation(com.epl.geometry.Transformation2D transform) { if (IsEmptyImpl()) { return; } com.epl.geometry.Point2D pt = GetXY(); transform.Transform(pt, pt); SetXY(pt); }
/// <summary> /// Returns TRUE if this is an orthonormal transformation with the given /// tolerance. /// </summary> /// <remarks> /// Returns TRUE if this is an orthonormal transformation with the given /// tolerance. The orthonormal: Rotation or rotoinversion and shift /// (preserves lengths of vectors and angles between vectors). /// </remarks> /// <param name="tol">The tolerance value.</param> public bool IsOrthonormal(double tol) { com.epl.geometry.Transformation2D r = new com.epl.geometry.Transformation2D(); r.xx = xx * xx + xy * xy; r.xy = xx * yx + xy * yy; r.yx = yx * xx + yy * xy; r.yy = yx * yx + yy * yy; r.xd = 0; r.yd = 0; return(r.IsIdentity(tol)); }
/// <summary>Returns a copy of the Transformation2D object.</summary> /// <returns>A copy of this object.</returns> public com.epl.geometry.Transformation2D Copy() { com.epl.geometry.Transformation2D result = new com.epl.geometry.Transformation2D(); result.xx = xx; result.xy = xy; result.xd = xd; result.yx = yx; result.yy = yy; result.yd = yd; return(result); }
/// <summary> /// Returns True when all members of this transformation are equal to the /// corresponding members of the other. /// </summary> public override bool Equals(object other) { if (this == other) { return(true); } if (!(other is com.epl.geometry.Transformation2D)) { return(false); } com.epl.geometry.Transformation2D that = (com.epl.geometry.Transformation2D)other; return(xx == that.xx && xy == that.xy && xd == that.xd && yx == that.yx && yy == that.yy && yd == that.yd); }
public override void ApplyTransformation(com.epl.geometry.Transformation2D transform) { _touch(); com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); pt.x = m_xStart; pt.y = m_yStart; transform.Transform(pt, pt); m_xStart = pt.x; m_yStart = pt.y; pt.x = m_xEnd; pt.y = m_yEnd; transform.Transform(pt, pt); m_xEnd = pt.x; m_yEnd = pt.y; }
/// <summary> /// Produces inverse matrix for this matrix and puts result into the inverse /// parameter. /// </summary> /// <param name="inverse">The result inverse matrix.</param> public void Inverse(com.epl.geometry.Transformation2D inverse) { double det = xx * yy - xy * yx; if (det == 0) { inverse.SetZero(); return; } det = 1 / det; inverse.xd = (xy * yd - xd * yy) * det; inverse.yd = (xd * yx - xx * yd) * det; inverse.xx = yy * det; inverse.xy = -xy * det; inverse.yx = -yx * det; inverse.yy = xx * det; }
// Used for IsSimple. internal static bool NeedsCracking(bool allowCoincident, com.epl.geometry.EditShape shape, double tolerance, com.epl.geometry.NonSimpleResult result, com.epl.geometry.ProgressTracker progress_tracker) { if (!CanBeCracked(shape)) { return(false); } com.epl.geometry.Cracker cracker = new com.epl.geometry.Cracker(progress_tracker); cracker.m_shape = shape; cracker.m_tolerance = tolerance; cracker.m_bAllowCoincident = allowCoincident; if (cracker.NeedsCrackingImpl_()) { if (result != null) { result.Assign(cracker.m_non_simple_result); } return(true); } // Now swap the coordinates to catch horizontal cases. com.epl.geometry.Transformation2D transform = new com.epl.geometry.Transformation2D(); transform.SetSwapCoordinates(); shape.ApplyTransformation(transform); cracker = new com.epl.geometry.Cracker(progress_tracker); cracker.m_shape = shape; cracker.m_tolerance = tolerance; cracker.m_bAllowCoincident = allowCoincident; bool b_res = cracker.NeedsCrackingImpl_(); transform.SetSwapCoordinates(); shape.ApplyTransformation(transform); // restore shape if (b_res) { if (result != null) { result.Assign(cracker.m_non_simple_result); } return(true); } return(false); }
public override void ApplyTransformation(com.epl.geometry.Transformation2D transform) { if (IsEmpty()) { return; } _verifyAllStreams(); com.epl.geometry.AttributeStreamOfDbl points = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[0]; com.epl.geometry.Point2D pt2 = new com.epl.geometry.Point2D(); for (int ipoint = 0; ipoint < m_pointCount; ipoint++) { pt2.x = points.Read(ipoint * 2); pt2.y = points.Read(ipoint * 2 + 1); transform.Transform(pt2, pt2); points.Write(ipoint * 2, pt2.x); points.Write(ipoint * 2 + 1, pt2.y); } // REFACTOR: reset the exact envelope only and transform the loose // envelope NotifyModified(com.epl.geometry.MultiVertexGeometryImpl.DirtyFlags.DirtyCoordinates); }
/// <summary> /// Performs multiplication of matrices a and b and places the result into /// this matrix. /// </summary> /// <remarks> /// Performs multiplication of matrices a and b and places the result into /// this matrix. The a, b, and result could point to same objects. <br /> /// Equivalent to result = a * b. /// </remarks> /// <param name="a">The 2D transformation to be multiplied.</param> /// <param name="b">The 2D transformation to be multiplied.</param> /// <param name="result">The 2D transformation created by multiplication of matrices.</param> public static void Multiply(com.epl.geometry.Transformation2D a, com.epl.geometry.Transformation2D b, com.epl.geometry.Transformation2D result) { double xx; double xy; double xd; double yx; double yy; double yd; xx = a.xx * b.xx + a.yx * b.xy; xy = a.xy * b.xx + a.yy * b.xy; xd = a.xd * b.xx + a.yd * b.xy + b.xd; yx = a.xx * b.yx + a.yx * b.yy; yy = a.xy * b.yx + a.yy * b.yy; yd = a.xd * b.yx + a.yd * b.yy + b.yd; result.xx = xx; result.xy = xy; result.xd = xd; result.yx = yx; result.yy = yy; result.yd = yd; }
/// <summary>Shears the transformation.</summary> /// <param name="proportionX">The proportion of shearing in x direction.</param> /// <param name="proportionY">The proportion of shearing in y direction.</param> public void Shear(double proportionX, double proportionY) { com.epl.geometry.Transformation2D temp = new com.epl.geometry.Transformation2D(); temp.SetShear(proportionX, proportionY); Multiply(temp); }
internal void Init(com.epl.geometry.MultiVertexGeometryImpl geom, double toleranceXY, int rasterSizeBytes) { // _ASSERT(CanUseAccelerator(geom)); m_width = System.Math.Max((int)(System.Math.Sqrt(rasterSizeBytes) * 2 + 0.5), 64); m_scanLineSize = (m_width * 2 + 31) / 32; // 2 bits per pixel m_geomEnv = new com.epl.geometry.Envelope2D(); m_toleranceXY = toleranceXY; // calculate bitmap size int size = 0; int width = m_width; int scanLineSize = m_scanLineSize; while (width >= 8) { size += width * scanLineSize; width /= 2; scanLineSize = (width * 2 + 31) / 32; } // allocate the bitmap, that contains the base and the mip-levels m_bitmap = new int[size]; for (int i = 0; i < size; i++) { m_bitmap[i] = 0; } m_rasterizer = new com.epl.geometry.SimpleRasterizer(); com.epl.geometry.RasterizedGeometry2DImpl.ScanCallbackImpl callback = new com.epl.geometry.RasterizedGeometry2DImpl.ScanCallbackImpl(this, m_bitmap, m_scanLineSize); m_callback = callback; m_rasterizer.Setup(m_width, m_width, callback); geom.QueryEnvelope2D(m_geomEnv); if (m_geomEnv.GetWidth() > m_width * m_geomEnv.GetHeight() || m_geomEnv.GetHeight() > m_geomEnv.GetWidth() * m_width) { } // the geometry is thin and the rasterizer is not needed. m_geomEnv.Inflate(toleranceXY, toleranceXY); com.epl.geometry.Envelope2D worldEnv = new com.epl.geometry.Envelope2D(); com.epl.geometry.Envelope2D pixEnv = com.epl.geometry.Envelope2D.Construct(1, 1, m_width - 2, m_width - 2); double minWidth = toleranceXY * pixEnv.GetWidth(); // min width is such // that the size of // one pixel is // equal to the // tolerance double minHeight = toleranceXY * pixEnv.GetHeight(); worldEnv.SetCoords(m_geomEnv.GetCenter(), System.Math.Max(minWidth, m_geomEnv.GetWidth()), System.Math.Max(minHeight, m_geomEnv.GetHeight())); m_stroke_half_widthX_pix = worldEnv.GetWidth() / pixEnv.GetWidth(); m_stroke_half_widthY_pix = worldEnv.GetHeight() / pixEnv.GetHeight(); // The stroke half width. Later it will be inflated to account for // pixels size. m_stroke_half_width = m_toleranceXY; m_transform = new com.epl.geometry.Transformation2D(); m_transform.InitializeFromRect(worldEnv, pixEnv); // geom to pixels com.epl.geometry.Transformation2D identityTransform = new com.epl.geometry.Transformation2D(); switch (geom.GetType().Value()) { case com.epl.geometry.Geometry.GeometryType.MultiPoint: { callback.SetColor(m_rasterizer, 2); FillPoints(m_rasterizer, (com.epl.geometry.MultiPointImpl)geom, m_stroke_half_width); break; } case com.epl.geometry.Geometry.GeometryType.Polyline: { callback.SetColor(m_rasterizer, 2); StrokeDrawPolyPath(m_rasterizer, (com.epl.geometry.MultiPathImpl)geom._getImpl(), m_stroke_half_width); break; } case com.epl.geometry.Geometry.GeometryType.Polygon: { bool isWinding = false; // NOTE: change when winding is supported callback.SetColor(m_rasterizer, 1); FillMultiPath(m_rasterizer, m_transform, (com.epl.geometry.MultiPathImpl)geom, isWinding); callback.SetColor(m_rasterizer, 2); StrokeDrawPolyPath(m_rasterizer, (com.epl.geometry.MultiPathImpl)geom._getImpl(), m_stroke_half_width); break; } } m_dx = m_transform.xx; m_dy = m_transform.yy; m_x0 = m_transform.xd; m_y0 = m_transform.yd; BuildLevels(); }
/// <summary>Multiplies this matrix on the right with the "right" matrix.</summary> /// <remarks> /// Multiplies this matrix on the right with the "right" matrix. Stores the /// result into this matrix and returns a reference to it. <br /> /// Equivalent to this *= right. /// </remarks> /// <param name="right">The matrix to be multiplied with.</param> public void Multiply(com.epl.geometry.Transformation2D right) { Multiply(this, right, this); }
/// <summary>Multiplies this matrix on the left with the "left" matrix.</summary> /// <remarks> /// Multiplies this matrix on the left with the "left" matrix. Stores the /// result into this matrix and returns a reference to it. <br /> /// Equivalent to this = left * this. /// </remarks> /// <param name="left">The matrix to be multiplied with.</param> public void MulLeft(com.epl.geometry.Transformation2D left) { Multiply(left, this, this); }
/// <summary>Extracts scaling part of the transformation.</summary> /// <remarks> /// Extracts scaling part of the transformation. this == scale /// rotateNshearNshift. /// </remarks> /// <param name="scale">The destination matrix where the scale part is copied.</param> /// <param name="rotateNshearNshift"> /// The destination matrix where the part excluding rotation is /// copied. /// </param> public void ExtractScaleTransform(com.epl.geometry.Transformation2D scale, com.epl.geometry.Transformation2D rotateNshearNshift) { scale.SetScale(System.Math.Sqrt(xx * xx + xy * xy), System.Math.Sqrt(yx * yx + yy * yy)); rotateNshearNshift.SetScale(1.0 / scale.xx, 1.0 / scale.yy); rotateNshearNshift.Multiply(this); }
/// <summary>Rotates the transformation aroung a center point.</summary> /// <param name="cos">The cos angle of the rotation.</param> /// <param name="sin">sin angle of the rotation.</param> /// <param name="rotationCenter">The center point of the rotation.</param> public void Rotate(double cos, double sin, com.epl.geometry.Point2D rotationCenter) { com.epl.geometry.Transformation2D temp = new com.epl.geometry.Transformation2D(); temp.SetRotate(cos, sin, rotationCenter); Multiply(temp); }
/// <summary>Rotates the transformation.</summary> /// <param name="cos">The cos angle of the rotation.</param> /// <param name="sin">The sin angle of the rotation.</param> public void Rotate(double cos, double sin) { com.epl.geometry.Transformation2D temp = new com.epl.geometry.Transformation2D(); temp.SetRotate(cos, sin); Multiply(temp); }
public override void ApplyTransformation(com.epl.geometry.Transformation2D transform) { _touch(); transform.Transform(m_envelope); }
public override void ApplyTransformation(com.epl.geometry.Transformation2D transform) { m_impl.ApplyTransformation(transform); }
/// <summary>Applies 2D affine transformation in XY plane.</summary> /// <param name="transform">The affine transformation to be applied to this geometry.</param> public abstract void ApplyTransformation(com.epl.geometry.Transformation2D transform);
/// <summary>Rotates the transformation.</summary> /// <param name="angle_in_Radians">The rotation angle in radian.</param> public void Rotate(double angle_in_Radians) { com.epl.geometry.Transformation2D temp = new com.epl.geometry.Transformation2D(); temp.SetRotate(angle_in_Radians); Multiply(temp); }