예제 #1
0
        public static void ContainsInclusive(Vector2[] vertices, ref Vector2 point, out Containment result)
        {
            Contract.Requires(vertices != null);
            Contract.Requires(vertices.Length > 2);

            var     count = 0; // the crossing count
            var     v1    = vertices[vertices.Length - 1];
            Vector2 v2;

            for (var index = 0; index < vertices.Length; index++, v1 = v2)
            {
                v2 = vertices[index];
                if (((v1.Y <= point.Y) ^ (v2.Y <= point.Y)) ||
                    (v1.Y.NearlyEquals(point.Y)) || (v2.Y.NearlyEquals(point.Y)))
                {
                    var xIntersection = (v1.X + ((point.Y - v1.Y) / (v2.Y - v1.Y)) * (v2.X - v1.X));
                    if (point.X < xIntersection) // P.X < intersect
                    {
                        ++count;
                    }
                    else if (xIntersection.NearlyEquals(point.X))
                    {
                        result = Containment.Contains;
                        return;
                    }
                }
            }
            result = ((count & 1) != 0) ? (Containment.Contains) : (Containment.Disjoint); //true if odd.
        }
예제 #2
0
        /// <summary>
        /// Does this ray intersect the provided polygon area?
        /// </summary>
        /// <param name="polygon">The Polygon to intersect with.</param>
        /// <param name="result">The intersection result.</param>
        /// <param name="containment">An enumeration detailing the type of intersection if one occurs.</param>
        /// <returns>True if an intersection occurs, otherwise false. If true, check the intersection result for the location of the intersection.</returns>
        public bool Intersects(Polygon polygon, out Vector3 result, out Containment containment)
        {
            var plane = new Plane(polygon.Vertices.First(), polygon.Vertices);

            if (Intersects(plane, out Vector3 test))
            {
                // Check the intersection against all the polygon's vertices.
                // If the intersection is at a vertex, the point is contained.
                if (polygon.Vertices.Any(v => v.IsAlmostEqualTo(test)))
                {
                    result      = test;
                    containment = Containment.CoincidesAtVertex;
                    return(true);
                }

                result = test;
                if (polygon.Contains3D(test))
                {
                    containment = Containment.Inside;
                    return(true);
                }
            }
            result      = default;
            containment = Containment.Outside;
            return(false);
        }
예제 #3
0
        private void Contains(Vector2[] otherVertexes, out Containment result)
        {
            Contract.Requires(otherVertexes != null);
            Contract.Requires(otherVertexes.Length > 2);

            Containment contains;

            result = Containment.Unknown;
            for (var index = 0; index < Vertices.Length; ++index)
            {
                ContainsExclusive(otherVertexes, ref Vertices[index], out contains);
                if (contains == Containment.Contains)
                {
                    result = Containment.Intersects;
                    return;
                }
            }
            for (var index = 0; index < otherVertexes.Length && result != Containment.Intersects; ++index)
            {
                ContainsInclusive(Vertices, ref otherVertexes[index], out contains);
                result |= contains;
            }
            if (result == Containment.Disjoint)
            {
                bool test;
                Intersects(Vertices, otherVertexes, out test);
                if (test)
                {
                    result = Containment.Intersects;
                }
            }
        }
예제 #4
0
        public static void ContainsExclusive(Vector2[] vertices, ref Vector2 point, out Containment result)
        {
            Contract.Requires(vertices != null);
            Contract.Requires(vertices.Length > 2);

            var     intersectionCount = 0;
            Vector2 v1, v2;

            v1 = vertices[vertices.Length - 1];
            for (var index = 0; index < vertices.Length; ++index, v1 = v2)
            {
                v2 = vertices[index];
                var t1 = (v1.Y <= point.Y);
                if (t1 ^ (v2.Y <= point.Y))
                {
                    var temp = ((point.Y - v1.Y) * (v2.X - v1.X) - (point.X - v1.X) * (v2.Y - v1.Y));
                    if (t1)
                    {
                        if (temp > 0)
                        {
                            intersectionCount++;
                        }
                    }
                    else
                    {
                        if (temp < 0)
                        {
                            intersectionCount--;
                        }
                    }
                }
            }
            result = (intersectionCount != 0) ? (Containment.Contains) : (Containment.Disjoint);
        }
예제 #5
0
        // Duplicates with BoundingRectangle.
        public void Contains(ref BoundingPolygon polygon, out Containment result)
        {
            Contract.Requires(polygon != null);
            Contract.Requires(polygon.Vertices != null);

            var vertices = polygon.Vertices;

            result = Containment.Unknown;
            for (var index = 0; index < vertices.Length && result != Containment.Intersects; ++index)
            {
                Containment con;
                Contains(ref vertices[index], out con);
                result |= con;
            }

            if (result == Containment.Disjoint)
            {
                bool test;
                polygon.Intersects(ref this, out test);
                if (test)
                {
                    result = Containment.Intersects;
                }
            }
        }
예제 #6
0
        public void Contains(ref Vector2 point, out Containment result)
        {
            float distance;

            GetDistance(ref point, out distance);
            result = ((distance <= 0) ? (Containment.Contains) : (Containment.Disjoint));
        }
예제 #7
0
 public void Contains(ref BoundingPolygon polygon, out Containment result)
 {
     if (polygon == null)
     {
         throw new ArgumentNullException("polygon");
     }
     Contains(polygon.Vertices, out result);
 }
예제 #8
0
파일: Profile.cs 프로젝트: jmerlan/Elements
        /// <summary>
        /// Tests if a point is contained within this profile. Returns false for points that are outside of the profile (or within voids).
        /// </summary>
        /// <param name="point">The position to test.</param>
        /// <param name="containment">Whether the point is inside, outside, at an edge, or at a vertex.</param>
        /// <returns>True if the point is within the profile.</returns>
        public bool Contains(Vector3 point, out Containment containment)
        {
            IEnumerable <(Vector3 from, Vector3 to)> allEdges = Perimeter.Edges();

            if (Voids != null)
            {
                allEdges = allEdges.Union(Voids.SelectMany(v => v.Edges()));
            }
            return(Polygon.Contains(allEdges, point, out containment));
        }
예제 #9
0
        /// <summary>
        /// Tests if a point is contained within this profile. Returns false for points that are outside of the profile (or within voids).
        /// </summary>
        /// <param name="point">The position to test.</param>
        /// <param name="containment">Whether the point is inside, outside, at an edge, or at a vertex.</param>
        /// <returns>True if the point is within the profile.</returns>
        public bool Contains(Vector3 point, out Containment containment)
        {
            IEnumerable <Line> allLines = Perimeter.Segments();

            if (Voids != null)
            {
                allLines = allLines.Union(Voids.SelectMany(v => v.Segments()));
            }
            return(Polygon.Contains(allLines, point, out containment));
        }
 public void Contains(ref Vector2 point, out Containment result)
 {
     if (point.X <= Max.X && point.X >= Min.X && point.Y <= Max.Y && point.Y >= Min.Y)
     {
         result = Containment.Contains;
     }
     else
     {
         result = Containment.Disjoint;
     }
 }
예제 #11
0
        public void PointInPoly_ExternalPoint_Success()
        {
            Vector3 pt = new Vector3(-1.0f, 0.0f, -1.0f);

            Vector3[] poly = new Vector3[3];
            poly[0] = new Vector3(0.0f, 0.0f, 1.0f);
            poly[1] = new Vector3(-1.0f, 0.0f, 0.0f);
            poly[2] = new Vector3(1.0f, 0.0f, 0.0f);

            bool isInPoly = Containment.PointInPoly(pt, poly, poly.Length);

            Assert.IsFalse(isInPoly);
        }
 public void Contains(ref BoundingCircle circle, out Containment result)
 {
     if ((circle.Center.X + circle.Radius) <= Max.X &&
         (circle.Center.X - circle.Radius) >= Min.X &&
         (circle.Center.Y + circle.Radius) <= Max.Y &&
         (circle.Center.Y - circle.Radius) >= Min.Y)
     {
         result = Containment.Contains;
     }
     else
     {
         bool intersects;
         circle.Intersects(ref this, out intersects);
         result = intersects ? Containment.Intersects : Containment.Disjoint;
     }
 }
예제 #13
0
        public static FindSpecificationCollection <TDataObject> Contains <TKey>(
            Expression <Func <TDataObject, TKey> > keyProperyExpression,
            IReadOnlyCollection <TKey> keys,
            int limit)
        {
            var specs = Enumerable.Range(0, (limit + keys.Count - 1) / limit)
                        .Select(x =>
            {
                var batch      = keys.Skip(x * limit).Take(limit);
                var expression = Containment <TKey> .Create(keyProperyExpression, batch);
                return(new FindSpecification <TDataObject>(expression));
            })
                        .ToArray();

            return(new FindSpecificationCollection <TDataObject>(specs));
        }
예제 #14
0
    // Start is called before the first frame update
    void Start()
    {
        timeElapsed    = 0;
        building       = GameManager.Instance.Buildings["containment"].GetComponent <Containment>();
        scips          = new List <SCP>();
        wantedScips    = new List <SCP>();
        containedScips = new List <SCP>();

        loadAllScips();

        foreach (SCP scip in scips)
        {
            GameManager.Instance.AddScp(scip.DL, scip);
            wantedScips.Add(scip);
        }
    }
예제 #15
0
        // Adapted from https://stackoverflow.com/questions/46144205/point-in-polygon-using-winding-number/46144206
        internal static bool Contains(IEnumerable <Line> segments, Vector3 location, out Containment containment)
        {
            int windingNumber = 0;

            foreach (var edge in segments)
            {
                // check for coincidence with edge vertices
                var toStart = location - edge.Start;
                if (toStart.IsZero())
                {
                    containment = Containment.CoincidesAtVertex;
                    return(true);
                }
                var toEnd = location - edge.End;
                if (toEnd.IsZero())
                {
                    containment = Containment.CoincidesAtVertex;
                    return(true);
                }
                //along segment - check if perpendicular distance to segment is below tolerance and that point is between ends
                var a = toStart.Length();
                var b = toStart.Dot((edge.End - edge.Start).Unitized());
                if (a * a - b * b < Vector3.EPSILON * Vector3.EPSILON && toStart.Dot(toEnd) < 0)
                {
                    containment = Containment.CoincidesAtEdge;
                    return(true);
                }


                if (edge.AscendingRelativeTo(location) &&
                    edge.LocationInRange(location, Line.Orientation.Ascending))
                {
                    windingNumber += Wind(location, edge, Line.Position.Left);
                }
                if (!edge.AscendingRelativeTo(location) &&
                    edge.LocationInRange(location, Line.Orientation.Descending))
                {
                    windingNumber -= Wind(location, edge, Line.Position.Right);
                }
            }

            var result = windingNumber != 0;

            containment = result ? Containment.Inside : Containment.Outside;
            return(result);
        }
예제 #16
0
        public void Contains(ref BoundingCircle circle, out Containment result)
        {
            float distance;

            GetDistance(ref circle.Center, out distance);
            if (-distance >= circle.Radius)
            {
                result = Containment.Contains;
            }
            else if (distance > circle.Radius)
            {
                result = Containment.Disjoint;
            }
            else
            {
                result = Containment.Intersects;
            }
        }
예제 #17
0
        public void Contains(ref BoundingRectangle rect, out Containment result)
        {
            float   mag;
            Vector2 maxDistance, minDistance;

            Vector2.Subtract(ref rect.Max, ref Center, out maxDistance);
            Vector2.Subtract(ref Center, ref rect.Min, out minDistance);
            NumberTools.Sort(ref minDistance.X, ref maxDistance.X, out minDistance.X, out maxDistance.X);
            NumberTools.Sort(ref minDistance.Y, ref maxDistance.Y, out minDistance.Y, out maxDistance.Y);
            mag = maxDistance.Length();
            if (mag <= Radius)
            {
                result = Containment.Contains;
            }
            else
            {
                mag    = minDistance.Length();
                result = (mag <= Radius) ? Containment.Intersects : Containment.Disjoint;
            }
        }
 public void Contains(ref BoundingRectangle rect, out Containment result)
 {
     if (Min.X > rect.Max.X ||
         Min.Y > rect.Max.Y ||
         Max.X < rect.Min.X ||
         Max.Y < rect.Min.Y)
     {
         result = Containment.Disjoint;
     }
     else if (
         Min.X <= rect.Min.X &&
         Min.Y <= rect.Min.Y &&
         Max.X >= rect.Max.X &&
         Max.Y >= rect.Max.Y)
     {
         result = Containment.Contains;
     }
     else
     {
         result = Containment.Intersects;
     }
 }
예제 #19
0
        public static void archiveFolder(
            String rCloneDirectory,
            String localDropStream,
            String localArchiverBuffer,
            String remoteDropStreamTarget,
            String remoteArchive,
            String fileFormatNameRegex,
            String fileExtenstion,
            String thesholdInGigabytes)
        {
            Stopwatch watch = Stopwatch.StartNew();

            String localTempFolder     = String.Empty;
            String localZipDestination = String.Empty;


            try
            {
                ///Timer for diagnosing

                ///Let's get a temperary name for the temperary folder
                Logger.Info("Getting Temparary Folder... ");
                localTempFolder = Organizer.getTempFolderPath(localDropStream, localArchiverBuffer);
                Logger.Info(String.Format("{0} - {1}", "Temparary Folder Retrieved!", localTempFolder));

                ///Where will this zip file be located locally
                Logger.Info("Creating Time-Stamped folders...");
                localZipDestination = Organizer.createTimestampFolders(localDropStream, localArchiverBuffer, fileFormatNameRegex, fileExtenstion);
                Logger.Info(String.Format("{0}: {1}", "Time-Stamped folders created! Local Zip Destination", localZipDestination));

                ///Compress / Remove the folder to be archived
                Logger.Info(String.Format("{0}: {1}", "Compress and removing target folder to the following location", localTempFolder));
                Organizer.compressAndRemoveTargetFolder(localZipDestination);
                Logger.Info("Successfully compressed and removed folder!");


                ///To make the threshold process a little easier, we need to rename any duplicated file names
                Logger.Info(String.Format("{0}: {1}", "Renaming any duplicated files for removal", localTempFolder));
                CDirectory.renameDuplicatedFiles(rCloneDirectory, remoteArchive);
                Logger.Info("Duplicates renamed / removed!");

                ///Serialize localzipdesitination file for parsing
                FileInfo info = new FileInfo(localZipDestination);
                ///Get a list of all of the existing files in target archive
                var existingFiles = CloudDirectory.serializeDirectory(CDirectory.getFilesStatsInDirectory(rCloneDirectory, remoteArchive));
                ///Delete any files in cloud over threshold
                Logger.Info(String.Format("Removing any files over: {0} (GB) At remote Location: {1} Utilizing: {2}", thesholdInGigabytes, remoteArchive, info.Name));
                List <FileCloudInfo> filesToRemove = Containment.getFIlesInDirectoryOverThreshold(existingFiles, info, Double.Parse(thesholdInGigabytes));
                Logger.Info("Now removing a total of {0} files from cloud directory: {1}", filesToRemove.Count(), remoteArchive);
                Logger.Debug("Target Files: {0}", String.Concat(filesToRemove.Select(o => String.Format("\n{0} ", o.FilePath)))); //Print out all of the files to remove

                ///Run Command to Delete *any* target files
                filesToRemove.ForEach(i => CDelete.deleteDirectory(rCloneDirectory, String.Format(@"{0}/{1}", remoteArchive, i.FilePath)));
                ///Lots of logging, information regarding deleting items
                Logger.Info("Ran command to removed files over threshold! Files *removed*: {0} | Memory *Free'd up*: {1} (GB) ", filesToRemove.Count,
                            ByteSizeLib.ByteSize.FromBytes(filesToRemove.Sum(i => i.Length)).GigaBytes, (filesToRemove.Sum(i => i.Length)));

                ///Moving Zipped file to the cloud storage
                Logger.Info(String.Format("{0} - Local Temp Folder: {1} RemoteArchive: {2}", "Moving the compressed file to cloud storage!", localTempFolder, remoteArchive));
                CMove.moveFile(rCloneDirectory, localTempFolder, remoteArchive, Config.compressionFormat, Config.connectionAttempts);
                Logger.Info(String.Format("{0}", "Successfully deleted Contents!"));

                ///Delete the local folder
                Logger.Info(String.Format("{0}: {1}", "Deleting the following local 'Temp Folder' ", localTempFolder));
                System.IO.Directory.Delete(localTempFolder, true);
                Logger.Info("Successfully deleted the local temp folder!");

                ///TODO: Remove this to a later process...
                Logger.Info(String.Format("{0} - rCloneLocation: {1} gDriveName: {2}", "Deleting requested remote folders", rCloneDirectory, remoteDropStreamTarget));
                CDelete.deleteDirectory(rCloneDirectory, remoteDropStreamTarget);
                Logger.Info(String.Format("{0}", "Deletion of contents command has been ran!"));


                ///Due to a bug, the cloud software may not "release" files. Resetting it will fix this.

                Logger.Info(String.Format("{0} - cloudProcessName: {1} cloudProcessPath: {2}", "Restarting Process", Config.cloudProcessName, Config.cloudProcessPath));
                Management.restartProcess(Config.cloudProcessName, Config.cloudProcessPath);
                Logger.Info("Process successully restarted!");



                ///Delete the cloud folder
                Logger.Info(String.Format("{0} - rCloneLocation: {1} gDriveName: {2}", "Emptying Cloud Folder", rCloneDirectory, Config.driveProfileName));
                CDelete.emptyTrashFolder(rCloneDirectory, Config.driveProfileName);
                Logger.Info("Successfully emptied cloud recycle bin");

                Logger.Info(String.Format("{0} - Elasped time:{1}", "Archiver has successully been ran!", watch.Elapsed.ToString()));
            }

            catch (OrganizerException e)
            {
                Logger.Error(e, String.Format("{0} - {1} (Elapsed time before error: {2} ", "Error while prepping files before transfer", e.Message, watch.Elapsed.ToString()));
                Logger.Trace(e.StackTrace);
            }
            catch (Rclone_Move_Exception e)
            {
                Logger.Error(e, String.Format("{0} - {1} (Elapsed time before error: {2}", "Error while transfering file to the cloud", e.Message, watch.Elapsed.ToString()));
                Logger.Trace(e.StackTrace);
            }

            catch (Exception e)
            {
                Logger.Error(e, String.Format("{0} - {1} (Elapsed time before error: {2} ", "Error while Archiving", e.Message, watch.Elapsed.ToString()));
                Logger.Trace(e.StackTrace);
            }

            finally
            {
                ///If the process fails, remove the temperary directory!
                if (Directory.Exists(localTempFolder))
                {
                    Directory.Delete(localTempFolder, true);
                }
            }
        }
예제 #20
0
 /// <summary>
 /// Tests if the supplied Vector3 is within this Polygon, using a 2D method.
 /// </summary>
 /// <param name="vector">The position to test.</param>
 /// <param name="containment">Whether the point is inside, outside, at an edge, or at a vertex.</param>
 /// <returns>Returns true if the supplied Vector3 is within this polygon.</returns>
 public bool Contains(Vector3 vector, out Containment containment)
 {
     return(Contains(Segments(), vector, out containment));
 }
예제 #21
0
 public void Contains(ref Vector2 point, out Containment result)
 {
     ContainsInclusive(Vertices, ref point, out result);
 }
예제 #22
0
 public void Contains(ref BoundingRectangle rect, out Containment result)
 {
     Contains(rect.Corners(), out result);
 }