internal void GetAxisIntersections(RangeAxis2d gridAxis, Polygon2d polygon, ref PointAxis2d pointAxis)
        {
            if (polygon == null)
            {
                return;
            }

            List <Line2d> lines = polygon.Lines;

            if (lines == null)
            {
                return;
            }

            foreach (RangeAxis2d.Value axisValue in gridAxis.CreateExtentsList())
            {
                for (int index = 0; index < lines.Count; ++index)
                {
                    Line2d  test  = axisValue.ToLine(m_basis, gridAxis.Ordinal);
                    Line2d  other = lines[index];
                    Point2d point = test.Intersect(other, true);
                    if (PointIsValid(point, other))
                    {
                        pointAxis.Add(PointAxis2d.Value.FromPoint2d(m_basis, gridAxis.Ordinal, point, true));
                    }
                }
            }
        }
        public List <RangeAxis2d> GetExtentsAxes()
        {
            if (m_extents == null)
            {
                return(null);
            }

            if (m_extentsAxes == null)
            {
                RangeAxis2d yLines = new RangeAxis2d(m_basis, 0);
                int         minX   = m_basis.ToGrid(0, m_extents.Min.X);
                int         maxX   = m_basis.ToGrid(0, m_extents.Max.X);
                for (int x = minX; x <= maxX; ++x)
                {
                    yLines.Add(x, new Range1d(m_extents.Min.Y, m_extents.Max.Y));
                }

                RangeAxis2d xLines = new RangeAxis2d(m_basis, 1);
                int         minY   = m_basis.ToGrid(0, m_extents.Min.Y);
                int         maxY   = m_basis.ToGrid(0, m_extents.Max.Y);
                for (int y = minY; y <= maxY; ++y)
                {
                    xLines.Add(y, new Range1d(m_extents.Min.X, m_extents.Max.X));
                }

                m_extentsAxes = new List <RangeAxis2d>();
                m_extentsAxes.Add(yLines); // Ordinal 0
                m_extentsAxes.Add(xLines); // Ordinal 1
            }

            return(m_extentsAxes);
        }
        internal RangeAxis2d GetAxisSegments(PointAxis2d intersections)
        {
            int         ordinal           = intersections.Ordinal;
            RangeAxis2d collinearSegments = new RangeAxis2d(m_basis, ordinal);

            foreach (Polygon2d polygon in m_outline.Polygons)
            {
                foreach (Line2d line in polygon.Lines)
                {
                    RangeAxis2d.Value value = RangeAxis2d.Value.FromLine2d(m_basis, ordinal, line, false);
                    if (value != null)
                    {
                        collinearSegments.Add(value);
                    }
                }
            }

            RangeAxis2d segments = new RangeAxis2d(m_basis, ordinal);

            foreach (KeyValuePair <int, List <double> > value in intersections.Points)
            {
                int           abscissa  = value.Key;
                List <double> ordinates = value.Value;

                if (ordinates.Count < 2)
                {
                    continue;
                }

                for (int index = 0; index < ordinates.Count - 1;)
                {
                    double first = ordinates[index++];
                    double next  = ordinates[index++];

                    if (index < ordinates.Count)
                    {
                        Range1d segment = collinearSegments.Contains(new PointAxis2d.Value(abscissa, next));
                        if (segment != null && ordinates.Count % 3 == 0)
                        {
                            next = ordinates[index++];
                        }
                    }

                    segments.Add(abscissa, new Range1d(first, next));
                }
            }

            return(segments);
        }
        public RangeAxis2d TrimToGrid(RangeAxis2d other)
        {
            RangeAxis2d axis = new RangeAxis2d(this, other.Ordinal);

            foreach (KeyValuePair <int, List <Range1d> > segments in other.Lines)
            {
                foreach (Range1d segment in segments.Value)
                {
                    double p0 = Ceiling(axis.Ordinal, segment.Min);
                    double p1 = Floor(axis.Ordinal, segment.Max);
                    axis.Add(segments.Key, new Range1d(p0, p1));
                }
            }

            return(axis);
        }
Ejemplo n.º 5
0
        internal void OutputAxis(ref string text, GridBasis basis, int ordinal, RangeAxis2d axis)
        {
            string tag = "axis";

            OutputHeader(ref text, tag);
            IndentIn();

            foreach (KeyValuePair <int, List <Range1d> > lineData in axis.Lines)
            {
                foreach (Range1d range in lineData.Value)
                {
                    int v0 = basis.ToGrid(ordinal, range.Min);
                    int v1 = basis.ToGrid(ordinal, range.Max);
                    OutputTextLine(ref text, "seg " + EncodeInt(lineData.Key) + " " + EncodeInt(v0) + " " + EncodeInt(v1));
                }
            }

            IndentOut();
            OutputFooter(ref text, tag);
        }
        internal List <RangeAxis2d> GetGridAxes()
        {
            if (m_axes == null)
            {
                List <RangeAxis2d> basicGridAxes     = GetExtentsAxes();
                List <PointAxis2d> gridIntersections = GetGridLineIntersections(basicGridAxes);
                if (gridIntersections == null)
                {
                    return(null);
                }

                m_axes = new List <RangeAxis2d>();
                foreach (PointAxis2d axisIntersections in gridIntersections)
                {
                    RangeAxis2d segments = GetAxisSegments(axisIntersections);
                    m_axes.Add(m_basis.TrimToGrid(segments));
                }
            }

            return(m_axes);
        }