예제 #1
0
 public void TestSettingValues(double data)
 {
     var constant = new Constant { ConstantValue = data };
     Assert.Equal(data, constant.GetValue(0, 0, 0));
     constant.ConstantValue += data;
     Assert.Equal(data * 2, constant.GetValue(0, 0, 0));
 }
예제 #2
0
        public void AddTest(double data)
        {
            var source = new Constant { ConstantValue = data };
            var add = new Add { Source0 = source, Source1 = source };

            Assert.Equal(2 * data, add.GetValue(0, 0, 0));
        }
예제 #3
0
 public void MultiplyTest(double a, double b)
 {
     var source0 = new Constant { ConstantValue = a };
     var source1 = new Constant { ConstantValue = b };
     var module = new Multiply { Source0 = source0, Source1 = source1 };
     Assert.Equal(a * b, module.GetValue(0, 0, 0));
 }
예제 #4
0
        public void AbsTest(double data)
        {
            var source = new Constant { ConstantValue = data };
            var module = new Abs { Source0 = source };

            Assert.Equal(Math.Abs(source.GetValue(0, 0, 0)), module.GetValue(0, 0, 0));
        }
예제 #5
0
        public void MinTest(double a, double b)
        {
            var source0 = new Constant { ConstantValue = a };
            var source1 = new Constant { ConstantValue = b };
            var module = new Min { Source0 = source0, Source1 = source1 };

            Assert.Equal(Math.Min(a, b), module.GetValue(0, 0, 0));
        }
예제 #6
0
        public void ClampTest(double data)
        {
            const double max = 10D;
            const double min = 0D;

            var source = new Constant { ConstantValue = data };
            var module = new Clamp { LowerBound = min, UpperBound = max, Source0 = source };

            Assert.InRange(module.GetValue(0, 0, 0), min, max);
        }
예제 #7
0
        public void GetSourceModuleTest()
        {
            var source0 = new Constant();
            var source1 = new Constant();
            var control = new Constant();

            var module = new Select() { Source0 = source0, Source1 = source1, Control = control };

            Assert.Same(source0, module.Source0);
            Assert.Same(source1, module.Source1);
            Assert.Same(control, module.Control);

            Assert.Same(module.Source0, module.SourceModules[0]);
            Assert.Same(module.Source1, module.SourceModules[1]);
            Assert.Same(module.Control, module.SourceModules[2]);
        }
예제 #8
0
        public void ConstantSerializeTest()
        {
            var module = new Constant() { ConstantValue = 5D };
            var formatter = new BinaryFormatter();

            byte[] data;
            using (var ms = new MemoryStream())
            {
                module.Serialize(ms);
                data = ms.ToArray();
            }

            Constant deserializedModule;
            using (var ms = new MemoryStream(data))
                deserializedModule = Constant.Deserialize<Constant>(ms, formatter);

            Assert.Equal(module.ConstantValue, deserializedModule.ConstantValue);
        }
예제 #9
0
 public void TestValues(double data)
 {
     var constant = new Constant { ConstantValue = data };
     Assert.Equal(data, constant.ConstantValue);
     Assert.Equal(data, constant.GetValue(0, 0, 0));
 }
예제 #10
0
        public void SerializeAllModulesTest()
        {
            var source0 = new Constant() { ConstantValue = 5D };
            var source1 = new Add() { Source0 = source0, Source1 = source0 };
            var source2 = new Multiply() { Source0 = source0, Source1 = source1 };

            // create modules with custom sources and parameters
            var modules = new Module[]
            {
                new Abs() { Source0=source0},
                new Add() { Source0=source0, Source1=source1},
                new Billow() { Quality= NoiseQuality.Fast, Lacunarity=Billow.DefaultLacunarity*2},
                new Blend(){ Control=new Constant(){ ConstantValue=0.5D}, Source0=source0, Source1=source1},
                new Cache() { Source0=source2},
                new Checkerboard(),
                new Clamp() { LowerBound=0D, UpperBound=5D, Source0=source0},
                new Constant() { ConstantValue=9D},
                new Cylinders() { Frequency=Cylinders.DefaultFrequency*2},
                new Displace() { Source0=source0, XDisplace=source0, YDisplace=source1, ZDisplace=source2},
                new Exponent(){ Exp=Exponent.DefaultExponent*3, Source0=source0},
                new Invert() {  Source0=source0},
                new Max() { Source0=source0, Source1=source1},
                new Min() {Source0=source0, Source1=source1},
                new Multiply(){ Source0=source0, Source1=source1},
                new Perlin() { Frequency=Perlin.DefaultFrequency*2, Quality=NoiseQuality.Best},
                new Power(){ Source0=source1, Source1=source0},
                new RidgedMulti(){ Frequency=RidgedMulti.DefaultFrequency*2},
                new RotatePoint(){ Source0=source0, XAngle=1, YAngle=2, ZAngle=3},
                new ScaleBias() { Bias=0.7, Scale=2, Source0=source0},
                new ScalePoint(){ Source0=source0, XScale=2, YScale=3, ZScale=4},
                new Select() { LowerBound=0, UpperBound=2, Control=source0, Source0=source1, Source1=source2},
                new Spheres() { Frequency=Spheres.DefaultFrequency*2},
                new TranslatePoint() { Source0=source0, XTranslation=2, YTranslation=3, ZTranslation=4},
                new Turbulence() { Source0=source0, Frequency=Turbulence.DefaultFrequency*2},
                new Voronoi(){ Displacement=Voronoi.DefaultDisplacement*2},
            };

            var serializedModules = new byte[modules.Length][];
            var deserializedModules = new Module[modules.Length];
            var formatter = new BinaryFormatter();

            for (var i = 0; i < modules.Length; i++)
            {
                using (var ms = new MemoryStream())
                {
                    modules[i].Serialize(ms, formatter);
                    serializedModules[i] = ms.ToArray();
                }
            }

            for (var i = 0; i < serializedModules.Length; i++)
            {
                using (var ms = new MemoryStream(serializedModules[i]))
                {
                    deserializedModules[i] = Module.Deserialize<Module>(ms, formatter);
                }
            }

            for (var i = 0; i < modules.Length; i++)
            {
                Assert.Equal(modules[i].GetValue(0, 0, 0), deserializedModules[i].GetValue(0, 0, 0));
                Assert.Equal(modules[i].GetValue(1, 2, 3), deserializedModules[i].GetValue(1, 2, 3));
            }
        }