/// <summary>
 /// Initializes an orhtonormal transformation from the Src and Dest
 /// rectangles.
 /// </summary>
 /// <remarks>
 /// Initializes an orhtonormal transformation from the Src and Dest
 /// rectangles.
 /// The result transformation proportionally fits the Src into the Dest. The
 /// center of the Src will be in the center of the Dest.
 /// </remarks>
 internal void InitializeFromRectIsotropic(com.epl.geometry.Envelope2D src, com.epl.geometry.Envelope2D dest)
 {
     if (src.IsEmpty() || dest.IsEmpty() || 0 == src.GetWidth() || 0 == src.GetHeight())
     {
         SetZero();
     }
     else
     {
         yx = 0;
         xy = 0;
         xx = dest.GetWidth() / src.GetWidth();
         yy = dest.GetHeight() / src.GetHeight();
         if (xx > yy)
         {
             xx = yy;
         }
         else
         {
             yy = xx;
         }
         com.epl.geometry.Point2D destCenter = dest.GetCenter();
         com.epl.geometry.Point2D srcCenter  = src.GetCenter();
         xd = destCenter.x - srcCenter.x * xx;
         yd = destCenter.y - srcCenter.y * yy;
     }
 }
예제 #2
0
 public virtual void TestEnvelope2D_corners()
 {
     com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(0, 1, 2, 3);
     NUnit.Framework.Assert.IsFalse(env.Equals(null));
     NUnit.Framework.Assert.IsTrue(env.Equals((object)new com.epl.geometry.Envelope2D(0, 1, 2, 3)));
     com.epl.geometry.Point2D pt2D = env.GetLowerLeft();
     NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(0, 1)));
     pt2D = env.GetUpperLeft();
     NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(0, 3)));
     pt2D = env.GetUpperRight();
     NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(2, 3)));
     pt2D = env.GetLowerRight();
     NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(2, 1)));
     {
         com.epl.geometry.Point2D[] corners = new com.epl.geometry.Point2D[4];
         env.QueryCorners(corners);
         NUnit.Framework.Assert.IsTrue(corners[0].Equals(com.epl.geometry.Point2D.Construct(0, 1)));
         NUnit.Framework.Assert.IsTrue(corners[1].Equals(com.epl.geometry.Point2D.Construct(0, 3)));
         NUnit.Framework.Assert.IsTrue(corners[2].Equals(com.epl.geometry.Point2D.Construct(2, 3)));
         NUnit.Framework.Assert.IsTrue(corners[3].Equals(com.epl.geometry.Point2D.Construct(2, 1)));
         env.QueryCorners(corners);
         NUnit.Framework.Assert.IsTrue(corners[0].Equals(env.QueryCorner(0)));
         NUnit.Framework.Assert.IsTrue(corners[1].Equals(env.QueryCorner(1)));
         NUnit.Framework.Assert.IsTrue(corners[2].Equals(env.QueryCorner(2)));
         NUnit.Framework.Assert.IsTrue(corners[3].Equals(env.QueryCorner(3)));
     }
     {
         com.epl.geometry.Point2D[] corners = new com.epl.geometry.Point2D[4];
         env.QueryCornersReversed(corners);
         NUnit.Framework.Assert.IsTrue(corners[0].Equals(com.epl.geometry.Point2D.Construct(0, 1)));
         NUnit.Framework.Assert.IsTrue(corners[1].Equals(com.epl.geometry.Point2D.Construct(2, 1)));
         NUnit.Framework.Assert.IsTrue(corners[2].Equals(com.epl.geometry.Point2D.Construct(2, 3)));
         NUnit.Framework.Assert.IsTrue(corners[3].Equals(com.epl.geometry.Point2D.Construct(0, 3)));
         env.QueryCornersReversed(corners);
         NUnit.Framework.Assert.IsTrue(corners[0].Equals(env.QueryCorner(0)));
         NUnit.Framework.Assert.IsTrue(corners[1].Equals(env.QueryCorner(3)));
         NUnit.Framework.Assert.IsTrue(corners[2].Equals(env.QueryCorner(2)));
         NUnit.Framework.Assert.IsTrue(corners[3].Equals(env.QueryCorner(1)));
     }
     NUnit.Framework.Assert.IsTrue(env.GetCenter().Equals(com.epl.geometry.Point2D.Construct(1, 2)));
     NUnit.Framework.Assert.IsFalse(env.ContainsExclusive(env.GetUpperLeft()));
     NUnit.Framework.Assert.IsTrue(env.Contains(env.GetUpperLeft()));
     NUnit.Framework.Assert.IsTrue(env.ContainsExclusive(env.GetCenter()));
 }
        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();
        }
예제 #4
0
 /// <summary>The x and y-coordinates of the center of the envelope.</summary>
 /// <returns>A point whose x and y-coordinates are that of the center of the envelope.</returns>
 public virtual com.epl.geometry.Point2D GetCenterXY()
 {
     return(m_envelope.GetCenter());
 }