Пример #1
0
        public override void Subdivide(Prism bounds, ISubdivisionGeometry geometry, INamedDataCollection hierarchicalParameters)
        {
            if (_designer == null)
            {
                _designer = hierarchicalParameters.GetValue(FloorDesignerName, false);
            }

            base.Subdivide(bounds, geometry, hierarchicalParameters);
        }
Пример #2
0
        public override void Subdivide(Prism bounds, ISubdivisionGeometry geometry, INamedDataCollection hierarchicalParameters)
        {
            //Get internals generated up tree in container
            var internals = hierarchicalParameters.GetValue(BaseSpecBuildingContainer.BuildingInternalsName);

            //Generate externals, now we can get the neighbour information that we need from the surrounding containers
            _design = internals.Externals(Random, hierarchicalParameters, (a, b) => ScriptReference.Find(a, b).Random((Func <double>)Random), GetNeighbourInfo(bounds));

            base.Subdivide(bounds, geometry, hierarchicalParameters);
        }
Пример #3
0
        public override void Subdivide(Prism bounds, ISubdivisionGeometry geometry, INamedDataCollection hierarchicalParameters)
        {
            var height = hierarchicalParameters.GetMaybeValue(new TypedName <float>("height")) ?? 1;

            this.CreateFlatPlane(geometry,
                                 hierarchicalParameters.GetValue(new TypedName <string>("material")) ?? "grass",
                                 bounds.Footprint,
                                 height,
                                 -height
                                 );
        }
        /// <summary>
        /// Determine a value by deriving it from a previously calculated value and then store the result
        /// </summary>
        /// <typeparam name="T">The type of the value</typeparam>
        /// <param name="provider">Provider for previously defined value as well as the target to store the new value in</param>
        /// <param name="random">A random number generator (supply a biased generator to bias the values generated)</param>
        /// <param name="interpolate">A function which interpolates between values</param>
        /// <param name="name">the name of this value</param>
        /// <param name="minName">The name of the lower bound to use</param>
        /// <param name="maxName">The name of the upper bound to use</param>
        /// <param name="min">The minimum value to use (or null, to not set a minimum bound)</param>
        /// <param name="max">The maximum value to use (or null, to not set a maximum bound)</param>
        /// <returns></returns>
        public static T DetermineHierarchicalValue <T>(this INamedDataCollection provider, Func <double> random, Func <T, T, float, T> interpolate, TypedName <T> name, TypedNameDefault <T> minName, TypedNameDefault <T> maxName, T?min = null, T?max = null) where T : struct, IComparable <T>, IEquatable <T>
        {
            Contract.Requires(provider != null);
            Contract.Requires(random != null);
            Contract.Requires(interpolate != null);
            Contract.Requires(minName != null);
            Contract.Requires(maxName != null);

            return(DetermineHierarchicalValue <T>(provider, name, oldValue =>
            {
                //Take an existing value and restrict it into the given range
                var value = oldValue;
                if (min.HasValue)
                {
                    value = min.Value.CompareTo(value) > 0 ? min.Value : value;
                }
                if (max.HasValue)
                {
                    value = max.Value.CompareTo(value) < 0 ? max.Value : value;
                }

                return value;
            }, () =>
            {
                //No existing value, generate a new one (in the given range)

                //Select the *maximum* of the two minimums
                var minHierarchicalValue = provider.GetValue(minName);
                var minValue = min.HasValue ? (min.Value.CompareTo(minHierarchicalValue) > 0 ? min.Value : minHierarchicalValue) : minHierarchicalValue;

                //Select the *minimum* of the two maximums
                var maxHierarchicalValue = provider.GetValue(maxName);
                var maxValue = max.HasValue ? (max.Value.CompareTo(maxHierarchicalValue) > 0 ? max.Value : maxHierarchicalValue) : maxHierarchicalValue;

                //Determine a value in the given range
                return interpolate(minValue, maxValue, (float)random());
            }));
        }
Пример #5
0
        /// <summary>
        /// Get the sidewalk material, or if one has not been generated, generate one based off DefaultSidewalkMaterial
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="random"></param>
        /// <param name="defaultMaterial"></param>
        /// <returns></returns>
        public static string RoadSidewalkMaterial(this INamedDataCollection provider, Func <double> random, string defaultMaterial = null)
        {
            Contract.Requires(provider != null);
            Contract.Requires(random != null);

            return(provider.DefaultMaterial(random, RoadSidewalkMaterialName, defaultMaterial ?? provider.GetValue(DefaultSidewalkMaterialName)));
        }
Пример #6
0
 public override IReadOnlyList <Vector2> Apply(Func <double> random, INamedDataCollection metadata, IReadOnlyList <Vector2> footprint, IReadOnlyList <Vector2> basis, IReadOnlyList <Vector2> lot)
 {
     return
         ((metadata.GetValue(new TypedName <bool>(_key)) ? _pass : _fail)
          .Apply(random, metadata, footprint, basis, lot));
 }