示例#1
0
 GraphNode(int index, ConvexPolygon polygon, PolyType t, List <int> siblings)
 {
     Idx      = index;
     Poly     = polygon;
     Type     = t;
     Siblings = siblings;
 }
        private void DropNewThing(PolyType newShape, double newSize, Color newColor)
        {
            // Only drop within the center "square" area
            double fDropWidth = (sceneRect.Bottom - sceneRect.Top);

            if (fDropWidth > sceneRect.Right - sceneRect.Left)
            {
                fDropWidth = sceneRect.Right - sceneRect.Left;
            }

            var newThing = new Thing()
            {
                size               = newSize,
                yVelocity          = (0.5 * rnd.NextDouble() - 0.25) / targetFrameRate,
                xVelocity          = 0,
                shape              = newShape,
                center             = new Point(rnd.NextDouble() * fDropWidth + (sceneRect.Left + sceneRect.Right - fDropWidth) / 2, sceneRect.Top - newSize),
                spinRate           = (rnd.NextDouble() * 12.0 - 6.0) * 2.0 * Math.PI / targetFrameRate / 4.0,
                theta              = 0,
                timeLastHit        = DateTime.MinValue,
                avgTimeBetweenHits = 100,
                color              = newColor,
                brush              = null,
                brush2             = null,
                brushPulse         = null,
                dissolve           = 0,
                state              = ThingState.Falling,
                touchedBy          = 0,
                hotness            = 0,
                flashCount         = 0
            };

            things.Add(newThing);
        }
 public void Add(IEnumerable <IPolygon2D> polygons, PolyType type)
 {
     foreach (var polygon in polygons)
     {
         this.Add(polygon, type);
     }
 }
示例#4
0
 private void AddPoints(Clipper clipper, IEnumerable <IShape> shapes, PolyType polyType)
 {
     foreach (IShape shape in shapes)
     {
         this.AddPoints(clipper, shape, polyType);
     }
 }
示例#5
0
        private void DropNewThing(PolyType newShape, double newSize, System.Windows.Media.Color newColor)
        {
            // Only drop within the center "square" area
            double dropWidth = this.sceneRect.Bottom - this.sceneRect.Top;

            if (dropWidth > this.sceneRect.Right - this.sceneRect.Left)
            {
                dropWidth = this.sceneRect.Right - this.sceneRect.Left;
            }

            var newThing = new Spider
            {
                Size               = newSize,
                YVelocity          = ((0.5 * this.rnd.NextDouble()) - 0.25) / this.targetFrameRate,
                XVelocity          = 0,
                Shape              = newShape,
                Center             = new System.Windows.Point((this.rnd.NextDouble() * dropWidth) + ((this.sceneRect.Left + this.sceneRect.Right - dropWidth) / 2), this.sceneRect.Top - newSize),
                SpinRate           = ((this.rnd.NextDouble() * 12.0) - 6.0) * 2.0 * Math.PI / this.targetFrameRate / 4.0,
                Theta              = 0,
                TimeLastHit        = DateTime.MinValue,
                AvgTimeBetweenHits = 100,
                Color              = newColor,
                Brush              = null,
                Brush2             = null,
                BrushPulse         = null,
                Dissolve           = 0,
                State              = ThingState.Falling,
                TouchedBy          = 0,
                Hotness            = 0,
                FlashCount         = 0
            };

            this.things.Add(newThing);
        }
示例#6
0
        private void DropNewThing(PolyType newShape, double newSize, Color newColor)
        {
            // Only drop within the center "square" area
            double dropWidth = _sceneRect.Bottom - _sceneRect.Top;

            if (dropWidth > _sceneRect.Right - _sceneRect.Left)
            {
                dropWidth = _sceneRect.Right - _sceneRect.Left;
            }

            var newThing = new Thing
            {
                Size               = newSize,
                YVelocity          = ((0.5 * _rnd.NextDouble()) - 0.25) / _targetFrameRate,
                XVelocity          = 0,
                Shape              = newShape,
                Center             = new Point((_rnd.NextDouble() * dropWidth) + ((_sceneRect.Left + _sceneRect.Right - dropWidth) / 2), _sceneRect.Top - newSize),
                TimeLastHit        = DateTime.MinValue,
                AvgTimeBetweenHits = 100,
                Color              = newColor,
                Brush              = null,
                Brush2             = null,
                BrushPulse         = null,
                Dissolve           = 0,
                State              = ThingState.Falling,
                Hotness            = 0,
                FlashCount         = 0
            };

            _things.Add(newThing);
        }
示例#7
0
        public void AddPath(Region region, PolyType polyType)
        {
            if (region == null || region.points == null)
            {
                return;
            }
            int             count  = region.points.Length;
            List <IntPoint> points = new List <IntPoint> (count);

            for (int k = 0; k < count; k++)
            {
                float    ix = region.points [k].x * MULTIPLIER;
                float    iy = region.points [k].y * MULTIPLIER;
                IntPoint p  = new IntPoint(ix, iy);
                points.Add(p);
            }
            AddPath(points, polyType, true);

            if (polyType == PolyType.ptSubject)
            {
                subject = region;
                if (subjects == null)
                {
                    subjects = new List <Region>();
                }
                subjects.Add(region);
            }
        }
        private void AddRegion(IRegion2D r, PolyType polyType)
        {
            var polygons = CreatePolygons(r);

            foreach (var poly in polygons)
            {
                this.clipper.AddPath(poly, polyType, true);
            }
        }
示例#9
0
        public void AddPaths(List <Region> regions, PolyType polyType)
        {
            int regionCount = regions.Count;

            for (int k = 0; k < regionCount; k++)
            {
                AddPath(regions [k], polyType);
            }
        }
示例#10
0
        public bool AddPath(IEnumerable <Point2d> poly, PolyType type, bool closed)
        {
            bool ret = this.clipper.AddPath(poly.Select(p => this.converter.ToIntPoint(p)).ToList(), type, closed);

            if (!ret)
            {
                Debug.WriteLine("Error in clipper.AddPath");
            }
            return(ret);
        }
示例#11
0
 /// <summary>
 /// Adds iText
 /// <see cref="iText.Kernel.Geom.Path"/>
 /// to the given
 /// <see cref="Clipper"/>
 /// object.
 /// </summary>
 /// <param name="clipper">
 /// The
 /// <see cref="Clipper"/>
 /// object.
 /// </param>
 /// <param name="path">
 /// The
 /// <see cref="iText.Kernel.Geom.Path"/>
 /// object to be added to the
 /// <see cref="Clipper"/>.
 /// </param>
 /// <param name="polyType">
 /// See
 /// <see cref="PolyType"/>.
 /// </param>
 public static void AddPath(Clipper clipper, Path path, PolyType polyType)
 {
     foreach (Subpath subpath in path.GetSubpaths())
     {
         if (!subpath.IsSinglePointClosed() && !subpath.IsSinglePointOpen())
         {
             IList <Point> linearApproxPoints = subpath.GetPiecewiseLinearApproximation();
             clipper.AddPath(new List <IntPoint>(ConvertToLongPoints(linearApproxPoints)), polyType, subpath.IsClosed());
         }
     }
 }
示例#12
0
        private void DropNewThing(PolyType newShape, double newSize, System.Windows.Media.Color newColor, double shoulderX, double shoulderY)
        {
            // Only drop within the center "square" area
            //double dropWidth = this.sceneRect.Bottom - this.sceneRect.Top;
            //if (dropWidth > this.sceneRect.Right - this.sceneRect.Left)
            //{
            //    dropWidth = this.sceneRect.Right - this.sceneRect.Left;
            //}
            if (shoulderX == 0)
            {
                shoulderX = (this.sceneRect.Left + this.sceneRect.Right) / 2;
            }
            double dropLeft   = shoulderX - 50;
            double dropRight  = shoulderX + 50;
            double dropHeight = this.sceneRect.Bottom - this.sceneRect.Top;

            double num   = this.rnd.NextDouble();
            double xDrop = 0;

            if (this.rnd.Next(0, 2) == 0)
            {
                xDrop = num * (dropLeft - this.sceneRect.Left - newSize) + this.sceneRect.Left + newSize;
            }
            else
            {
                xDrop = num * (this.sceneRect.Right - newSize - dropRight) + dropRight;
            }

            var newThing = new Thing
            {
                Size = newSize,
                //YVelocity = ((0.5 * this.rnd.NextDouble()) - 0.25) / this.targetFrameRate,
                YVelocity = 0.5 * this.rnd.NextDouble() + 0.5,
                XVelocity = 0.5 * this.rnd.NextDouble() + 0.5,
                Shape     = newShape,
                Center    = new System.Windows.Point(xDrop, (this.rnd.NextDouble() * dropHeight) + ((this.sceneRect.Top + this.sceneRect.Bottom - dropHeight) / 2)),
                SpinRate  = ((this.rnd.NextDouble() * 12.0) - 6.0) * 2.0 * Math.PI / this.targetFrameRate / 4.0,
                //SpinRate = 0,
                Theta              = 0,
                TimeLastHit        = DateTime.MinValue,
                AvgTimeBetweenHits = 100,
                Color              = newColor,
                Brush              = null,
                Brush2             = null,
                BrushPulse         = null,
                Dissolve           = 0,
                State              = ThingState.Falling,
                TouchedBy          = 0,
                Hotness            = 0,
                FlashCount         = 0
            };

            this.things.Add(newThing);
        }
示例#13
0
 private void PolyTypeFlagChanged(PolyType flag)
 {
     if ((flag | EditorMaterial.materialPolyTypes) != PolyType.None) //if this changes any flag of the material we have to change material
     {
         Material = new EditorMaterial(Material.TexturePath, info.polyType, Material.TransVal);
     }
     if (flag == PolyType.QUAD)
     {
         UpdateMesh();
     }
 }
示例#14
0
        public void Add(IPolyLine2D polyline, PolyType type)
        {
            if (!this.containsCircArc)
            {
                this.containsCircArc |= polyline.Segments.FirstOrDefault(s => s is CircularArcSegment2D) != null;
            }

            var p = CreatePolygon(polyline, this.Discretizator, false);

            this.clipper.AddPath(p, type, polyline.IsClosed);
        }
示例#15
0
        public bool AddPaths <TPoly>(IEnumerable <TPoly> polys, PolyType type, bool closed)
            where TPoly : IEnumerable <Point2d>
        {
            bool ret = this.clipper.AddPaths(polys.Select(poly => poly.Select(p => this.converter.ToIntPoint(p)).ToList()).ToList(), type, closed);

            if (!ret)
            {
                Debug.WriteLine("Error in clipper.AddPaths");
            }
            return(ret);
        }
示例#16
0
 public void RemoveShape(PolyType shape)
 {
     for (int thingIndex = 0; thingIndex < this.things.Count; thingIndex++)
     {
         Thing thing = this.things[thingIndex];
         if (thing.Shape == shape)
         {
             this.things.Remove(thing);
             thingIndex--;
         }
     }
 }
示例#17
0
        private PolyType GetPolyType()
        {
            PolyType type = 0;

            foreach (var v in lstType.CheckedItems)
            {
                var tmp = (PolyType)Enum.Parse(typeof(PolyType), v.ToString());
                type |= tmp;
            }

            return(type);
        }
示例#18
0
 void SetPolyType(PolyType type)
 {
     for (int i = 0; i < lstType.Items.Count; i++)
     {
         var v = lstType.Items[i];
         lstType.SetItemChecked(i, false);
         var itemPolyType = (PolyType)Enum.Parse(typeof(PolyType), v.ToString());
         if (type.HasFlag(itemPolyType))
         {
             lstType.SetItemChecked(i, true);
         }
     }
 }
        public bool AddPaths(List <List <IntPoint> > ppg, PolyType polyType, bool closed)
        {
            bool result = false;

            for (int i = 0; i < ppg.Count; i++)
            {
                if (AddPath(ppg[i], polyType, closed))
                {
                    result = true;
                }
            }
            return(result);
        }
示例#20
0
        //------------------------------------------------------------------------------

        public bool AddPolygons(List <List <IntPoint> > ppg, PolyType polyType)
        {
            bool result = false;

            for (int i = 0; i < ppg.Count; ++i)
            {
                if (AddPath(ppg[i], polyType, true))
                {
                    result = true;
                }
            }
            return(result);
        }
    public void AddPolygon(List <Vector2> polygon, PolyType type)
    {
        List <IntPoint> preparedPolygon = new List <IntPoint>();

        foreach (Vector2 origVertice in polygon)
        {
            Vector2  multipliedVector = ClipperUnitsPerUnityUnit * origVertice;
            Vector2  rounded          = new Vector2((float)Math.Round(multipliedVector.x), (float)Math.Round(multipliedVector.y));
            IntPoint preparedVertice  = new IntPoint((int)rounded.x, (int)rounded.y);
            preparedPolygon.Add(preparedVertice);
        }
        TheClipper.AddPolygon(preparedPolygon, type);
    }
示例#22
0
        static TriangleHelper.PolygonType ConvertType(PolyType type)
        {
            switch (type)
            {
            case PolyType.QUADS: return(TriangleHelper.PolygonType.Quad);

            case PolyType.QUAD_STRIP: return(TriangleHelper.PolygonType.QuadStrip);

            case PolyType.TRIANGLES: return(TriangleHelper.PolygonType.Triangle);

            case PolyType.TRIANGLE_STRIP: return(TriangleHelper.PolygonType.TriangleStrip);
            }
            return(TriangleHelper.PolygonType.Triangle);
        }
 private void InitEdge2(TEdge e, PolyType polyType)
 {
     if (e.Curr.Y >= e.Next.Curr.Y)
     {
         e.Bot = e.Curr;
         e.Top = e.Next.Curr;
     }
     else
     {
         e.Top = e.Curr;
         e.Bot = e.Next.Curr;
     }
     SetDx(e);
     e.PolyTyp = polyType;
 }
示例#24
0
        /// <summary>
        /// Get the hash code for this object
        /// </summary>
        ///
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            int prime  = 31;
            int result = 1;

            result = prime * result + N;
            result = prime * result + (_fastFp ? 1231 : 1237);
            result = prime * result + ((FP == null) ? 0 : FP.GetHashCode());
            result = prime * result + PolyType.GetHashCode();
            result = prime * result + Q;
            result = prime * result + (_sparse ? 1231 : 1237);
            result = prime * result + ((T == null) ? 0 : T.GetHashCode());

            return(result);
        }
示例#25
0
        public void AddPath(Region region, PolyType polyType)
        {
            if (region == null)
            {
                return;
            }
            int             count  = region.latlon.Length;
            List <IntPoint> points = new List <IntPoint> (count);

            for (int k = 0; k < count; k++)
            {
                IntPoint p = new IntPoint(region.latlon [k].x * MULTIPLIER, region.latlon [k].y * MULTIPLIER);
                points.Add(p);
            }
            AddPath(points, polyType, true);
        }
示例#26
0
        /// <summary>
        ///     Joins all the polygones.
        ///     ClipType: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/ClipType.htm
        ///     PolyFillType: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/PolyFillType.htm
        /// </summary>
        /// <param name="sList">The s list.</param>
        /// <param name="cType">Type of the c.</param>
        /// <param name="pType">Type of the p.</param>
        /// <param name="pFType1">The p f type1.</param>
        /// <param name="pFType2">The p f type2.</param>
        /// <returns></returns>
        public static List <Polygon> JoinPolygons(
            this List <Polygon> sList,
            ClipType cType,
            PolyType pType       = PolyType.ptClip,
            PolyFillType pFType1 = PolyFillType.pftNonZero,
            PolyFillType pFType2 = PolyFillType.pftNonZero)
        {
            var p     = ClipPolygons(sList);
            var tList = new List <List <IntPoint> >();

            var c = new Clipper();

            c.AddPaths(p, pType, true);
            c.Execute(cType, tList, pFType1, pFType2);

            return(ToPolygons(tList));
        }
示例#27
0
        /// <summary>
        /// Adds the path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="clippingType">Type of the poly.</param>
        /// <exception cref="ClipperException">AddPath: Open paths have been disabled.</exception>
        internal void AddPath(ISimplePath path, ClippingType clippingType)
        {
            var             vectors = path.Points;
            List <IntPoint> points  = new List <ClipperLib.IntPoint>(vectors.Length);

            foreach (var v in vectors)
            {
                points.Add(new IntPoint(v.X * ScalingFactor, v.Y * ScalingFactor));
            }

            PolyType type = clippingType == ClippingType.Clip ? PolyType.ptClip : PolyType.ptSubject;

            lock (this.syncRoot)
            {
                this.innerClipper.AddPath(points, type, path.IsClosed, path);
            }
        }
        /// <summary>
        /// Reset all fields to default values in preparation for object recycling
        /// </summary>
        public void PrepareForRecycle()
        {
            PolyTyp = PolyType.Subject;
            Side    = EdgeSide.Left;

            Bot = Curr = Top = Delta = new IntPoint();

            Dx        = 0;
            WindDelta = 0;
            WindCnt   = 0;
            WindCnt2  = 0;
            OutIdx    = 0;

            Next      = Prev = null;
            PrevInAEL = PrevInSEL = null;
            NextInLML = NextInAEL = NextInSEL = null;
        }
示例#29
0
 private void AddPoints(Clipper clipper, IShape shape, PolyType polyType)
 {
     // if the path is already the shape use it directly and skip the path loop.
     if (shape is IPath)
     {
         clipper.AddPath(
             (IPath)shape,
             polyType);
     }
     else
     {
         foreach (IPath path in shape)
         {
             clipper.AddPath(
                 path,
                 polyType);
         }
     }
 }
示例#30
0
        public void AddPath(Vector2[] points, PolyType polyType)
        {
            if (points == null)
            {
                return;
            }
            if (polyType == PolyType.ptSubject)
            {
                Debug.LogError("Subject polytype needs a Region object.");
                return;
            }
            int             count     = points.Length;
            List <IntPoint> newPoints = new List <IntPoint> (count);

            for (int k = 0; k < count; k++)
            {
                float    ix = points [k].x * MULTIPLIER;
                float    iy = points [k].y * MULTIPLIER;
                IntPoint p  = new IntPoint(ix, iy);
                newPoints.Add(p);
            }
            AddPath(newPoints, polyType, true);
        }
示例#31
0
      //------------------------------------------------------------------------------

      private void InitEdge2(TEdge e, PolyType polyType)
      {
        if (e.Curr.Y >= e.Next.Curr.Y)
        {
          e.Bot = e.Curr;
          e.Top = e.Next.Curr;
        }
        else
        {
          e.Top = e.Curr;
          e.Bot = e.Next.Curr;
        }
        SetDx(e);
        e.PolyTyp = polyType;
      }
示例#32
0
        private void DropNewThing(PolyType newShape, double newSize, Color newColor, int number)
        {
            // Only drop within the center "square" area 
            double dropWidth = _sceneRect.Bottom - _sceneRect.Top;
            if (dropWidth > _sceneRect.Right - _sceneRect.Left)
            {
                dropWidth = _sceneRect.Right - _sceneRect.Left;
            }

            var newThing = new Thing
            {
                Size = newSize,
                YVelocity = ((0.5 * _rnd.NextDouble()) - 0.25) / _targetFrameRate,
                XVelocity = 0,
                Shape = newShape,
                Center = new Point((_rnd.NextDouble() * dropWidth) + ((_sceneRect.Left + _sceneRect.Right - dropWidth) / 2), _sceneRect.Top - newSize),
                TimeLastHit = DateTime.MinValue,
                AvgTimeBetweenHits = 100,
                Color = newColor,
                Brush = null,
                Brush2 = null,
                BrushPulse = null,
                Dissolve = 0,
                State = ThingState.Falling,
                Hotness = 0,
                FlashCount = 0,
                Number = number
            };
            if (BubblesFallen < _maxBubbles)
            {
                _things.Add(newThing);
                BubblesFallen++;
            }
        }
示例#33
0
 //------------------------------------------------------------------------------
 public void AddPolygons(Polygons ppg, PolyType polyType)
 {
     for (int i = 0; i < ppg.Count; ++i)
         AddPolygon(ppg[i], polyType);
 }
示例#34
0
        /// <summary>
        ///     Joins all the polygones.
        ///     ClipType: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/ClipType.htm
        ///     PolyFillType: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/PolyFillType.htm
        /// </summary>
        /// <param name="sList">The s list.</param>
        /// <param name="cType">Type of the c.</param>
        /// <param name="pType">Type of the p.</param>
        /// <param name="pFType1">The p f type1.</param>
        /// <param name="pFType2">The p f type2.</param>
        /// <returns></returns>
        public static List<Polygon> ELJoinPolygons(this List<Polygon> sList, ClipType cType,
            PolyType pType = PolyType.ptClip, PolyFillType pFType1 = PolyFillType.pftNonZero,
            PolyFillType pFType2 = PolyFillType.pftNonZero)
        {
            var p = ELClipPolygons(sList);
            var tList = new List<List<IntPoint>>();

            var c = new Clipper();
            c.AddPaths(p, pType, true);
            c.Execute(cType, tList, pFType1, pFType2);

            return ToPolygons(tList);
        }
示例#35
0
        //------------------------------------------------------------------------------
        public bool AddPath(List<IntPoint> pg, PolyType polyType, bool Closed)
        {
            #if use_lines
              if (!Closed && polyType == PolyType.ptClip)
            throw new ClipperException("AddPath: Open paths must be subject.");
            #else
            if (!Closed)
                throw new ClipperException("AddPath: Open paths have been disabled.");
            #endif

            int highI = (int)pg.Count - 1;
            if (Closed) while (highI > 0 && (pg[highI] == pg[0])) --highI;
            while (highI > 0 && (pg[highI] == pg[highI - 1])) --highI;
            if ((Closed && highI < 2) || (!Closed && highI < 1)) return false;

            //create a new edge array ...
            List<TEdge> edges = new List<TEdge>(highI + 1);
            for (int i = 0; i <= highI; i++) edges.Add(new TEdge());

            bool IsFlat = true;

            //1. Basic (first) edge initialization ...
            edges[1].Curr = pg[1];
            RangeTest(pg[0], ref m_UseFullRange);
            RangeTest(pg[highI], ref m_UseFullRange);
            InitEdge(edges[0], edges[1], edges[highI], pg[0]);
            InitEdge(edges[highI], edges[0], edges[highI - 1], pg[highI]);
            for (int i = highI - 1; i >= 1; --i)
            {
                RangeTest(pg[i], ref m_UseFullRange);
                InitEdge(edges[i], edges[i + 1], edges[i - 1], pg[i]);
            }
            TEdge eStart = edges[0];

            //2. Remove duplicate vertices, and (when closed) collinear edges ...
            TEdge E = eStart, eLoopStop = eStart;
            for (;;)
            {
                //nb: allows matching start and end points when not Closed ...
                if (E.Curr == E.Next.Curr && (Closed || E.Next != eStart))
                {
                    if (E == E.Next) break;
                    if (E == eStart) eStart = E.Next;
                    E = RemoveEdge(E);
                    eLoopStop = E;
                    continue;
                }
                if (E.Prev == E.Next)
                    break; //only two vertices
                else if (Closed &&
                  SlopesEqual(E.Prev.Curr, E.Curr, E.Next.Curr, m_UseFullRange) &&
                  (!PreserveCollinear ||
                  !Pt2IsBetweenPt1AndPt3(E.Prev.Curr, E.Curr, E.Next.Curr)))
                {
                    //Collinear edges are allowed for open paths but in closed paths
                    //the default is to merge adjacent collinear edges into a single edge.
                    //However, if the PreserveCollinear property is enabled, only overlapping
                    //collinear edges (ie spikes) will be removed from closed paths.
                    if (E == eStart) eStart = E.Next;
                    E = RemoveEdge(E);
                    E = E.Prev;
                    eLoopStop = E;
                    continue;
                }
                E = E.Next;
                if ((E == eLoopStop) || (!Closed && E.Next == eStart)) break;
            }

            if ((!Closed && (E == E.Next)) || (Closed && (E.Prev == E.Next)))
                return false;

            if (!Closed)
            {
                m_HasOpenPaths = true;
                eStart.Prev.OutIdx = Skip;
            }

            //3. Do second stage of edge initialization ...
            E = eStart;
            do
            {
                InitEdge2(E, polyType);
                E = E.Next;
                if (IsFlat && E.Curr.Y != eStart.Curr.Y) IsFlat = false;
            }
            while (E != eStart);

            //4. Finally, add edge bounds to LocalMinima list ...

            //Totally flat paths must be handled differently when adding them
            //to LocalMinima list to avoid endless loops etc ...
            if (IsFlat)
            {
                if (Closed) return false;
                E.Prev.OutIdx = Skip;
                LocalMinima locMin = new LocalMinima();
                locMin.Next = null;
                locMin.Y = E.Bot.Y;
                locMin.LeftBound = null;
                locMin.RightBound = E;
                locMin.RightBound.Side = EdgeSide.esRight;
                locMin.RightBound.WindDelta = 0;
                for (;;)
                {
                    if (E.Bot.X != E.Prev.Top.X) ReverseHorizontal(E);
                    if (E.Next.OutIdx == Skip) break;
                    E.NextInLML = E.Next;
                    E = E.Next;
                }
                InsertLocalMinima(locMin);
                m_edges.Add(edges);
                return true;
            }

            m_edges.Add(edges);
            bool leftBoundIsForward;
            TEdge EMin = null;

            //workaround to avoid an endless loop in the while loop below when
            //open paths have matching start and end points ...
            if (E.Prev.Bot == E.Prev.Top) E = E.Next;

            for (;;)
            {
                E = FindNextLocMin(E);
                if (E == EMin) break;
                else if (EMin == null) EMin = E;

                //E and E.Prev now share a local minima (left aligned if horizontal).
                //Compare their slopes to find which starts which bound ...
                LocalMinima locMin = new LocalMinima();
                locMin.Next = null;
                locMin.Y = E.Bot.Y;
                if (E.Dx < E.Prev.Dx)
                {
                    locMin.LeftBound = E.Prev;
                    locMin.RightBound = E;
                    leftBoundIsForward = false; //Q.nextInLML = Q.prev
                }
                else
                {
                    locMin.LeftBound = E;
                    locMin.RightBound = E.Prev;
                    leftBoundIsForward = true; //Q.nextInLML = Q.next
                }
                locMin.LeftBound.Side = EdgeSide.esLeft;
                locMin.RightBound.Side = EdgeSide.esRight;

                if (!Closed) locMin.LeftBound.WindDelta = 0;
                else if (locMin.LeftBound.Next == locMin.RightBound)
                    locMin.LeftBound.WindDelta = -1;
                else locMin.LeftBound.WindDelta = 1;
                locMin.RightBound.WindDelta = -locMin.LeftBound.WindDelta;

                E = ProcessBound(locMin.LeftBound, leftBoundIsForward);
                if (E.OutIdx == Skip) E = ProcessBound(E, leftBoundIsForward);

                TEdge E2 = ProcessBound(locMin.RightBound, !leftBoundIsForward);
                if (E2.OutIdx == Skip) E2 = ProcessBound(E2, !leftBoundIsForward);

                if (locMin.LeftBound.OutIdx == Skip)
                    locMin.LeftBound = null;
                else if (locMin.RightBound.OutIdx == Skip)
                    locMin.RightBound = null;
                InsertLocalMinima(locMin);
                if (!leftBoundIsForward) E = E2;
            }
            return true;
        }
示例#36
0
        public void AddPolygons(IEnumerable<List<IntPoint>> ppg, PolyType polyType)
        {
            Contract.Requires(ppg != null);
            Contract.Requires(Contract.ForAll(ppg, a => a != null));

            foreach (var poly in ppg)
                AddPolygon(poly, polyType);
        }
示例#37
0
        private static void InitEdge(TEdge e, TEdge eNext, TEdge ePrev, IntPoint pt, PolyType polyType)
        {
            Contract.Requires(e != null);
            Contract.Requires(eNext != null);

            e.Next = eNext;
            e.Prev = ePrev;
            e.XCurr = pt.X;
            e.YCurr = pt.Y;
            if (e.YCurr >= e.Next.YCurr)
            {
                e.XBot = e.XCurr;
                e.YBot = e.YCurr;
                e.XTop = e.Next.XCurr;
                e.YTop = e.Next.YCurr;
                e.WindDelta = 1;
            }
            else
            {
                e.XTop = e.XCurr;
                e.YTop = e.YCurr;
                e.XBot = e.Next.XCurr;
                e.YBot = e.Next.YCurr;
                e.WindDelta = -1;
            }
            SetDx(e);
            e.PolyType = polyType;
            e.OutIdx = -1;
        }
示例#38
0
        public void AddPolygon(IReadOnlyList<IntPoint> pg, PolyType polyType)
        {
            Contract.Requires(pg != null);

            var len = pg.Count;
            if (len < 3)
                return;

            var maxVal = HI_RANGE;
            InternalHelpers.RangeTest(pg[0], ref maxVal);

            var p = new List<IntPoint>(len) { new IntPoint(pg[0].X, pg[0].Y) };
            var j = 0;
            for (var i = 1; i < len; ++i)
            {
                InternalHelpers.RangeTest(pg[i], ref maxVal);
                if (p[j].Equals(pg[i]))
                    continue;
                else if (j > 0 && InternalHelpers.SlopesEqual(p[j - 1], p[j], pg[i]))
                {
                    if (p[j - 1].Equals(pg[i]))
                        j--;
                }
                else
                    j++;
                if (j < p.Count)
                    p[j] = pg[i];
                else
                    p.Add(new IntPoint(pg[i].X, pg[i].Y));
            }
            if (j < 2)
                return;

            len = j + 1;
            while (len > 2)
            {
                //nb: test for point equality before testing slopes ...
                if (p[j].Equals(p[0]))
                    j--;
                else if (p[0].Equals(p[1]) || InternalHelpers.SlopesEqual(p[j], p[0], p[1]))
                    p[0] = p[j--];
                else if (InternalHelpers.SlopesEqual(p[j - 1], p[j], p[0]))
                    j--;
                else if (InternalHelpers.SlopesEqual(p[0], p[1], p[2]))
                {
                    for (var i = 2; i <= j; ++i)
                        p[i - 1] = p[i];
                    j--;
                }
                else
                    break;
                len--;
            }
            if (len < 3)
                return;

            //create a new edge array ...
            var edges = new List<TEdge>(len);
            for (var i = 0; i < len; i++)
                edges.Add(new TEdge());
            Edges.Add(edges);

            //convert vertices to a double-linked-list of edges and initialize ...
            edges[0].XCurr = p[0].X;
            edges[0].YCurr = p[0].Y;
            InitEdge(edges[len - 1], edges[0], edges[len - 2], p[len - 1], polyType);
            for (var i = len - 2; i > 0; --i)
                InitEdge(edges[i], edges[i + 1], edges[i - 1], p[i], polyType);
            InitEdge(edges[0], edges[1], edges[len - 1], p[0], polyType);

            //reset xcurr & ycurr and find 'eHighest' (given the Y axis coordinates
            //increase downward so the 'highest' edge will have the smallest ytop) ...
            var e = edges[0];
            var eHighest = e;
            do
            {
                e.XCurr = e.XBot;
                e.YCurr = e.YBot;
                if (e.YTop < eHighest.YTop)
                    eHighest = e;
                e = e.Next;
            } while (e != edges[0]);

            //make sure eHighest is positioned so the following loop works safely ...
            if (eHighest.WindDelta > 0)
                eHighest = eHighest.Next;
            if (eHighest.Dx == HORIZONTAL)
                eHighest = eHighest.Next;

            //finally insert each local minima ...
            e = eHighest;
            do
            {
                e = AddBoundsToLML(e);
            } while (e != eHighest);
        }
示例#39
0
        public void DropNewThing(PolyType newShape, double newSize, double appleLocation ,Color newColor, UIElementCollection children, String word /*, List<ShoopDoup.Models.DataObject> data*/)
        {
            // Only drop within the center "square" area
            double dropX;
            double fDropWidth = (sceneRect.Bottom - sceneRect.Top);
            if (fDropWidth > sceneRect.Right - sceneRect.Left)
                fDropWidth = sceneRect.Right - sceneRect.Left;
            if (appleLocation == 0)
            {
                dropX = rnd.NextDouble() * fDropWidth + (sceneRect.Left + sceneRect.Right - fDropWidth) / 2;
                while(Math.Abs(dropX-lastDropLocation)<150)
                {
                    dropX = rnd.NextDouble() * fDropWidth + (sceneRect.Left + sceneRect.Right - fDropWidth) / 2;
                }
                lastDropLocation = dropX;

            }
            else
            {
                dropX = appleLocation;
            }

            var newThing = new Thing()
            {
                size = 125,
                yVelocity = (0.5 * rnd.NextDouble() - 0.25) / targetFrameRate,
                xVelocity = 0,
                shape = newShape,
                center = new Point(dropX, sceneRect.Top - newSize),
                spinRate = (rnd.NextDouble() * 12.0 - 6.0) * 2.0 * Math.PI / targetFrameRate / 4.0,
                theta = 0,
                timeLastHit = DateTime.MinValue,
                avgTimeBetweenHits = 100,
                color = newColor,
                brush = null,
                brush2 = null,
                brushPulse = null,
                dissolve = 0,
                state = ThingState.Falling,
                touchedBy = 0,
                hotness = 0,
                flashCount = 0,
            };
            things.Add(newThing);

            String text = word;

            if (word == null)
            {
                int randomLabel = rnd.Next(0, textLabels.Count - 1);
                 text = textLabels[randomLabel];

                while (usedLabels.Contains(text))
                {
                    if (usedLabels.Count > textLabels.Count - 5)
                    {
                        usedLabels.Clear();
                    }
                    randomLabel = rnd.Next(0, textLabels.Count - 1);
                    text = textLabels[randomLabel];
                }
                usedLabels.Add(text);
            }

            Label label = new Label();
            TextBlock bubbleTextBlock = new TextBlock();
            bubbleTextBlock.Text = text;
            SolidColorBrush appleColor = new SolidColorBrush();
            appleColor.Color = Color.FromArgb(255, 227, 50, 50);
            bubbleTextBlock.Foreground=appleColor;
            Viewbox bubbleViewBox = new Viewbox();
            bubbleViewBox.Stretch = Stretch.Uniform;
            bubbleViewBox.Height = 80;
            bubbleViewBox.Width = 100;
            bubbleViewBox.Child = bubbleTextBlock;
            label.Content = bubbleViewBox;
            appleLabels.Add(label);

            children.Add(label);

            children.Add(makeApple(PolyDefs[newThing.shape].numSides, PolyDefs[newThing.shape].skip,
            newThing.size, newThing.theta, newThing.center, newThing.brush,
            newThing.brushPulse, newThing.size * 0.1, 0));
        }
示例#40
0
        public void DropNewThing(PolyType newShape, double newSize, System.Windows.Media.Color newColor)
        {
            // Only drop within the center "square" area 
            double dropWidth = this.sceneRect.Bottom - this.sceneRect.Top;
            if (dropWidth > this.sceneRect.Right - this.sceneRect.Left)
            {
                dropWidth = this.sceneRect.Right - this.sceneRect.Left;
            }

            var newThing = new Thing
            {
                Size = newSize,
                YVelocity = ((0.5 * this.rnd.NextDouble()) - 0.25) / this.targetFrameRate,
                XVelocity = 0,
                Shape = newShape,
                Center = new System.Windows.Point((this.rnd.NextDouble() * dropWidth) + ((this.sceneRect.Left + this.sceneRect.Right - dropWidth) / 2), this.sceneRect.Top - newSize),
                SpinRate = ((this.rnd.NextDouble() * 12.0) - 6.0) * 2.0 * Math.PI / this.targetFrameRate / 4.0,
                Theta = 0,
                TimeLastHit = DateTime.MinValue,
                AvgTimeBetweenHits = 100,
                Color = newColor,
                Brush = null,
                Brush2 = null,
                BrushPulse = null,
                Dissolve = 0,
                State = ThingState.Falling,
                TouchedBy = 0,
                Hotness = 0,
                FlashCount = 0
            };

            this.things.Add(newThing);
        }
示例#41
0
        private void DropNewThing(PolyType newShape, double newSize, Color newColor)
        {
            // Only drop within the center "square" area 
            double fDropWidth = (sceneRect.Bottom - sceneRect.Top);
            if (fDropWidth > sceneRect.Right - sceneRect.Left)
                fDropWidth = sceneRect.Right - sceneRect.Left;

            var newThing = new Thing()
            {
                size = newSize,
                yVelocity = (0.5 * rnd.NextDouble() - 0.25) / targetFrameRate,
                xVelocity = 0,
                shape = newShape,
                center = new Point(rnd.NextDouble() * fDropWidth + (sceneRect.Left + sceneRect.Right - fDropWidth) / 2, sceneRect.Top - newSize),
                spinRate = (rnd.NextDouble() * 12.0 - 6.0) * 2.0 * Math.PI / targetFrameRate / 4.0,
                theta = 0,
                timeLastHit = DateTime.MinValue,
                avgTimeBetweenHits = 100,
                color = newColor,
                brush = null,
                brush2 = null,
                brushPulse = null,
                dissolve = 0,
                state = ThingState.Falling,
                touchedBy = 0,
                hotness = 0,
                flashCount = 0
            };

            things.Add(newThing);
        }
示例#42
0
 public void SetPolies(PolyType polies)
 {
     polyTypes = polies;
 }
 //------------------------------------------------------------------------------
 public bool AddPolygons(Polygons ppg, PolyType polyType)
 {
     bool result = false;
     for (int i = 0; i < ppg.Count; ++i)
         if (AddPolygon(ppg[i], polyType)) result = true;
     return result;
 }
示例#44
0
      //------------------------------------------------------------------------------

#if use_deprecated
      public bool AddPolygon(Path pg, PolyType polyType)
      {
        return AddPath(pg, polyType, true);
      }
示例#45
0
 private static void AddRect(Clipper clipper, Point2D[] rectVertices, PolyType polyType) {
     clipper.AddPath(ConvertToIntPoints(new List<Point2D>(rectVertices)), polyType, true);
 }
        //------------------------------------------------------------------------------
        public bool AddPolygon(Polygon pg, PolyType polyType)
        {
            int len = pg.Count;
            if (len < 3) return false;
            Polygon p = new Polygon(len);
            p.Add(new IntPoint(pg[0].X, pg[0].Y));
            int j = 0;
            for (int i = 1; i < len; ++i)
            {

                Int64 maxVal;
                if (m_UseFullRange) maxVal = hiRange; else maxVal = loRange;
                if (Math.Abs(pg[i].X) > maxVal || Math.Abs(pg[i].Y) > maxVal)
                {
                  if (m_UseFullRange)
                    throw new ClipperException("Coordinate exceeds range bounds");
                  maxVal = hiRange;
                  if (Math.Abs(pg[i].X) > maxVal || Math.Abs(pg[i].Y) > maxVal)
                    throw new ClipperException("Coordinate exceeds range bounds");
                  m_UseFullRange = true;
                }

                if (PointsEqual(p[j], pg[i])) continue;
                else if (j > 0 && SlopesEqual(p[j-1], p[j], pg[i], m_UseFullRange))
                {
                    if (PointsEqual(p[j-1], pg[i])) j--;
                } else j++;
                if (j < p.Count)
                    p[j] = pg[i]; else
                    p.Add(new IntPoint(pg[i].X, pg[i].Y));
            }
            if (j < 2) return false;

            len = j+1;
            for (;;)
            {
            //nb: test for point equality before testing slopes ...
            if (PointsEqual(p[j], p[0])) j--;
            else if (PointsEqual(p[0], p[1]) || SlopesEqual(p[j], p[0], p[1], m_UseFullRange))
                p[0] = p[j--];
            else if (SlopesEqual(p[j-1], p[j], p[0], m_UseFullRange)) j--;
            else if (SlopesEqual(p[0], p[1], p[2], m_UseFullRange))
            {
                for (int i = 2; i <= j; ++i) p[i-1] = p[i];
                j--;
            }
            //exit loop if nothing is changed or there are too few vertices ...
            if (j == len-1 || j < 2) break;
            len = j +1;
            }
            if (len < 3) return false;

            //create a new edge array ...
            List<TEdge> edges = new List<TEdge>(len);
            for (int i = 0; i < len; i++) edges.Add(new TEdge());
            m_edges.Add(edges);

            //convert vertices to a double-linked-list of edges and initialize ...
            edges[0].xcurr = p[0].X;
            edges[0].ycurr = p[0].Y;
            InitEdge(edges[len-1], edges[0], edges[len-2], p[len-1], polyType);
            for (int i = len-2; i > 0; --i)
            InitEdge(edges[i], edges[i+1], edges[i-1], p[i], polyType);
            InitEdge(edges[0], edges[1], edges[len-1], p[0], polyType);

            //reset xcurr & ycurr and find 'eHighest' (given the Y axis coordinates
            //increase downward so the 'highest' edge will have the smallest ytop) ...
            TEdge e = edges[0];
            TEdge eHighest = e;
            do
            {
            e.xcurr = e.xbot;
            e.ycurr = e.ybot;
            if (e.ytop < eHighest.ytop) eHighest = e;
            e = e.next;
            }
            while ( e != edges[0]);

            //make sure eHighest is positioned so the following loop works safely ...
            if (eHighest.windDelta > 0) eHighest = eHighest.next;
            if (eHighest.dx == horizontal) eHighest = eHighest.next;

            //finally insert each local minima ...
            e = eHighest;
            do {
            e = AddBoundsToLML(e);
            }
            while( e != eHighest );
            return true;
        }
示例#47
0
      //------------------------------------------------------------------------------

      public bool AddPath(Path pg, PolyType polyType, bool Closed)
      {
#if use_lines
        if (!Closed && polyType == PolyType.ptClip)
          throw new ClipperException("AddPath: Open paths must be subject.");
#else
        if (!Closed)
          throw new ClipperException("AddPath: Open paths have been disabled.");
#endif

        int highI = (int)pg.Count - 1;
        bool ClosedOrSemiClosed = (highI > 0) && (Closed || (pg[0] == pg[highI]));
        while (highI > 0 && (pg[highI] == pg[0])) --highI;
        while (highI > 0 && (pg[highI] == pg[highI - 1])) --highI;
        if ((Closed && highI < 2) || (!Closed && highI < 1)) return false;

          //create a new edge array ...
          List<TEdge> edges = new List<TEdge>(highI+1);
          for (int i = 0; i <= highI; i++) edges.Add(new TEdge());
          
          //1. Basic initialization of Edges ...
          try
          {
            edges[1].Curr = pg[1];
            RangeTest(pg[0], ref m_UseFullRange);
            RangeTest(pg[highI], ref m_UseFullRange);
            InitEdge(edges[0], edges[1], edges[highI], pg[0]);
            InitEdge(edges[highI], edges[0], edges[highI - 1], pg[highI]);
            for (int i = highI - 1; i >= 1; --i)
            {
              RangeTest(pg[i], ref m_UseFullRange);
              InitEdge(edges[i], edges[i + 1], edges[i - 1], pg[i]);
            }
          }
          catch 
          {
            return false; //almost certainly a vertex has exceeded range
          };

          TEdge eStart = edges[0];
          if (!ClosedOrSemiClosed) eStart.Prev.OutIdx = Skip;

          //2. Remove duplicate vertices, and collinear edges (when closed) ...
          TEdge E = eStart, eLoopStop = eStart;
          for (;;)
          {
            if (E.Curr == E.Next.Curr)
            {
              //nb if E.OutIdx == Skip, it would have been semiOpen
              if (E == eStart) eStart = E.Next;
              E = RemoveEdge(E);
              eLoopStop = E;
              continue;
            }
            if (E.Prev == E.Next) 
              break; //only two vertices
            else if ((ClosedOrSemiClosed ||
              (E.Prev.OutIdx != Skip && E.OutIdx != Skip &&
              E.Next.OutIdx != Skip)) &&
              SlopesEqual(E.Prev.Curr, E.Curr, E.Next.Curr, m_UseFullRange)) 
            {
              //All collinear edges are allowed for open paths but in closed paths
              //inner vertices of adjacent collinear edges are removed. However if the
              //PreserveCollinear property has been enabled, only overlapping collinear
              //edges (ie spikes) are removed from closed paths.
              if (Closed && (!PreserveCollinear ||
                !Pt2IsBetweenPt1AndPt3(E.Prev.Curr, E.Curr, E.Next.Curr))) 
              {
                if (E == eStart) eStart = E.Next;
                E = RemoveEdge(E);
                E = E.Prev;
                eLoopStop = E;
                continue;
              }
            }
            E = E.Next;
            if (E == eLoopStop) break;
          }

          if ((!Closed && (E == E.Next)) || (Closed && (E.Prev == E.Next)))
            return false;
          m_edges.Add(edges);

          if (!Closed)
            m_HasOpenPaths = true;

          //3. Do final Init and also find the 'highest' Edge. (nb: since I'm much
          //more familiar with positive downwards Y axes, 'highest' here will be
          //the Edge with the *smallest* Top.Y.)
          TEdge eHighest = eStart;
          E = eStart;
          do
          {
            InitEdge2(E, polyType);
            if (E.Top.Y < eHighest.Top.Y) eHighest = E;
            E = E.Next;
          }
          while (E != eStart);

          //4. build the local minima list ...
          if (AllHorizontal(E))
          {
            if (ClosedOrSemiClosed)
              E.Prev.OutIdx = Skip;
            AscendToMax(ref E, false, false);
            return true;
          }

          //if eHighest is also the Skip then it's a natural break, otherwise
          //make sure eHighest is positioned so we're either at a top horizontal or
          //just starting to head down one edge of the polygon
          E = eStart.Prev; //EStart.Prev == Skip edge
          if (E.Prev == E.Next)
            eHighest = E.Next;
          else if (!ClosedOrSemiClosed && E.Top.Y == eHighest.Top.Y)
          {
            if ((IsHorizontal(E) || IsHorizontal(E.Next)) && 
              E.Next.Bot.Y == eHighest.Top.Y)
                eHighest = E.Next;
            else if (SharedVertWithPrevAtTop(E)) eHighest = E;
            else if (E.Top == E.Prev.Top) eHighest = E.Prev;
            else eHighest = E.Next;
          } else
          {
            E = eHighest;
            while (IsHorizontal(eHighest) ||
              (eHighest.Top == eHighest.Next.Top) ||
              (eHighest.Top == eHighest.Next.Bot)) //next is high horizontal
            {
              eHighest = eHighest.Next;
              if (eHighest == E) 
              {
                while (IsHorizontal(eHighest) || !SharedVertWithPrevAtTop(eHighest))
                    eHighest = eHighest.Next;
                break; //avoids potential endless loop
              }
            }
          }
          E = eHighest;
          do
            E = AddBoundsToLML(E, Closed);
          while (E != eHighest);
          return true;
      }
 //------------------------------------------------------------------------------
 private void InitEdge(TEdge e, TEdge eNext,
   TEdge ePrev, IntPoint pt, PolyType polyType)
 {
     e.next = eNext;
       e.prev = ePrev;
       e.xcurr = pt.X;
       e.ycurr = pt.Y;
       if (e.ycurr >= e.next.ycurr)
       {
     e.xbot = e.xcurr;
     e.ybot = e.ycurr;
     e.xtop = e.next.xcurr;
     e.ytop = e.next.ycurr;
     e.windDelta = 1;
       } else
       {
     e.xtop = e.xcurr;
     e.ytop = e.ycurr;
     e.xbot = e.next.xcurr;
     e.ybot = e.next.ycurr;
     e.windDelta = -1;
       }
       SetDx(e);
       e.polyType = polyType;
       e.outIdx = -1;
 }
示例#49
0
      //------------------------------------------------------------------------------

      public bool AddPaths(Paths ppg, PolyType polyType, bool closed)
      {
        bool result = false;
        for (int i = 0; i < ppg.Count; ++i)
          if (AddPath(ppg[i], polyType, closed)) result = true;
        return result;
      }