private ChunkedLodTreeNode[] GetLeafs(Bounds2D bounds, ChunkedLodTreeNode parent, int depth)
        {
            if (depth == 0)
            {
                return new ChunkedLodTreeNode[0];
            }

            var min = bounds.Min;
            var max = bounds.Max;
            var center = bounds.Center;

            var first = new Bounds2D(min, new Vector2d(center.X, center.Y));
            var second = new Bounds2D(new Vector2d(center.X, min.Y), new Vector2d(max.X, center.Y));
            var third = new Bounds2D(new Vector2d(min.X, center.Y), new Vector2d(center.X, max.Y));
            var fourth = new Bounds2D(new Vector2d(center.X, center.Y), max);
            var nextDepth = depth - 1;
            var geometricError = CalculateGeometricError(depth - 1);
            return new[]
            {
                CreateChunkedLodTreeNode(first, parent, nextDepth, geometricError),
                CreateChunkedLodTreeNode(second, parent, nextDepth, geometricError),
                CreateChunkedLodTreeNode(third, parent, nextDepth, geometricError),
                CreateChunkedLodTreeNode(fourth, parent, nextDepth, geometricError)
            };
        }
Ejemplo n.º 2
0
 private Collision2D(SpriteCollider a, SpriteCollider b)
 {
     this.a = a;
     this.b = b;
     boundsA = a.getBounds();
     boundsB = b.getBounds();
     checkCollsion();
 }
Ejemplo n.º 3
0
 public Bounds2D toLocal(Bounds2D global)
 {
     Bounds2D ret = new Bounds2D();
     ret.x = global.x - x;
     ret.y = global.y - y;
     ret.width = global.width;
     ret.height = global.height;
     return ret;
 }
Ejemplo n.º 4
0
 public Bounds2D intersection(Bounds2D other)
 {
     Bounds2D ret = new Bounds2D();
     ret.x = Mathf.Max(x, other.x);
     ret.y = Mathf.Max(y, other.y);
     ret.width = Mathf.Abs(ret.x - Mathf.Min(x+width,other.x+other.width));
     ret.height = Mathf.Abs(ret.y - Mathf.Min(y+height,other.y+other.height));
     return ret;
 }
        public static ChunkedLodTreeFactory.ChunkedLodTreeNode CreateTree()
        {
            var chunkedLodTreeFactory = new ChunkedLodTreeFactory();

            double width = 8192 * 2 * 2;
            var bounds = new Bounds2D(
                new Vector2d(-width/2, -width/2),
                new Vector2d(width/2, width/2));

            var chunkResolution = 32;
            var depth = (int)Math.Log((width / chunkResolution), 2);

            return chunkedLodTreeFactory.Create(bounds, depth);
        }
 public ChunkedLodTreeNode(Bounds2D bounds, ChunkedLodTreeNode parent, double geometricError)
 {
     Bounds = bounds;
     Parent = parent;
     Nodes = new ChunkedLodTreeNode[0];
     GeometricError = geometricError;
     if (Parent == null)
     {
         Level = 0;
     }
     else
     {
         Level = parent.Level + 1;
     }
 }
Ejemplo n.º 7
0
        protected override void DoCheck(IMovable user, ref Vector2 vel, ref CollisionStatus collStatus, LayerMask mask,
                                        Bounds2D bounds, Bounds2D shrinkedBounds)
        {
            //Direction
            var direction       = Math.Sign(vel.y);
            var verticalRays    = user.VerticalRaycasts;
            var directionVector = new Vector2(0, vel.y * Time.deltaTime);
            // Bounds2D
            var bMin        = bounds.Min;
            var bMax        = bounds.Max;
            var positiveDir = direction == 1;

            var originX   = shrinkedBounds.Min.x;
            var originY   = positiveDir ? bMax.y : bMin.y;
            var origin    = new Vector2(originX, originY);
            var width     = shrinkedBounds.Size.x;
            var spacing   = width / (verticalRays - 1);
            var rayLength = directionVector.magnitude;

            LastHit = null;
            var hitDown = false;

            for (byte x = 0; x < verticalRays; x++)
            {
                var raycast = Physics2D.Raycast(origin, directionVector, rayLength, mask);
                Debug.DrawRay(origin, directionVector, raycast ? Color.green : Color.red);
                if (raycast && !raycast.collider.isTrigger && raycast.distance < rayLength)
                {
                    LastHit         = raycast;
                    vel.y           = raycast.distance / Time.deltaTime * direction;
                    rayLength       = raycast.distance;
                    collStatus.Down = direction == -1;
                    collStatus.Up   = direction == 1;
                    if (!hitDown)
                    {
                        hitDown = direction == -1;
                    }
                }

                origin.x += spacing;
            }

            if (!hitDown)
            {
                collStatus.Down = false;
            }
        }
Ejemplo n.º 8
0
        public Film(
            Point2I resolution,
            Bounds2D cropWindow,
            Filter filter,
            double diagonal,
            string filename,
            double scale,
            double maxSampleLuminance = double.MaxValue)
        {
            FullResolution      = resolution;
            Diagonal            = diagonal * 0.001;
            Filter              = filter;
            Filename            = filename;
            _scale              = scale;
            _maxSampleLuminance = maxSampleLuminance;

            CroppedPixelBounds = new Bounds2I(
                new Point2I(
                    Convert.ToInt32(Math.Ceiling(Convert.ToDouble(FullResolution.X) * cropWindow.MinPoint.X)),
                    Convert.ToInt32(Math.Ceiling(Convert.ToDouble(FullResolution.Y) * cropWindow.MinPoint.Y))),
                new Point2I(
                    Convert.ToInt32(Math.Ceiling(Convert.ToDouble(FullResolution.X) * cropWindow.MaxPoint.X)),
                    Convert.ToInt32(Math.Ceiling(Convert.ToDouble(FullResolution.Y) * cropWindow.MaxPoint.Y))));
            //LOG(INFO) << "Created film with full resolution " << resolution <<
            //  ". Crop window of " << cropWindow << " -> croppedPixelBounds " <<
            //  croppedPixelBounds;

            // Allocate film image storage
            _pixels = new Pixel[CroppedPixelBounds.Area];
            // todo: this is a stat... _filmPixelMemory += croppedPixelBounds.Area() * sizeof(Pixel);

            // Precompute filter weight table
            int offset = 0;

            for (int y = 0; y < FilterTableWidth; ++y)
            {
                for (int x = 0; x < FilterTableWidth; ++x, ++offset)
                {
                    Point2D p = new Point2D(
                        (x + 0.5f) * filter.Radius.X / Convert.ToDouble(FilterTableWidth),
                        (y + 0.5f) * filter.Radius.Y / Convert.ToDouble(FilterTableWidth));
                    FilterTable[offset] = filter.Evaluate(p);
                }
            }
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        public PerspectiveCamera(AnimatedTransform cameraToWorld, Bounds2D screenWindow, double shutterOpen, double shutterClose, double lensr, double focald, double fov, Film film, Medium medium)
            : base(cameraToWorld, Transform.Perspective(fov, 1e-2f, 1000.0), screenWindow, shutterOpen, shutterClose, lensr, focald, film, medium)
        {
            // Compute differential changes in origin for perspective camera rays
            _dxCamera =
                (RasterToCamera.AtPoint(new Point3D(1.0, 0.0, 0.0)) - RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0))).ToVector3D();
            _dyCamera =
                (RasterToCamera.AtPoint(new Point3D(0.0, 1.0, 0.0)) - RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0))).ToVector3D();

            // Compute image plane bounds at $z=1$ for _PerspectiveCamera_
            Point2I res      = film.FullResolution;
            Point3D MinPoint = RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0));
            Point3D MaxPoint = RasterToCamera.AtPoint(new Point3D(res.X, res.Y, 0.0));

            MinPoint /= MinPoint.Z;
            MaxPoint /= MaxPoint.Z;
            _a        = Math.Abs((MaxPoint.X - MinPoint.X) * (MaxPoint.Y - MinPoint.Y));
        }
Ejemplo n.º 10
0
    /// <summary> Constructor </summary>
    public Polygon2D(params Vector2[] verts)
    {
        if (verts.Length < 4)
        {
            Debug.LogWarning("You cannot create a polygon with less than 4 verts. Input count: " + verts.Length);
            verts = new Vector2[] { new Vector2(-1, 1), new Vector2(1, 1), new Vector2(1, -1), new Vector2(-1, -1) };
        }
        _verts      = verts;
        _triIndices = Triangulate(verts);
        float area = Geometry2D.ShoelaceFormula(_verts);

        _area        = Mathf.Abs(area);
        _triCount    = _triIndices.Length / 3;
        _bounds      = new Bounds2D(verts);
        _edges       = GetEdges(_verts);
        _tris        = GetTriangles(_verts, _triIndices);
        _isClockwise = area < 0;
    }
Ejemplo n.º 11
0
        private IList <Polyline4D> method_17(
            IClippingTransformer transformer,
            Bounds2D textBounds)
        {
            Matrix4D             transform    = this.Transform;
            IClippingTransformer transformer1 = (IClippingTransformer)transformer.Clone();

            transformer1.SetPreTransform(transform);
            double num = this.double_1 * (this.backgroundFillInfo_0.BorderOffsetFactor - 1.0);
            double x1  = textBounds.Corner1.X - num;
            double x2  = this.double_2 + num;
            double y1  = textBounds.Corner1.Y - num;
            double y2  = textBounds.Corner2.Y + num;

            return(DxfUtil.smethod_38(new WW.Math.Geometry.Polyline3D(true, new WW.Math.Point3D[4] {
                new WW.Math.Point3D(x1, y1, 0.0), new WW.Math.Point3D(x2, y1, 0.0), new WW.Math.Point3D(x2, y2, 0.0), new WW.Math.Point3D(x1, y2, 0.0)
            }), true, transformer1));
        }
Ejemplo n.º 12
0
        private static bool Contains(Class455.Class461 polyInfo, Point2D point)
        {
            Bounds2D bounds2D0 = polyInfo.bounds2D_0;
            Point2D  min       = bounds2D0.Min;
            Point2D  max       = bounds2D0.Max;

            if (min.X > point.X || max.X < point.X || (min.Y > point.Y || max.Y < point.Y))
            {
                return(polyInfo.bool_0);
            }
            Polygon2D polygon2D0 = polyInfo.polygon2D_0;

            if (polyInfo.bool_0)
            {
                return(!polygon2D0.IsInside(point));
            }
            return(polygon2D0.IsInside(point));
        }
Ejemplo n.º 13
0
        private static void SearchRecursive(PathFinderAgent agent, Bounds2D targetBounds, Vector3 targetPos, float targetSqrDist, int targetBranch)
        {
            kDTreeBranch branch = branches[targetBranch];

            if (branch.bounds.Overlap(targetBounds))
            {
                if (branch.branchA != -1)
                {
                    SearchRecursive(agent, targetBounds, targetPos, targetSqrDist, branch.branchA);
                    SearchRecursive(agent, targetBounds, targetPos, targetSqrDist, branch.branchB);
                }
                else
                {
                    for (int i = branch.start; i < branch.end; i++)
                    {
                        var realAgent = PathFinder.agents[agents[i].index];
                        if (agent != realAgent)
                        {
                            float curSqrDist = SomeMath.SqrDistance(targetPos, realAgent.positionVector3);
                            if (curSqrDist < targetSqrDist)
                            {
                                if (agent.neighbourAgents.Count < agent.maxNeighbors)
                                {
                                    agent.neighbourAgents.Add(realAgent);
                                    agent.neighbourSqrDistances.Add(curSqrDist);
                                }
                                else
                                {
                                    for (int n = 0; n < agent.maxNeighbors; n++)
                                    {
                                        if (agent.neighbourSqrDistances[n] > curSqrDist)
                                        {
                                            agent.neighbourAgents[n]       = realAgent;
                                            agent.neighbourSqrDistances[n] = curSqrDist;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private void SearchRecursive(T target, Bounds2D targetBounds, Vector2 targetPos, float targetSqrDist, int targetBranch)
        {
            kDTreeBranch branch = branches[targetBranch];

            if (branch.bounds.Overlap(targetBounds))
            {
                if (branch.branchA != -1)
                {
                    SearchRecursive(target, targetBounds, targetPos, targetSqrDist, branch.branchA);
                    SearchRecursive(target, targetBounds, targetPos, targetSqrDist, branch.branchB);
                }
                else
                {
                    for (int i = branch.start; i < branch.end; i++)
                    {
                        T realAgent = data[members[i].index];
                        if (target.Equals(realAgent) == false)
                        {
                            float curSqrDist = SomeMath.SqrDistance(targetPos, realAgent.position);
                            if (curSqrDist < targetSqrDist)
                            {
                                if (target.neighbourAgents.Count < target.maxNeighbours)
                                {
                                    target.neighbourAgents.Add(realAgent);
                                    target.neighbourSqrDistances.Add(curSqrDist);
                                }
                                else
                                {
                                    for (int n = 0; n < target.maxNeighbours; n++)
                                    {
                                        if (target.neighbourSqrDistances[n] > curSqrDist)
                                        {
                                            target.neighbourAgents[n]       = realAgent;
                                            target.neighbourSqrDistances[n] = curSqrDist;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public void Transform(ITransformer4D transformer)
        {
            WW.Math.Point3D position  = this.Position;
            Vector4D        vector4D1 = new Vector4D(position.X, position.Y, position.Z, 1.0);

            WW.Math.Point3D point3D1  = transformer.TransformToPoint3D(this.matrix4D_0 * vector4D1);
            Bounds2D        bounds    = this.interface34_0.Font.Metrics.GetBounds(this.interface34_0.Text, Enum24.flag_0);
            Vector4D        vector4D2 = vector4D1 + new Vector4D(bounds.Delta.X, 0.0, 0.0, 0.0);

            WW.Math.Point3D point3D2  = transformer.TransformToPoint3D(this.matrix4D_0 * vector4D2);
            Vector4D        vector4D3 = vector4D1 + new Vector4D(0.0, bounds.Delta.Y, 0.0, 0.0);

            WW.Math.Point3D point3D3  = transformer.TransformToPoint3D(this.matrix4D_0 * vector4D3);
            Vector3D        vector3D1 = (point3D2 - point3D1) / bounds.Delta.X;
            Vector3D        vector3D2 = (point3D3 - point3D1) / bounds.Delta.Y;
            Vector3D        zaxis     = Vector3D.CrossProduct(vector3D1, vector3D2);

            this.matrix4D_0 = Transformation4D.GetCoordSystem(vector3D1, vector3D2, zaxis, point3D1);
        }
        /// <summary>
        ///     Determines whether every item matches the conditions defined by the specified
        ///     predicate. If the current instance contains no items the return value is
        ///     <see langword="true"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TRefReadOnlyRectCollection">
        ///     <typeparamref name="TRefReadOnlyRectCollection"/> is
        ///     <see cref="IRefReadOnlyRectangularCollection{T}"/>
        /// </typeparam>
        /// <typeparam name="TPredicate">
        ///     <typeparamref name = "TPredicate"/> is <see cref="IPredicate{T}"/> and
        ///     <see langword="struct"/>
        /// </typeparam>
        /// <param name="source">The collection in which the operation takes place.</param>
        /// <param name="match">
        ///     A <see langword="struct"/> implementing <see cref="IPredicate{T}"/> that defines
        ///     the conditions to check against the items.
        /// </param>
        /// <returns></returns>
        public static bool TrueForAll <T, TRefReadOnlyRectCollection, TPredicate>(
            this TRefReadOnlyRectCollection source, TPredicate match)
            where TRefReadOnlyRectCollection : IRefReadOnlyRectangularCollection <T>
            where TPredicate : struct, IPredicate <T>
        {
            Bounds2D bounds = source.Boundaries;

            for (int i = 0; i < bounds.Length1; i++)
            {
                for (int j = 0; j < bounds.Length2; j++)
                {
                    if (!match.Invoke(source[new Index2D(i, j)]))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 17
0
        public PerspectiveCamera(Transform cameraToWorld,
                                 Bounds2D screenWindow,
                                 float lensRadius,
                                 float focalDistance,
                                 float fov,
                                 Film film)
            : base(cameraToWorld, Perspective(fov, 1e-2f, 1000f), screenWindow, lensRadius, focalDistance, film)
        {
            _dxCamera = RasterToCamera * new Point(1, 0, 0) - RasterToCamera * new Point(0, 0, 0);
            _dyCamera = RasterToCamera * new Point(0, 1, 0) - RasterToCamera * new Point(0, 0, 0);

            var res  = film.FullResolution;
            var pMin = RasterToCamera * new Point(0, 0, 0);
            var pMax = RasterToCamera * new Point(res.X, res.Y, 0);

            pMin /= pMin.Z;
            pMax /= pMax.Z;
            A     = Abs((pMax.X - pMin.X) * (pMax.Y - pMin.Y));
        }
Ejemplo n.º 18
0
    private Vector2 GetRandomVectorOutTheRoad(Bounds2D bounds)
    {
        var rnd = new System.Random();
        var vec = new Vector2(
            rnd.Next((int)bounds.Min.x,
                     (int)bounds.Max.x),
            rnd.Next((int)bounds.Min.y,
                     (int)bounds.Max.y));

        while (game.Map.RoadNodes.Contains(vec))
        {
            vec = new Vector2(
                rnd.Next((int)bounds.Min.x,
                         (int)bounds.Max.x),
                rnd.Next((int)bounds.Min.y,
                         (int)bounds.Max.y));
        }
        return(vec);
    }
Ejemplo n.º 19
0
            public BasicLayoutRenderInfo(IViewDescription viewDescription)
            {
                double val1 = viewDescription.ViewportWidth / viewDescription.ViewWidth;
                double val2 = viewDescription.ViewportHeight / viewDescription.ViewHeight;

                if (DxfUtil.IsSaneNotZero(val1) && DxfUtil.IsSaneNotZero(val2))
                {
                    this.ModelToLayoutScaling = System.Math.Min(val1, val2);
                    Vector2D        vector2D       = val1 > val2 ? new Vector2D(0.5 * val2 / val1 * viewDescription.ViewportWidth, 0.5 * viewDescription.ViewportHeight) : new Vector2D(0.5 * viewDescription.ViewportWidth, 0.5 * val1 / val2 * viewDescription.ViewportHeight);
                    WW.Math.Point2D viewportCenter = (WW.Math.Point2D)viewDescription.ViewportCenter;
                    this.LayoutViewport         = new Bounds2D(viewportCenter - vector2D, viewportCenter + vector2D);
                    this.ModelToLayoutTransform = Transformation4D.Translation((WW.Math.Vector3D)viewDescription.ViewportCenter) * Transformation4D.Scaling(this.ModelToLayoutScaling) * ViewUtil.GetBasicModelToViewportTransform(viewDescription) * Transformation4D.Translation(-(WW.Math.Vector3D)viewDescription.ViewportCenter);
                }
                else
                {
                    this.LayoutViewport         = new Bounds2D();
                    this.ModelToLayoutTransform = Matrix4D.Identity;
                    this.ModelToLayoutScaling   = 0.0;
                }
            }
Ejemplo n.º 20
0
        public void SetWipeoutPolygon(IList <WW.Math.Point2D> polygon)
        {
            Bounds2D bounds2D = new Bounds2D();

            bounds2D.Update(polygon);
            this.InsertionPoint = (WW.Math.Point3D)bounds2D.Min;
            this.XAxis          = new Vector3D(bounds2D.Delta.X, 0.0, 0.0);
            this.YAxis          = new Vector3D(0.0, bounds2D.Delta.Y, 0.0);
            Matrix3D matrix3D = Transformation3D.Scaling(1.0 / this.XAxis.X, -1.0 / this.YAxis.Y, 1.0) * Transformation3D.Translation(WW.Math.Point2D.Zero - bounds2D.Center);

            this.BoundaryVertices.Clear();
            foreach (WW.Math.Point2D point in (IEnumerable <WW.Math.Point2D>)polygon)
            {
                this.BoundaryVertices.Add(matrix3D.Transform(point));
            }
            if (this.BoundaryVertices.Count <= 2 || !(this.BoundaryVertices[0] != this.BoundaryVertices[this.BoundaryVertices.Count - 1]))
            {
                return;
            }
            this.BoundaryVertices.Add(this.BoundaryVertices[0]);
        }
Ejemplo n.º 21
0
        /**
         * Attempts to translate, rotate, and scale @points to match @target as closely as possible.
         * Only points[0, target.Length] coordinates are used in the matching process - points[target.Length, points.Length]
         * are just along for the ride.
         */
        public static Transform2D MatchCoordinates(Vector2[] points, Vector2[] target)
        {
            int length = points.Length < target.Length ? points.Length : target.Length;

            Bounds2D t_bounds = new Bounds2D(target, length); // only match the bounds of known matching points

            // move points to the center of target
            Vector2 translation = t_bounds.center - Bounds2D.Center(points, length);

            Vector2[] transformed = new Vector2[points.Length];
            for (int i = 0; i < points.Length; i++)
            {
                transformed[i] = points[i] + translation;
            }

            // rotate to match target points
            Vector2 target_angle = target[1] - target[0], transform_angle = transformed[1] - transformed[0];

            float angle = Vector2.Angle(target_angle, transform_angle);
            float dot   = Vector2.Dot(Vector2.Perpendicular(target_angle), transform_angle);

            if (dot < 0)
            {
                angle = 360f - angle;
            }

            for (int i = 0; i < points.Length; i++)
            {
                transformed[i] = transformed[i].RotateAroundPoint(t_bounds.center, angle);
            }

            // and lastly scale
            Bounds2D p_bounds = new Bounds2D(transformed, length);
            Vector2  scale    = t_bounds.size.DivideBy(p_bounds.size);

            // for(int i = 0; i < points.Length; i++)
            //  transformed[i] = transformed[i].ScaleAroundPoint(t_bounds.center, scale);

            return(new Transform2D(translation, angle, scale));
        }
Ejemplo n.º 22
0
        public Terminal(Primitive <bool> isPauseToggled)
        {
            this.isPauseToggled = isPauseToggled;

            commands       = new SortedDictionary <string, Command>();
            autocomplete   = new Autocomplete();
            font           = ContentCache.GetFont("Debug");
            currentLine    = new SpriteText(font);
            suggestionText = new SpriteText(font);
            lines          = new List <SpriteText>();
            history        = new List <string>();
            charWidth      = font.Measure("A").x;
            storedIndex    = -1;
            insertBounds   = new Bounds2D(charWidth, font.Size);

            var accessor = Properties.Access();

            padding       = accessor.GetInt("terminal.padding");
            historyLimit  = accessor.GetInt("terminal.history.limit");
            Height        = accessor.GetInt("terminal.default.height");
            Anchor        = Anchors.Left | Anchors.Top;
            IsDrawEnabled = false;
            colors        = new Color[5];

            textProcessor             = new TextProcessor();
            textProcessor.RepeatDelay = accessor.GetFloat("terminal.repeat.delay");
            textProcessor.RepeatRate  = accessor.GetFloat("terminal.repeat.rate");
            textProcessor.Submit      = Submit;

            AddDefaultCommands();

            MessageSystem.Subscribe(this, (int)CoreMessageTypes.ResizeWindow, data =>
            {
                // The terminal is always resized to fit the window width.
                Width = ((ivec2)data).x;
            });

            InputProcessor.Add(this, 10);
        }
Ejemplo n.º 23
0
        protected ProjectiveCamera(
            Transform cameraToWorld,
            Transform cameraToScreen,
            Bounds2D screenWindow,
            float lensRadius,
            float focalDistance,
            Film film)
        {
            CameraToWorld  = cameraToWorld;
            CameraToScreen = cameraToScreen;
            LensRadius     = lensRadius;
            FocalDistance  = focalDistance;
            Film           = film;

            ScreenToRaster = Scale(film.FullResolution.X, film.FullResolution.Y, 1f) *
                             Scale(1f / (screenWindow.Max.X - screenWindow.Min.X),
                                   1f / (screenWindow.Min.Y - screenWindow.Max.Y),
                                   1f) *
                             Translate(-screenWindow.Min.X, -screenWindow.Max.Y, 0f);
            RasterToScreen = Invert(ScreenToRaster);
            RasterToCamera = Invert(CameraToScreen) * RasterToScreen;
        }
Ejemplo n.º 24
0
        private void SearchRecursive(QuadTreeBranch curBranch, Bounds2D bounds, List <T> result)
        {
            if (curBranch == null)
            {
                return;
            }

            Bounds2D branchBounds = curBranch.bounds;

            if (bounds.Overlap(branchBounds) == false)
            {
                return;
            }

            for (int i = 0; i < curBranch.list.Count; i++)
            {
                if (bounds.Overlap(curBranch.list[i].bounds))
                {
                    result.Add(curBranch.list[i]);
                }
            }

            if (curBranch.branches[0] != null)
            {
                SearchRecursive(curBranch.branches[0], bounds, result);
            }
            if (curBranch.branches[1] != null)
            {
                SearchRecursive(curBranch.branches[1], bounds, result);
            }
            if (curBranch.branches[2] != null)
            {
                SearchRecursive(curBranch.branches[2], bounds, result);
            }
            if (curBranch.branches[3] != null)
            {
                SearchRecursive(curBranch.branches[3], bounds, result);
            }
        }
 public static ItemRequestResult <Index2D> FindIndex <
     T, TRectCollection>(
     this TRectCollection source,
     Index2D startIndex,
     Bounds2D sectorSize,
     Predicate <T> match)
     where TRectCollection : IRectangularCollection <T>
 {
     if (match == null)
     {
         throw new ArgumentNullException(nameof(match), "match cannot be null.");
     }
     try
     {
         return(source.FindIndex <T, TRectCollection, BoxedPredicate <T> >(
                    startIndex, sectorSize, new BoxedPredicate <T>(match)));
     }
     catch (ArgumentOutOfRangeException)
     {
         throw;
     }
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Get the distance between a point and a quad
        /// </summary>
        /// <param name="point">The point from which the distance is calculated`</param>
        /// <param name="a">One of the quad's point. Is connected to b and d.</param>
        /// <param name="b">One of the quad's point. Is connected to a and c.</param>
        /// <param name="c">One of the quad's point. Is connected to b and d.</param>
        /// <param name="d">One of the quad's point. Is connected to c and a.</param>
        /// <returns></returns>
        public static float DistanceToQuad(Vector2 point, Vector2 a, Vector2 b, Vector2 c, Vector2 d)
        {
            s_QuadBuffer[0] = a;
            s_QuadBuffer[1] = b;
            s_QuadBuffer[2] = c;
            s_QuadBuffer[3] = d;

            var bounds = new Bounds2D(s_QuadBuffer);

            //Check if the point is inside the quad
            if (bounds.Contains(point))
            {
                var firstEdgeDir = bounds.center - (Vector2)GetEdgeCenter(a, b);
                var rayStart     = bounds.center + firstEdgeDir * (bounds.size.y + bounds.size.x + 2f);
                var collisions   = 0;

                for (int i = 0, count = s_QuadBuffer.Length - 1; i < count; ++i)
                {
                    var p1 = s_QuadBuffer[i];
                    var p2 = s_QuadBuffer[i + 1];
                    if (AreSegmentIntersecting(rayStart, point, p1, p2))
                    {
                        ++collisions;
                    }
                }

                if (collisions % 2 != 0)
                {
                    return(0f);
                }
            }

            s_QuadDistanceBuffer[0] = DistanceToLine(point, a, b);
            s_QuadDistanceBuffer[1] = DistanceToLine(point, b, c);
            s_QuadDistanceBuffer[2] = DistanceToLine(point, c, d);
            s_QuadDistanceBuffer[3] = DistanceToLine(point, d, a);

            return(Mathf.Min(s_QuadDistanceBuffer));
        }
Ejemplo n.º 27
0
        public FlatShape4D(FillableShape2D shape, Matrix4D transform)
        {
            this.fillableShape2D_0 = shape;
            this.matrix4D_0        = transform;
            Bounds2D bounds = ShapeTool.GetBounds((IShape2D)shape);

            if (bounds.Initialized)
            {
                this.point2D_0 = new Point2D[4]
                {
                    bounds.Corner1,
                    new Point2D(bounds.Corner2.X, bounds.Corner1.Y),
                    bounds.Corner2,
                    new Point2D(bounds.Corner1.X, bounds.Corner2.Y)
                }
            }
            ;
            else
            {
                this.point2D_0 = (Point2D[])null;
            }
        }
Ejemplo n.º 28
0
        public static void AddToBounds(
            Bounds2D bounds,
            ISegment2DIterator iterator,
            Matrix4D transformation)
        {
            if (!iterator.MoveNext())
            {
                return;
            }
            Point2D[] points  = new Point2D[3];
            Point2D   point2D = new Point2D();

            do
            {
                switch (iterator.Current(points, 0))
                {
                case SegmentType.MoveTo:
                case SegmentType.LineTo:
                    point2D = transformation.Transform(points[0]);
                    bounds.Update(point2D);
                    break;

                case SegmentType.QuadTo:
                    Point2D p1 = transformation.Transform(points[1]);
                    ShapeTool.smethod_4(bounds, point2D, transformation.Transform(points[0]), p1);
                    point2D = p1;
                    bounds.Update(point2D);
                    break;

                case SegmentType.CubicTo:
                    Point2D p3 = transformation.Transform(points[2]);
                    ShapeTool.smethod_5(bounds, point2D, transformation.Transform(points[0]), transformation.Transform(points[1]), p3);
                    point2D = p3;
                    bounds.Update(point2D);
                    break;
                }
            }while (iterator.MoveNext());
        }
Ejemplo n.º 29
0
        public void BuildTree(int membersPerBranch = 2)
        {
            this.membersPerBranch = Mathf.Max(1, membersPerBranch);

            foreach (var item in inUse)
            {
                ReturnBranch(item);
            }
            inUse.Clear();

            //find current bonds
            if (data.Count == 0)
            {
                return;
            }

            Bounds2D curBounds = data[0].bounds;

            float minX = curBounds.minX;
            float minY = curBounds.minY;
            float maxX = curBounds.maxX;
            float maxY = curBounds.maxY;

            for (int i = 1; i < data.Count; i++)
            {
                curBounds = data[i].bounds;
                minX      = Mathf.Min(curBounds.minX, minX);
                minY      = Mathf.Min(curBounds.minY, minY);
                maxX      = Mathf.Max(curBounds.maxX, maxX);
                maxY      = Mathf.Max(curBounds.maxY, maxY);
            }

            root = GetFreeBranch();
            root.list.AddRange(data);
            root.bounds = new Bounds2D(minX, minY, maxX, maxY);
            root.depth  = 0;
            BuildRecursive(root);
        }
        public RenderableMesh GetRenderable(Bounds2D bounds)
        {
            RenderableMesh mesh;
            var result = _cache.TryGetValue(bounds, out mesh);
            if (result)
            {
                return mesh;
            }

            if (!_jobs.Contains(bounds))
            {
                _jobs.Add(bounds);
                JobDispatcher.Instance.Enqueue(() =>
                {
                    var terrainChunk = _terrainChunkFactory.Create(bounds);
                    var renderableMesh = _resourceAllocator.AllocateResourceFor(terrainChunk);
                    _cache[bounds] = renderableMesh;
                    _jobs.Remove(bounds);
                });
            }

            return null;
        }
        internal static ItemRequestResult <Index2D> FindIndexInternal <
            T, TRectCollection, TPredicate>(
            this TRectCollection source,
            Index2D startIndex,
            Bounds2D sectorSize,
            TPredicate match)
            where TRectCollection : IRectangularCollection <T>
            where TPredicate : struct, IPredicate <T>
        {
            for (int i = startIndex.Dimension1Index; i < sectorSize.Length1; i++)
            {
                for (int j = startIndex.Dimension2Index; j < sectorSize.Length2; j++)
                {
                    var index = new Index2D(i, j);

                    if (match.Invoke(source[index]))
                    {
                        return(new ItemRequestResult <Index2D>(index));
                    }
                }
            }
            return(ItemRequestResult <Index2D> .Fail);
        }
Ejemplo n.º 32
0
    /// <summary>
    /// Makes sure that the <paramref name="objCenter"/> specified will allow the <paramref name="obj"/> to remain in the <paramref name="field"/>.
    /// Returns the original <paramref name="objCenter"/> if it is valid or a new location otherwise.
    /// </summary>
    /// <param name="objCenter">The location of the object's center</param>
    /// <param name="obj">The object's bounds</param>
    /// <param name="field">The bounding box to fit the object in</param>
    /// <returns>The location to move the object to</returns>
    public static Vector2 VerifyBounds(Vector2 objCenter, Bounds2D obj, Bounds2D field)
    {
        Vector2 maxOffset = field.Max - (objCenter + obj.Extents);
        Vector2 minOffset = field.Min - (objCenter - obj.Extents);

        if (minOffset.x > 0)
        {
            objCenter.x = field.XMin + obj.Extents.x;
        }
        else if (maxOffset.x < 0)
        {
            objCenter.x = field.XMax - obj.Extents.x;
        }
        if (minOffset.y > 0)
        {
            objCenter.y = field.YMin + obj.Extents.y;
        }
        else if (maxOffset.y < 0)
        {
            objCenter.y = field.YMax - obj.Extents.y;
        }
        return(objCenter);
    }
Ejemplo n.º 33
0
        public override InsideTestResult TryIsInside(Bounds3D bounds)
        {
            if (!bounds.Initialized)
            {
                return(InsideTestResult.None);
            }
            Bounds2D bounds2D = new Bounds2D();
            Point3D  min      = bounds.Min;
            Point3D  max      = bounds.Max;

            bounds2D.Update(this.matrix4D_1.TransformTo2D(min));
            bounds2D.Update(this.matrix4D_1.TransformTo2D(new Point3D(min.X, min.Y, max.Z)));
            bounds2D.Update(this.matrix4D_1.TransformTo2D(new Point3D(min.X, max.X, min.Z)));
            bounds2D.Update(this.matrix4D_1.TransformTo2D(new Point3D(min.X, max.X, max.Z)));
            bounds2D.Update(this.matrix4D_1.TransformTo2D(new Point3D(max.X, min.X, min.Z)));
            bounds2D.Update(this.matrix4D_1.TransformTo2D(new Point3D(max.X, min.X, max.Z)));
            bounds2D.Update(this.matrix4D_1.TransformTo2D(new Point3D(max.X, max.X, min.Z)));
            bounds2D.Update(this.matrix4D_1.TransformTo2D(max));
            if (bounds2D.Overlaps(this.class461_0.bounds2D_0))
            {
                return(InsideTestResult.BothSides);
            }
            return(!this.class461_0.bool_0 ? InsideTestResult.Outside : InsideTestResult.Inside);
        }
Ejemplo n.º 34
0
        public static Polygon2D[] smethod_9(
            Interface28 xInterval,
            Interface28 yInterval,
            Polygon2D[] outer,
            Polygon2D[] holes,
            bool right,
            double epsilon)
        {
            if (xInterval.IsUnbound || yInterval.IsUnbound)
            {
                Bounds2D bounds2D = new Bounds2D();
                foreach (Polygon2D polygon2D in outer)
                {
                    bounds2D.Update((IList <Point2D>)polygon2D);
                }
                if (!bounds2D.Initialized)
                {
                    return((Polygon2D[])null);
                }
                if (xInterval.IsUnbound)
                {
                    xInterval = (Interface28) new Class438(xInterval.HasUnboundStart ? bounds2D.Min.X : xInterval.Start, xInterval.HasUnboundEnd ? bounds2D.Max.X : xInterval.End, xInterval.PeriodicLength);
                }
                if (yInterval.IsUnbound)
                {
                    yInterval = (Interface28) new Class438(yInterval.HasUnboundStart ? bounds2D.Min.Y : yInterval.Start, yInterval.HasUnboundEnd ? bounds2D.Max.Y : yInterval.End, yInterval.PeriodicLength);
                }
            }
            List <Polygon2D> polygon2DList = new List <Polygon2D>();

            Polygon2D[] polygon2DArray1 = Class794.smethod_10(outer, right, true, xInterval, yInterval, epsilon);
            polygon2DList.AddRange((IEnumerable <Polygon2D>)polygon2DArray1);
            Polygon2D[] polygon2DArray2 = Class794.smethod_10(holes, right, false, xInterval, yInterval, epsilon);
            polygon2DList.AddRange((IEnumerable <Polygon2D>)polygon2DArray2);
            return(polygon2DList.ToArray());
        }
Ejemplo n.º 35
0
        private DxfLayout.BasicLayoutRenderInfo method_8()
        {
            Bounds2D bounds2D = new Bounds2D();

            switch (this.PlotArea)
            {
            case PlotArea.LastScreenDisplay:
                if (this.LastActiveViewport is DxfVPort)
                {
                    return(new DxfLayout.BasicLayoutRenderInfo(((DxfVPort)this.LastActiveViewport).ViewDescription));
                }
                if (this.LastActiveViewport is DxfViewport)
                {
                    return(new DxfLayout.BasicLayoutRenderInfo(((DxfViewport)this.LastActiveViewport).ViewDescription));
                }
                return(new DxfLayout.BasicLayoutRenderInfo());

            case PlotArea.SpecifiedByViewName:
                return(new DxfLayout.BasicLayoutRenderInfo(this.Model.Views[this.PlotViewName].ViewDescription));

            default:
                return(new DxfLayout.BasicLayoutRenderInfo(this.GetPlotAreaBounds()));
            }
        }
Ejemplo n.º 36
0
        public RenderableMesh GetRenderable(Bounds2D bounds)
        {
            RenderableMesh mesh;
            var            result = _cache.TryGetValue(bounds, out mesh);

            if (result)
            {
                return(mesh);
            }

            if (!_jobs.Contains(bounds))
            {
                _jobs.Add(bounds);
                JobDispatcher.Instance.Enqueue(() =>
                {
                    var terrainChunk   = _terrainChunkFactory.Create(bounds);
                    var renderableMesh = _resourceAllocator.AllocateResourceFor(terrainChunk);
                    _cache[bounds]     = renderableMesh;
                    _jobs.Remove(bounds);
                });
            }

            return(null);
        }
Ejemplo n.º 37
0
 public bool isVerticalOverlap(Bounds2D other)
 {
     return !(y > other.y + other.height || other.y > y + height);
 }
Ejemplo n.º 38
0
 public bool overlaps(Bounds2D other)
 {
     return isHorizontalOverlap(other) && isVerticalOverlap(other);
 }
 private ChunkedLodTreeNode CreateChunkedLodTreeNode(Bounds2D first, ChunkedLodTreeNode parent, int nextDepth, double geometricError)
 {
     var chunkedLodTreeNode = new ChunkedLodTreeNode(first, parent, geometricError);
     chunkedLodTreeNode.SetNodes(GetLeafs(first, chunkedLodTreeNode, nextDepth));
     return chunkedLodTreeNode;
 }
 public ChunkedLodTreeNode Create(Bounds2D bounds, int depth)
 {
     return CreateChunkedLodTreeNode(bounds, null, depth, CalculateGeometricError(depth));
 }
Ejemplo n.º 41
0
            public ImplicitChunkHeightMap(Bounds2D bounds, int columns, int rows, INoiseGenerator noiseGenerator)
            {
                _noiseGenerator = noiseGenerator;
                _rows = rows;
                _columns = columns;
                _bounds = bounds;

                var origin = CalculatePosition(0, 0);
                var position = CalculatePosition(1, 1);

                _dx = 1 / (position.X - origin.X);
                _dy = 1 / (position.Y - origin.Y);
            }
Ejemplo n.º 42
0
 protected void MakeBounds()
 {
     Bounds2D actualBounds = new Bounds2D(collider2D);
     Vector3 max = actualBounds.GetMax();
     Vector3 min = actualBounds.GetMin();
     Vector3 maxY = new Vector3(min.x, max.y, min.z);
     Vector3 maxX = new Vector3(max.x, min.y, min.z);
     if (bounds == null)
     {
         bounds = new LineRenderer[4];
     }
     bounds[0] = MakeOutline(min, maxY, bounds[0]);
     bounds[1] = MakeOutline(maxY, max, bounds[1]);
     bounds[2] = MakeOutline(min, maxX, bounds[2]);
     bounds[3] = MakeOutline(maxX, max, bounds[3]);
 }
Ejemplo n.º 43
0
 private static Color[] getBitArray(Bounds2D section, Texture2D texture)
 {
     return texture.GetPixels(section.x, section.y, section.width,section.height);
 }
Ejemplo n.º 44
0
 public bool isHorizontalOverlap(Bounds2D other)
 {
     return !(x > other.x + other.width || other.x > x + width);
 }
Ejemplo n.º 45
0
        public void imethod_0(ref Vector2D baselinePos, double height, Enum24 whiteSpaceHandlingFlags)
        {
            LinkedList <Class427> linkedList = new LinkedList <Class427>();

            this.vector2D_0 = baselinePos;
            baselinePos    += new Vector2D(0.0, -this.class1024_0.BeforeSpace);
            double paragraphWidth = this.class1024_0.ParagraphWidth;
            bool   flag1;
            double width = (flag1 = paragraphWidth > 0.0) ? paragraphWidth - this.class1024_0.RightIndent + this.vector2D_0.X : 0.0;
            bool   flag2 = true;

            using (LinkedList <Class427> .Enumerator enumerator = this.linkedList_0.GetEnumerator())
            {
label_13:
                if (enumerator.MoveNext())
                {
                    Class427 class427_1 = enumerator.Current;
                    do
                    {
                        double x = this.vector2D_0.X + this.class1024_0.LeftIndent;
                        if (flag2)
                        {
                            goto label_11;
                        }
label_3:
                        Vector2D baselinePos1 = new Vector2D(x, baselinePos.Y);
                        Vector2D vector2D = baselinePos1;
                        class427_1.imethod_0(ref baselinePos1, height, whiteSpaceHandlingFlags);
                        Bounds2D bounds = class427_1.GetBounds(whiteSpaceHandlingFlags, (Class985)null);
                        if (flag1 && bounds.Delta.X > width - x)
                        {
                            Interface24[] nterface24Array = class427_1.imethod_1(width, this.TextBreaker);
                            switch (nterface24Array.Length)
                            {
                            case 0:
                                linkedList.AddLast(class427_1);
                                class427_1 = (Class427)null;
                                break;

                            case 1:
                                linkedList.AddLast(class427_1);
                                class427_1 = (Class427)null;
                                break;

                            case 2:
                                baselinePos1 = vector2D;
                                Class427 class427_2 = (Class427)nterface24Array[0];
                                class427_2.imethod_0(ref baselinePos1, height, whiteSpaceHandlingFlags);
                                linkedList.AddLast(class427_2);
                                class427_1 = (Class427)nterface24Array[1];
                                break;

                            default:
                                linkedList.AddLast(class427_1);
                                class427_1 = (Class427)null;
                                break;
                            }
                        }
                        else
                        {
                            linkedList.AddLast(class427_1);
                            class427_1 = (Class427)null;
                        }
                        baselinePos += baselinePos1 - vector2D;
                        continue;
label_11:
                        flag2 = false;
                        x    += this.class1024_0.LeftIndentFirst;
                        goto label_3;
                    }while (class427_1 != null);
                    goto label_13;
                }
            }
            if (linkedList.Count > this.linkedList_0.Count)
            {
                this.linkedList_0 = linkedList;
            }
            bool flag3 = true;

            foreach (Class427 class427 in this.linkedList_0)
            {
                double num = this.vector2D_0.X + this.class1024_0.LeftIndent;
                if (flag3)
                {
                    flag3 = false;
                    num  += this.class1024_0.LeftIndentFirst;
                }
                Bounds2D bounds = class427.GetBounds(Enum24.flag_1, (Class985)null);
                switch (this.class1024_0.Alignment)
                {
                case Class1023.Enum45.const_0:
                    class427.method_1(0.5 * (width + num) - bounds.Center.X);
                    continue;

                case Class1023.Enum45.const_1:
                    class427.method_1(num - bounds.Corner1.X);
                    continue;

                case Class1023.Enum45.const_2:
                    class427.method_1(width - bounds.Corner2.X);
                    continue;

                default:
                    continue;
                }
            }
            baselinePos += new Vector2D(0.0, -this.class1024_0.AfterSpace);
        }
Ejemplo n.º 46
0
 public Mesh3V3N Create(Bounds2D bounds)
 {
     var meshDimensions = 128;
     var implicintHeightMap = new ImplicitChunkHeightMap(bounds, meshDimensions, meshDimensions, new ScaledNoiseGenerator());
     return MeshCreator.CreateFromHeightMap(meshDimensions, meshDimensions, implicintHeightMap);
 }