public void ConvertToLoop(SmoothCurveElement curve, double tolerance = MathUtil.ZeroTolerance)
        {
            double dDelta = (curve.polyLine.Start - curve.polyLine.End).Length;

            if (dDelta < tolerance)
            {
                // handle degenerate element case
                if (curve.polyLine.VertexCount == 2)
                {
                    vElements.Remove(curve);
                    return;
                }

                // should always be one of these since we constructed it in append()
                if (curve.source is ParametricCurveSequence2)
                {
                    (curve.source as ParametricCurveSequence2).IsClosed = true;
                }
                else
                {
                    throw new Exception("PlanarComplex.ConvertToLoop: we have closed a loop but it is not a parametric seq??");
                }

                var loop = new SmoothLoopElement()
                {
                    ID     = id_generator++,
                    source = curve.source
                };
                vElements.Remove(curve);
                vElements.Add(loop);
                UpdateSampling(loop);
            }
        }
        void append(SmoothCurveElement cTo, SmoothCurveElement cAppend)
        {
            ParametricCurveSequence2 use = null;

            if (cTo.source is ParametricCurveSequence2)
            {
                use = cTo.source as ParametricCurveSequence2;
            }
            else
            {
                use = new ParametricCurveSequence2();
                use.Append(cTo.source);
            }

            if (cAppend.source is ParametricCurveSequence2)
            {
                var cseq = cAppend.source as ParametricCurveSequence2;
                foreach (var c in cseq.Curves)
                {
                    use.Append(c);
                }
            }
            else
            {
                use.Append(cAppend.source);
            }

            cTo.source = use;
            UpdateSampling(cTo);
        }
Exemple #3
0
 public Element Add(IParametricCurve2d curve)
 {
     if (curve.IsClosed)
     {
         SmoothLoopElement e = new SmoothLoopElement
         {
             ID     = id_generator++,
             source = curve
         };
         UpdateSampling(e);
         vElements.Add(e);
         return(e);
     }
     else
     {
         SmoothCurveElement e = new SmoothCurveElement
         {
             ID     = id_generator++,
             source = curve
         };
         UpdateSampling(e);
         vElements.Add(e);
         return(e);
     }
 }
            public override Element Clone()
            {
                var curve = new SmoothCurveElement();

                this.copy_to(curve);
                curve.polyLine = (this.polyLine == this.source) ? curve.source as PolyLine2d : new PolyLine2d(this.polyLine);
                return(curve);
            }
Exemple #5
0
        public void Add(PolyLine2d pline)
        {
            SmoothCurveElement e = new SmoothCurveElement();

            e.ID     = id_generator++;
            e.source = new PolyLine2DCurve()
            {
                Polyline = pline
            };
            e.polyLine = new PolyLine2d(pline);
            vElements.Add(e);
        }
 void UpdateSampling(SmoothCurveElement c)
 {
     if (MinimizeSampling && c.source is Segment2d)
     {
         c.polyLine = new PolyLine2d();
         c.polyLine.AppendVertex(((Segment2d)c.source).P0);
         c.polyLine.AppendVertex(((Segment2d)c.source).P1);
     }
     else
     {
         c.polyLine = new PolyLine2d(
             CurveSampler2.AutoSample(c.source, DistanceAccuracy, SpacingT));
     }
 }
 public void Add(IParametricCurve2d curve)
 {
     if (curve.IsClosed)
     {
         SmoothLoopElement e = new SmoothLoopElement();
         e.ID     = id_generator++;
         e.source = curve;
         UpdateSampling(e);
         vElements.Add(e);
     }
     else
     {
         SmoothCurveElement e = new SmoothCurveElement();
         e.ID     = id_generator++;
         e.source = curve;
         UpdateSampling(e);
         vElements.Add(e);
     }
 }
        // iterate through endpoints of open curves
        public IEnumerable <ComplexEndpoint2d> EndpointsItr()
        {
            foreach (Element e in vElements)
            {
                if (e is SmoothCurveElement)
                {
                    SmoothCurveElement s = e as SmoothCurveElement;
                    yield return(new ComplexEndpoint2d()
                    {
                        v = s.polyLine.Start, isStart = true, element = s
                    });

                    yield return(new ComplexEndpoint2d()
                    {
                        v = s.polyLine.End, isStart = false, element = s
                    });
                }
            }
        }
        public bool JoinElements(ComplexEndpoint2d a, ComplexEndpoint2d b)
        {
            if (a.element == b.element)
            {
                throw new Exception("PlanarComplex.ChainElements: same curve!!");
            }

            SmoothCurveElement c1 = a.element;
            SmoothCurveElement c2 = b.element;

            SmoothCurveElement joined = null;

            if (a.isStart == false && b.isStart == true)
            {
                vElements.Remove(c2);
                append(c1, c2);
                joined = c1;
            }
            else if (a.isStart == true && b.isStart == false)
            {
                vElements.Remove(c1);
                append(c2, c1);
                joined = c2;
            }
            else if (a.isStart == false)                                // end-to-end join
            {
                c2.source.Reverse();
                vElements.Remove(c2);
                append(c1, c2);
                joined = c1;
            }
            else if (a.isStart == true)                         // start-to-start join
            {
                c1.source.Reverse();
                vElements.Remove(c2);
                append(c1, c2);
                joined = c1;
            }

            if (joined != null)
            {
                // check if we have closed a loop
                double dDelta = (joined.polyLine.Start - joined.polyLine.End).Length;
                if (dDelta < MathUtil.ZeroTolerance)
                {
                    // should always be one of these since we constructed it in append()
                    if (joined.source is ParametricCurveSequence2)
                    {
                        (joined.source as ParametricCurveSequence2).IsClosed = true;
                    }
                    else
                    {
                        throw new Exception("PlanarComplex.JoinElements: we have closed a loop but it is not a parametric seq??");
                    }

                    SmoothLoopElement loop = new SmoothLoopElement()
                    {
                        ID = id_generator++, source = joined.source
                    };
                    vElements.Remove(joined);
                    vElements.Add(loop);
                    UpdateSampling(loop);
                }
                return(true);
            }

            return(false);
        }
 public void Reverse(SmoothCurveElement c)
 {
     c.source.Reverse();
     UpdateSampling(c);
 }