Esempio n. 1
0
        public static Heightmap Create <T>(Int2 size, HeightfieldTypes heightType, Vector2 heightRange, float heightScale, T[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            HeightmapUtils.CheckHeightParameters(size, heightType, heightRange, heightScale, true);

            var length = size.X * size.Y;

            switch (data)
            {
            case float[] floats when floats.Length == length: break;

            case short[] shorts when shorts.Length == length: break;

            case byte[] bytes when bytes.Length == length: break;

            default: throw new ArgumentException($"{ typeof(T[]) } is not supported in { heightType } height type. Or { nameof(data) }.{ nameof(data).Length } doesn't match { nameof(size) }.");
            }

            var heightmap = new Heightmap
            {
                HeightType  = heightType,
                Size        = size,
                HeightRange = heightRange,
                HeightScale = heightScale,
                Floats      = data as float[],
                Shorts      = data as short[],
                Bytes       = data as byte[],
            };

            return(heightmap);
        }
Esempio n. 2
0
        public static bool IsValid([NotNull] this Heightmap heightmap)
        {
            if (heightmap == null)
            {
                throw new ArgumentNullException(nameof(heightmap));
            }

            bool IsValidHeights()
            {
                var length = heightmap.Size.X * heightmap.Size.Y;

                switch (heightmap.HeightType)
                {
                case HeightfieldTypes.Float when heightmap.Floats != null && heightmap.Floats.Length == length:
                    return(true);

                case HeightfieldTypes.Short when heightmap.Shorts != null && heightmap.Shorts.Length == length:
                    return(true);

                case HeightfieldTypes.Byte when heightmap.Bytes != null && heightmap.Bytes.Length == length:
                    return(true);
                }

                return(false);
            }

            return(HeightmapUtils.CheckHeightParameters(heightmap.Size, heightmap.HeightType, heightmap.HeightRange, heightmap.HeightScale, false) &&
                   IsValidHeights());
        }
 public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&
 MathUtil.IsInRange(InitialByte, byte.MinValue, byte.MaxValue);
 public bool IsValid() => HeightmapUtils.CheckHeightParameters(HeightStickSize, HeightType, HeightRange, HeightScale, false) &&
 MathUtil.IsInRange(InitialHeight, HeightRange.X, HeightRange.Y);