Пример #1
0
        /// <summary> Creates instance of <see cref="Apartment"/>. </summary>
        public Apartment(IObjectPool objectPool)
        {
            _objectPool = objectPool;

            OuterWalls     = objectPool.NewList <int>(16);
            TransitWalls   = objectPool.NewList <int>(16);
            PartitionWalls = objectPool.NewList <int>(16);
        }
Пример #2
0
        /// <summary> Initializes a new instance of the <see cref="Polygon" /> class. </summary>
        /// <param name="capacity">The default capacity for the points list.</param>
        /// <param name="objectPool">Object pool.</param>
        public Polygon(int capacity, IObjectPool objectPool)
        {
            _objectPool = objectPool;

            Points   = _objectPool.NewList <Vertex>(capacity);
            Holes    = _objectPool.NewList <Point>();
            Segments = _objectPool.NewList <Edge>();
        }
Пример #3
0
        private List <Point> GetVertices(Path path, RenderMode renderMode, ref Rectangle2d rect)
        {
            // do not split path for overview mode
            var  points     = _objectPool.NewList <Point>(path.Count);
            bool isOverview = renderMode == RenderMode.Overview;

            // split path for scene mode
            var lastItemIndex = path.Count - 1;

            for (int i = 0; i <= lastItemIndex; i++)
            {
                var start = path[i];
                var end   = path[i == lastItemIndex ? 0 : i + 1];

                var p1 = new Point(Math.Round(start.X / Scale, MathUtils.RoundDigitCount),
                                   Math.Round(start.Y / Scale, MathUtils.RoundDigitCount));

                var p2 = new Point(Math.Round(end.X / Scale, MathUtils.RoundDigitCount),
                                   Math.Round(end.Y / Scale, MathUtils.RoundDigitCount));

                if (isOverview &&
                    (!rect.IsOnBorder(new Vector2d(p1.X, p1.Y)) ||
                     !rect.IsOnBorder(new Vector2d(p2.X, p2.Y))))
                {
                    points.Add(p1);
                    continue;
                }

                _lineGridSplitter.Split(p1, p2, _objectPool, points);
            }

            return(points);
        }
Пример #4
0
        private Way ReadWay(BinaryReader reader)
        {
            Way way   = new Way();
            var count = reader.ReadUInt16();
            // TODO use object pool
            var coordinates = _objectPool.NewList <GeoCoordinate>(count);

            for (int i = 0; i < count; i++)
            {
                coordinates.Add(ReadCoordinate(reader));
            }
            way.Coordinates = coordinates;
            return(way);
        }
Пример #5
0
        public Floor(IObjectPool objectPool)
        {
            _objectPool = objectPool;

            Entrances      = objectPool.NewList <LineSegment2d>(1);
            Apartments     = objectPool.NewList <Apartment>(16);
            Stairs         = objectPool.NewList <Vector2d>(32);
            OuterWalls     = objectPool.NewList <LineSegment2d>(32);
            PartitionWalls = objectPool.NewList <LineSegment2d>(32);
            TransitWalls   = objectPool.NewList <LineSegment2d>(32);
        }
Пример #6
0
        /// <summary>
        ///     Reduces the number of points
        /// </summary>
        public static void Reduce(List <Vector2d> source, List <Vector2d> destination, Double tolerance, IObjectPool objectPool)
        {
            if (source == null || source.Count < 3)
            {
                destination.AddRange(source);
                return;
            }

            Int32 firstPoint        = 0;
            Int32 lastPoint         = source.Count - 1;
            var   pointIndexsToKeep = objectPool.NewList <int>(128);

            //Add the first and last index to the keepers
            pointIndexsToKeep.Add(firstPoint);
            pointIndexsToKeep.Add(lastPoint);

            //The first and the last point can not be the same
            while (source[firstPoint].Equals(source[lastPoint]))
            {
                lastPoint--;
            }

            Reduce(source, firstPoint, lastPoint, tolerance, pointIndexsToKeep);

            pointIndexsToKeep.Sort();

            for (int i = 0; i < pointIndexsToKeep.Count; i++)
            {
                var index = pointIndexsToKeep[i];
                // NOTE do not add items twice due to bug in implementation
                if (i > 0 && pointIndexsToKeep[i - 1] == pointIndexsToKeep[i])
                {
                    continue;
                }
                destination.Add(source[index]);
            }
            objectPool.StoreList(pointIndexsToKeep);
        }
Пример #7
0
        /// <summary> Splits line to segments. </summary>
        public void Split(Point s, Point e, IObjectPool objectPool, List <Point> result)
        {
            var start = new Point(s.X, s.Y);
            var end   = new Point(e.X, e.Y);

            var points = objectPool.NewList <Point>();

            points.Add(s);

            double slope = (e.Y - s.Y) / (e.X - s.X);

            if (double.IsInfinity(slope) || Math.Abs(slope) < double.Epsilon)
            {
                ZeroSlope(s, e, points);
            }
            else
            {
                NormalCase(start, end, slope, points);
            }

            MergeResults(points, result);

            objectPool.StoreList(points);
        }
Пример #8
0
 /// <summary> Creates instance of <see cref="TerrainMeshData"/>. </summary>
 /// <param name="objectPool">Object pool.</param>
 public TerrainMeshData(IObjectPool objectPool)
 {
     _objectPool = objectPool;
     Triangles   = _objectPool.NewList <TerrainMeshTriangle>(2048);
 }