Exemplo n.º 1
0
        /// <summary>
        /// Gets the set of floating objects within a reaction radius from a given position.
        /// Only objects unused in this simulation step are considered.
        /// Only objects with no obstacle between them and the given position are considered.
        /// </summary>
        /// <param name="position">Position whose neighborhood is searched</param>
        /// <param name="targetMultiset">OPTIMIZATION: Objects are collected only until this multiset is reached</param>
        private FloatingObjectsSet GetNearObjects(Point3D position, NamedMultiset targetMultiset)
        {
            var missingObjects = new NamedMultiset(targetMultiset.ToDictionary());
            var nearObjectsSet = new FloatingObjectsSet();

            if (!missingObjects.Any())
            {
                return(nearObjectsSet);
            }

            Vector3D radiusVector = new Vector3D(v_MSystem.Mobility, v_MSystem.Mobility, v_MSystem.Mobility);

            var gridKeys = KeysInBox(new Box3D(position - radiusVector, position + radiusVector)).ToList();

            gridKeys.Shuffle();     // Random order of grid boxes where objects are sought for

            foreach (var key in gridKeys)
            {
                foreach (var fltObject in v_Grid[key].OldSet)
                {
                    if (missingObjects.Contains(fltObject.Name) &&
                        fltObject.Position.DistanceTo(position) < fltObject.Type.Mobility &&
                        !v_tilesWorld.IntersectsWith(fltObject.Position, position, false))
                    {
                        nearObjectsSet.Add(fltObject);
                        missingObjects.Remove(fltObject.Name);
                        if (!missingObjects.Any())
                        {
                            return(nearObjectsSet);
                        }
                    }
                }
            }
            return(nearObjectsSet);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the set of floating objects within the reaction distance from any position of a given connector.
        /// Only objects unused in this simulation step are considered.
        /// TODO low priority: return floating objects close to the whole shape of the connector except endpoints
        /// </summary>
        public FloatingObjectsSet GetNearObjects(ConnectorOnTileInSpace connector, NamedMultiset targetMultiset)
        {
            FloatingObjectsSet objectsSet = new FloatingObjectsSet();

            foreach (var position in connector.Positions)
            {
                objectsSet.UnionWith(GetNearObjects(connector.SidePoint(position), targetMultiset));
            }
            return(objectsSet);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Provides the set of all floating objects in the world.
        /// </summary>
        /// <returns>Set of all floating objects in the world.</returns>
        public FloatingObjectsSet ToSet()
        {
            FloatingObjectsSet allFltObjects = new FloatingObjectsSet();

            foreach (var bar in v_Grid.Values)
            {
                allFltObjects.UnionWith(bar.OldSet.GetHashSet());
                allFltObjects.UnionWith(bar.NewSet.GetHashSet());
            }
            return(allFltObjects);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the set of floating objects within a given prism.
        /// Both objects used and unused in this simulation step are considered.
        /// </summary>
        public FloatingObjectsSet GetObjectsInPrism(Polygon3D basePolygon, Vector3D vector)
        {
            FloatingObjectsSet insideObjects = new FloatingObjectsSet();
            var topPolygon = basePolygon.Select(vertex => vertex + vector);

            foreach (var key in KeysInBox(new Box3D(basePolygon.Union(topPolygon))))
            {
                insideObjects.UnionWith(v_Grid[key].OldSet.GetHashSet().Where(fltObject =>
                                                                              basePolygon.IntersectsWith(fltObject.Position, fltObject.Position - vector)));
                insideObjects.UnionWith(v_Grid[key].NewSet.GetHashSet().Where(fltObject =>
                                                                              basePolygon.IntersectsWith(fltObject.Position, fltObject.Position - vector)));
            }
            return(insideObjects);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Removes the multiset of names of floating objects from a given set of floating objects in space
        /// </summary>
        /// <param name="multiset">Multiset of floating object names to be removed</param>
        /// <param name="targetSet">Set of floating objects from which the multiset is removed - all must be of type "FloatingObjectsInWorld"</param>
        /// <exception cref="ArgumentNullException">If the set contains object which is not "FloatingObjectsInWorld"</exception>
        /// <exception cref="ArgumentException">If the multiset could not be removed</exception>
        public void RemoveFrom(NamedMultiset multiset, FloatingObjectsSet targetSet)
        {
            // Deep copy of the original multiset
            NamedMultiset myMultiset = new NamedMultiset(multiset.ToDictionary());

            foreach (var fltObject in targetSet)
            {
                if (myMultiset.Remove(fltObject.Name))
                {
                    Remove(fltObject as FloatingObjectInWorld);
                }
            }

            if (myMultiset.Count > 0)
            {
                throw new ArgumentException($"{myMultiset} could not be removed from the world!");
            }
        }