Exemplo n.º 1
0
        void ch1Example()
        {
            Interpreter interp = RaytraceInterpreter.MakeInterp();

            interp.RegisterModule(new Ch1Module());
            interp.Run("[ Ch1 ] USE-MODULES");

            double pos(string axis)
            {
                interp.Run(String.Format("{0}-POS", axis));
                DoubleItem item = (DoubleItem)interp.StackPop();

                return(item.DoubleValue);
            }

            interp.Run("0 2 0 Point POSITION!");
            double y             = pos("Y");
            int    numIterations = 0;

            while (y > 0)
            {
                interp.Run("TICK");
                y = pos("Y");
                numIterations++;
            }
            double x = pos("X");

            Debug.WriteLine("distance: {0}, numIterations: {1}", x, numIterations);
        }
Exemplo n.º 2
0
        DoubleItem AddDoubles(dynamic l, dynamic r)
        {
            double     val    = l.DoubleValue + r.DoubleValue;
            DoubleItem result = new DoubleItem(val);

            return(result);
        }
Exemplo n.º 3
0
        // ( a -- sqrt(a) )
        public override void Execute(Interpreter interp)
        {
            dynamic    a      = interp.StackPop();
            DoubleItem result = new DoubleItem(Math.Sqrt(a.DoubleValue));

            interp.StackPush(result);
        }
Exemplo n.º 4
0
        // ( v -- ||v|| )
        public override void Execute(Interpreter interp)
        {
            dynamic    v      = interp.StackPop();
            DoubleItem result = new DoubleItem(v.Vector4Value.Length());

            interp.StackPush(result);
        }
Exemplo n.º 5
0
        public void TestConstruction()
        {
            DoubleItem val = new DoubleItem(100.5);

            Assert.IsNotNull(val);
            Assert.AreEqual(100.5, val.DoubleValue, 0.01);
        }
Exemplo n.º 6
0
        // ( v1 v2 -- s )
        public override void Execute(Interpreter interp)
        {
            dynamic    v2     = interp.StackPop();
            dynamic    v1     = interp.StackPop();
            DoubleItem result = new DoubleItem(Vector4.Dot(v1.Vector4Value, v2.Vector4Value));

            interp.StackPush(result);
        }
Exemplo n.º 7
0
        public void TestAddTwoDoubleItems()
        {
            DoubleItem val1 = new DoubleItem(1);
            DoubleItem val2 = new DoubleItem(2);

            DoubleItem s = AddDoubles(val1, val2);

            Assert.AreEqual(3, s.DoubleValue, 0.1);
        }
Exemplo n.º 8
0
        public void TestAddIntItemAndDoubleItem()
        {
            IntItem    val1 = new IntItem(1);
            DoubleItem val2 = new DoubleItem(3.4);

            DoubleItem s = AddDoubles(val1, val2);

            Assert.AreEqual(4.4, s.DoubleValue, 0.01);
        }
Exemplo n.º 9
0
        public void TestAddIntItemAndDoubleItem()
        {
            IntItem    val1 = new IntItem(1);
            DoubleItem val2 = new DoubleItem(3.4);

            IntItem s = AddInts(val1, val2);

            Assert.AreEqual(4, s.IntValue);
        }
Exemplo n.º 10
0
        private void PointsPerProblem_PointsPerProblemValueChanged(object sender, EventArgs e)
        {
            DoubleItem item = sender as DoubleItem;

            try
            {
                this.CheckInputValues();
            }
            catch (InputValueException)
            {
                // TODO: Implement Logging....
                return;
            }

            this.CalculateGradeAndTotalScore();
        }
Exemplo n.º 11
0
        // ( double max-int -- int )
        public override void Execute(Interpreter interp)
        {
            IntItem    maxVal   = (IntItem)interp.StackPop();
            DoubleItem value    = (DoubleItem)interp.StackPop();
            int        intValue = value.IntValue;

            if (intValue < 0)
            {
                intValue = 0;
            }
            if (intValue > maxVal.IntValue - 1)
            {
                intValue = maxVal.IntValue - 1;
            }
            interp.StackPush(new IntItem(intValue));
        }
Exemplo n.º 12
0
        void ch2Example()
        {
            Interpreter interp = RaytraceInterpreter.MakeInterp();

            double pos(string axis)
            {
                interp.Run(String.Format("{0}-POS", axis));
                DoubleItem item = (DoubleItem)interp.StackPop();

                return(item.DoubleValue);
            }

            interp.RegisterModule(new Ch1Module());
            interp.Run(@"
            [ Ch1 canvas ] USE-MODULES
            [ '_canvas' '_color' ] VARIABLES
             900 550 Canvas _canvas !
             0 0 1 Color _color !
            : CHART   _canvas @ ;
            ");

            interp.Run("0 1 0 Point POSITION!");
            interp.Run("1 1.8 0 Vector NORMALIZE 11.25 *  VELOCITY!");
            double y             = pos("Y");
            int    numIterations = 0;

            while (y > 0)
            {
                interp.Run("TICK");
                interp.Run("CHART ( X-POS 900 >CLAMPED-INT ) ( Y-POS 550 >CLAMPED-INT 550 FLIP-Y ) _color @ WRITE-PIXEL");
                y = pos("Y");
                numIterations++;
            }
            double x = pos("X");

            interp.Run("CHART >PPM");
            dynamic ppmData = interp.StackPop();

            writeFile("ch2.ppm", ppmData.StringValue);
            Debug.WriteLine("distance: {0}, numIterations: {1}", x, numIterations);
        }
Exemplo n.º 13
0
        ArrayItem intersections(Interpreter interp, SphereItem sphere, RayItem ray)
        {
            // Compute sphere_to_ray
            interp.StackPush(ray);
            interp.Run("'origin' REC@  0 0 0 Point -");
            Vector4Item sphere_to_ray = (Vector4Item)interp.StackPop();

            // Compute a
            interp.StackPush(ray);
            interp.Run("'direction' REC@ DUP DOT");
            DoubleItem a = (DoubleItem)interp.StackPop();

            // Compute b
            interp.StackPush(sphere_to_ray);
            interp.StackPush(ray);
            interp.Run("'direction' REC@ DOT 2 *");
            DoubleItem b = (DoubleItem)interp.StackPop();

            // Compute c
            interp.StackPush(sphere_to_ray);
            interp.Run("DUP DOT 1 -");
            DoubleItem c = (DoubleItem)interp.StackPop();

            float discriminant = b.FloatValue * b.FloatValue - 4.0f * a.FloatValue * c.FloatValue;

            ArrayItem result = new ArrayItem();

            if (discriminant < 0)
            {
                return(result);
            }
            else
            {
                double t1 = (-b.FloatValue - Math.Sqrt(discriminant)) / 2.0f / a.FloatValue;
                double t2 = (-b.FloatValue + Math.Sqrt(discriminant)) / 2.0f / a.FloatValue;
                result.Add(new IntersectionItem(t1, sphere));
                result.Add(new IntersectionItem(t2, sphere));
                return(result);
            }
        }
Exemplo n.º 14
0
        void compute_parameters()
        {
            double half_view = Math.Tan(FieldOfView.DoubleValue / 2.0f);
            double aspect = Hsize.DoubleValue / Vsize.DoubleValue;
            double half_width, half_height;

            if (aspect >= 1)
            {
                half_width  = half_view;
                half_height = half_view / aspect;
            }
            else
            {
                half_height = half_view;
                half_width  = half_view * aspect;
            }

            // Set params
            HalfWidth  = new DoubleItem(half_width);
            HalfHeight = new DoubleItem(half_height);
            PixelSize  = new DoubleItem(half_width * 2.0f / Hsize.DoubleValue);
        }
Exemplo n.º 15
0
 public bool Match(DoubleItem item)
 {
     return item.Value == 41.99;
 }
Exemplo n.º 16
0
 BoolItem get_result(IntersectionItem h, DoubleItem distance)
 {
     return(new BoolItem(h.T < distance.DoubleValue));
 }
Exemplo n.º 17
0
 BoolItem get_result(NullItem h, DoubleItem distance)
 {
     return(new BoolItem(false));
 }
Exemplo n.º 18
0
 public bool Match(DoubleItem item)
 {
     return(item.Value == 41.99);
 }
Exemplo n.º 19
0
 StackItem negate(DoubleItem item)
 {
     return(new DoubleItem(-item.DoubleValue));
 }