Beispiel #1
0
 /// <summary>Creates an envelope by defining its center, width, and height.</summary>
 /// <param name="center">The center point of the envelope.</param>
 /// <param name="width">The width of the envelope.</param>
 /// <param name="height">The height of the envelope.</param>
 public Envelope(com.epl.geometry.Point center, double width, double height)
 {
     //We are using writeReplace instead.
     //private static final long serialVersionUID = 2L;
     // use doubles to store everything
     m_description = com.epl.geometry.VertexDescriptionDesignerImpl.GetDefaultDescriptor2D();
     m_envelope.SetEmpty();
     if (center.IsEmpty())
     {
         return;
     }
     _setFromPoint(center, width, height);
 }
 internal virtual void CalculateEnvelope2D(com.epl.geometry.Envelope2D env, bool bExact)
 {
     env.SetEmpty();
     com.epl.geometry.AttributeStreamOfDbl stream = (com.epl.geometry.AttributeStreamOfDbl)m_vertexAttributes[0];
     com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
     for (int i = 0; i < m_pointCount; i++)
     {
         stream.Read(2 * i, pt);
         env.Merge(pt);
     }
 }
Beispiel #3
0
 public override void QueryEnvelope2D(com.epl.geometry.Envelope2D env)
 {
     if (IsEmptyImpl())
     {
         env.SetEmpty();
         return;
     }
     env.xmin = m_attributes[0];
     env.ymin = m_attributes[1];
     env.xmax = m_attributes[0];
     env.ymax = m_attributes[1];
 }
Beispiel #4
0
 internal OperatorBufferCursor(com.epl.geometry.GeometryCursor inputGeoms, com.epl.geometry.SpatialReference sr, double[] distances, double max_deviation, int max_vertices, bool b_union, com.epl.geometry.ProgressTracker progress_tracker)
 {
     m_index         = -1;
     m_inputGeoms    = inputGeoms;
     m_max_deviation = max_deviation;
     m_max_vertices_in_full_circle = max_vertices;
     m_Spatial_reference           = (com.epl.geometry.SpatialReferenceImpl)(sr);
     m_distances = distances;
     m_currentUnionEnvelope2D = new com.epl.geometry.Envelope2D();
     m_currentUnionEnvelope2D.SetEmpty();
     m_dindex           = -1;
     m_progress_tracker = progress_tracker;
 }
 /// <summary>Sets the envelope from the attribute stream.</summary>
 /// <remarks>
 /// Sets the envelope from the attribute stream. The attribute stream stores
 /// interleaved x and y. The envelope will be set to empty if the pointCount
 /// is zero.
 /// </remarks>
 public void SetEnvelopeFromPoints(int pointCount, com.epl.geometry.Envelope2D inOutEnv)
 {
     if (pointCount == 0)
     {
         inOutEnv.SetEmpty();
         return;
     }
     if (pointCount < 0)
     {
         pointCount = Size() / 2;
     }
     else
     {
         if (pointCount * 2 > Size())
         {
             throw new System.ArgumentException();
         }
     }
     inOutEnv.SetCoords(Read(0), Read(1));
     for (int i = 1; i < pointCount; i++)
     {
         inOutEnv.MergeNE(Read(i * 2), Read(i * 2 + 1));
     }
 }
        internal void StrokeDrawPolyPath(com.epl.geometry.SimpleRasterizer rasterizer, com.epl.geometry.MultiPathImpl polyPath, double tol)
        {
            com.epl.geometry.Point2D[] fan = new com.epl.geometry.Point2D[4];
            for (int i = 0; i < fan.Length; i++)
            {
                fan[i] = new com.epl.geometry.Point2D();
            }
            com.epl.geometry.SegmentIteratorImpl segIter = polyPath.QuerySegmentIterator();
            double strokeHalfWidth = m_transform.Transform(tol) + 1.5;
            double shortSegment    = 0.25;

            com.epl.geometry.Point2D vec        = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D vecA       = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D vecB       = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D ptStart    = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D ptEnd      = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D prev_start = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D prev_end   = new com.epl.geometry.Point2D();
            double[] helper_xy_10_elm           = new double[10];
            com.epl.geometry.Envelope2D segEnv  = new com.epl.geometry.Envelope2D();
            com.epl.geometry.Point2D    ptOld   = new com.epl.geometry.Point2D();
            while (segIter.NextPath())
            {
                bool hasFan = false;
                bool first  = true;
                ptOld.SetCoords(0, 0);
                while (segIter.HasNextSegment())
                {
                    com.epl.geometry.Segment seg = segIter.NextSegment();
                    ptStart.x = seg.GetStartX();
                    ptStart.y = seg.GetStartY();
                    ptEnd.x   = seg.GetEndX();
                    ptEnd.y   = seg.GetEndY();
                    segEnv.SetEmpty();
                    segEnv.Merge(ptStart.x, ptStart.y);
                    segEnv.MergeNE(ptEnd.x, ptEnd.y);
                    if (!m_geomEnv.IsIntersectingNE(segEnv))
                    {
                        if (hasFan)
                        {
                            rasterizer.StartAddingEdges();
                            rasterizer.AddSegmentStroke(prev_start.x, prev_start.y, prev_end.x, prev_end.y, strokeHalfWidth, false, helper_xy_10_elm);
                            rasterizer.RenderEdges(com.epl.geometry.SimpleRasterizer.EVEN_ODD);
                            hasFan = false;
                        }
                        first = true;
                        continue;
                    }
                    m_transform.Transform(ptEnd, ptEnd);
                    if (first)
                    {
                        m_transform.Transform(ptStart, ptStart);
                        ptOld.SetCoords(ptStart);
                        first = false;
                    }
                    else
                    {
                        ptStart.SetCoords(ptOld);
                    }
                    prev_start.SetCoords(ptStart);
                    prev_end.SetCoords(ptEnd);
                    rasterizer.StartAddingEdges();
                    hasFan = !rasterizer.AddSegmentStroke(prev_start.x, prev_start.y, prev_end.x, prev_end.y, strokeHalfWidth, true, helper_xy_10_elm);
                    rasterizer.RenderEdges(com.epl.geometry.SimpleRasterizer.EVEN_ODD);
                    if (!hasFan)
                    {
                        ptOld.SetCoords(prev_end);
                    }
                }
                if (hasFan)
                {
                    rasterizer.StartAddingEdges();
                    hasFan = !rasterizer.AddSegmentStroke(prev_start.x, prev_start.y, prev_end.x, prev_end.y, strokeHalfWidth, false, helper_xy_10_elm);
                    rasterizer.RenderEdges(com.epl.geometry.SimpleRasterizer.EVEN_ODD);
                }
            }
        }
Beispiel #7
0
        private bool CrackBruteForce_()
        {
            com.epl.geometry.EditShape.VertexIterator iter_1 = m_shape.QueryVertexIterator(false);
            bool b_cracked = false;

            com.epl.geometry.Line       line_1    = new com.epl.geometry.Line();
            com.epl.geometry.Line       line_2    = new com.epl.geometry.Line();
            com.epl.geometry.Envelope2D seg_1_env = new com.epl.geometry.Envelope2D();
            seg_1_env.SetEmpty();
            com.epl.geometry.Envelope2D seg_2_env = new com.epl.geometry.Envelope2D();
            seg_2_env.SetEmpty();
            bool assume_intersecting = false;

            com.epl.geometry.Point helper_point = new com.epl.geometry.Point();
            com.epl.geometry.SegmentIntersector segment_intersector = new com.epl.geometry.SegmentIntersector();
            for (int vertex_1 = iter_1.Next(); vertex_1 != -1; vertex_1 = iter_1.Next())
            {
                com.epl.geometry.ProgressTracker.CheckAndThrow(m_progress_tracker);
                int GT_1 = m_shape.GetGeometryType(iter_1.CurrentGeometry());
                com.epl.geometry.Segment seg_1 = null;
                bool seg_1_zero = false;
                if (!com.epl.geometry.Geometry.IsPoint(GT_1))
                {
                    seg_1 = GetSegment_(vertex_1, line_1);
                    if (seg_1 == null)
                    {
                        continue;
                    }
                    seg_1.QueryEnvelope2D(seg_1_env);
                    seg_1_env.Inflate(m_tolerance, m_tolerance);
                    if (seg_1.IsDegenerate(m_tolerance))
                    {
                        // do not crack with
                        // degenerate segments
                        if (seg_1.IsDegenerate(0))
                        {
                            seg_1_zero = true;
                            seg_1      = null;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                com.epl.geometry.EditShape.VertexIterator iter_2 = m_shape.QueryVertexIterator(iter_1);
                int vertex_2 = iter_2.Next();
                if (vertex_2 != -1)
                {
                    vertex_2 = iter_2.Next();
                }
                for (; vertex_2 != -1; vertex_2 = iter_2.Next())
                {
                    int GT_2 = m_shape.GetGeometryType(iter_2.CurrentGeometry());
                    com.epl.geometry.Segment seg_2 = null;
                    bool seg_2_zero = false;
                    if (!com.epl.geometry.Geometry.IsPoint(GT_2))
                    {
                        seg_2 = GetSegment_(vertex_2, line_2);
                        if (seg_2 == null)
                        {
                            continue;
                        }
                        seg_2.QueryEnvelope2D(seg_2_env);
                        if (seg_2.IsDegenerate(m_tolerance))
                        {
                            // do not crack with
                            // degenerate segments
                            if (seg_2.IsDegenerate(0))
                            {
                                seg_2_zero = true;
                                seg_2      = null;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    int split_count_1 = 0;
                    int split_count_2 = 0;
                    if (seg_1 != null && seg_2 != null)
                    {
                        if (seg_1_env.IsIntersectingNE(seg_2_env))
                        {
                            segment_intersector.PushSegment(seg_1);
                            segment_intersector.PushSegment(seg_2);
                            segment_intersector.Intersect(m_tolerance, assume_intersecting);
                            split_count_1 = segment_intersector.GetResultSegmentCount(0);
                            split_count_2 = segment_intersector.GetResultSegmentCount(1);
                            if (split_count_1 + split_count_2 > 0)
                            {
                                m_shape.SplitSegment_(vertex_1, segment_intersector, 0, true);
                                m_shape.SplitSegment_(vertex_2, segment_intersector, 1, true);
                            }
                            segment_intersector.Clear();
                        }
                    }
                    else
                    {
                        if (seg_1 != null)
                        {
                            com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
                            m_shape.GetXY(vertex_2, pt);
                            if (seg_1_env.Contains(pt))
                            {
                                segment_intersector.PushSegment(seg_1);
                                m_shape.QueryPoint(vertex_2, helper_point);
                                segment_intersector.Intersect(m_tolerance, helper_point, 0, 1.0, assume_intersecting);
                                split_count_1 = segment_intersector.GetResultSegmentCount(0);
                                if (split_count_1 > 0)
                                {
                                    m_shape.SplitSegment_(vertex_1, segment_intersector, 0, true);
                                    if (seg_2_zero)
                                    {
                                        //seg_2 was zero length. Need to change all coincident points
                                        //segment at vertex_2 is dzero length, change all attached zero length segments
                                        int v_to = -1;
                                        for (int v = m_shape.GetNextVertex(vertex_2); v != -1 && v != vertex_2; v = m_shape.GetNextVertex(v))
                                        {
                                            seg_2 = GetSegment_(v, line_2);
                                            v_to  = v;
                                            if (seg_2 == null || !seg_2.IsDegenerate(0))
                                            {
                                                break;
                                            }
                                        }
                                        //change from vertex_2 to v_to (inclusive).
                                        for (int v_1 = vertex_2; v_1 != -1; v_1 = m_shape.GetNextVertex(v_1))
                                        {
                                            m_shape.SetPoint(v_1, segment_intersector.GetResultPoint());
                                            if (v_1 == v_to)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        m_shape.SetPoint(vertex_2, segment_intersector.GetResultPoint());
                                    }
                                }
                                segment_intersector.Clear();
                            }
                        }
                        else
                        {
                            if (seg_2 != null)
                            {
                                com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
                                m_shape.GetXY(vertex_1, pt);
                                seg_2_env.Inflate(m_tolerance, m_tolerance);
                                if (seg_2_env.Contains(pt))
                                {
                                    segment_intersector.PushSegment(seg_2);
                                    m_shape.QueryPoint(vertex_1, helper_point);
                                    segment_intersector.Intersect(m_tolerance, helper_point, 0, 1.0, assume_intersecting);
                                    split_count_2 = segment_intersector.GetResultSegmentCount(0);
                                    if (split_count_2 > 0)
                                    {
                                        m_shape.SplitSegment_(vertex_2, segment_intersector, 0, true);
                                        if (seg_1_zero)
                                        {
                                            //seg_1 was zero length. Need to change all coincident points
                                            //segment at vertex_2 is dzero length, change all attached zero length segments
                                            int v_to = -1;
                                            for (int v = m_shape.GetNextVertex(vertex_1); v != -1 && v != vertex_1; v = m_shape.GetNextVertex(v))
                                            {
                                                seg_2 = GetSegment_(v, line_2);
                                                //using here seg_2 for seg_1
                                                v_to = v;
                                                if (seg_2 == null || !seg_2.IsDegenerate(0))
                                                {
                                                    break;
                                                }
                                            }
                                            //change from vertex_2 to v_to (inclusive).
                                            for (int v_1 = vertex_1; v_1 != -1; v_1 = m_shape.GetNextVertex(v_1))
                                            {
                                                m_shape.SetPoint(v_1, segment_intersector.GetResultPoint());
                                                if (v_1 == v_to)
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            m_shape.SetPoint(vertex_1, segment_intersector.GetResultPoint());
                                        }
                                    }
                                    segment_intersector.Clear();
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    // points on points
                    if (split_count_1 + split_count_2 != 0)
                    {
                        if (split_count_1 != 0)
                        {
                            seg_1 = m_shape.GetSegment(vertex_1);
                            // reload segment
                            // after split
                            if (seg_1 == null)
                            {
                                if (!m_shape.QueryLineConnector(vertex_1, line_1))
                                {
                                    continue;
                                }
                                seg_1 = line_1;
                                line_1.QueryEnvelope2D(seg_1_env);
                            }
                            else
                            {
                                seg_1.QueryEnvelope2D(seg_1_env);
                            }
                            if (seg_1.IsDegenerate(m_tolerance))
                            {
                                // do not crack with
                                // degenerate
                                // segments
                                break;
                            }
                        }
                        b_cracked = true;
                    }
                }
            }
            return(b_cracked);
        }