コード例 #1
0
ファイル: Sphere.cs プロジェクト: rzel/sunflowsharp
        public void intersectPrimitive(Ray r, int primID, IntersectionState state)
        {
            // intersect in local space
            float qa = r.dx * r.dx + r.dy * r.dy + r.dz * r.dz;
            float qb = 2 * ((r.dx * r.ox) + (r.dy * r.oy) + (r.dz * r.oz));
            float qc = ((r.ox * r.ox) + (r.oy * r.oy) + (r.oz * r.oz)) - 1;

            double[] t = Solvers.solveQuadric(qa, qb, qc);
            if (t != null)
            {
                // early rejection
                if (t[0] >= r.getMax() || t[1] <= r.getMin())
                {
                    return;
                }
                if (t[0] > r.getMin())
                {
                    r.setMax((float)t[0]);
                }
                else
                {
                    r.setMax((float)t[1]);
                }
                state.setIntersection(0, 0, 0);
            }
        }
コード例 #2
0
        protected void Initialize()
        {
            if (ResourceSet == null)
            {
                ResourceSet = new FuriganaResourceSet();
                ResourceSet.Load();
            }

            if (Solvers == null)
            {
                Solvers = new List <FuriganaSolver>()
                {
                    new KanaReadingSolver(),
                    new KanjiReadingSolver(useNanori: DictionaryFile == DictionaryFile.Jmnedict),
                    new LengthMatchSolver(),
                    new NoConsecutiveKanjiSolver(),
                    new OverrideSolver(),
                    new RepeatedKanjiSolver(),
                    new SingleCharacterSolver(),
                    new SingleKanjiSolver()
                };
            }
            Solvers.Sort();
            Solvers.Reverse();
        }
コード例 #3
0
        public void intersectPrimitive(Ray r, int primID, IntersectionState state)
        {
            int   i3  = primID * 3;
            float ocx = r.ox - particles[i3 + 0];
            float ocy = r.oy - particles[i3 + 1];
            float ocz = r.oz - particles[i3 + 2];
            float qa  = r.dx * r.dx + r.dy * r.dy + r.dz * r.dz;
            float qb  = 2 * ((r.dx * ocx) + (r.dy * ocy) + (r.dz * ocz));
            float qc  = ((ocx * ocx) + (ocy * ocy) + (ocz * ocz)) - r2;

            double[] t = Solvers.solveQuadric(qa, qb, qc);
            if (t != null)
            {
                // early rejection
                if (t[0] >= r.getMax() || t[1] <= r.getMin())
                {
                    return;
                }
                if (t[0] > r.getMin())
                {
                    r.setMax((float)t[0]);
                }
                else
                {
                    r.setMax((float)t[1]);
                }
                state.setIntersection(primID);
            }
        }
コード例 #4
0
        private FuriganaSolutionSet Process(VocabEntry v)
        {
            FuriganaSolutionSet solutionSet = new FuriganaSolutionSet(v);

            int priority = Solvers.First().Priority;

            foreach (FuriganaSolver solver in Solvers)
            {
                if (solver.Priority < priority)
                {
                    if (solutionSet.Any())
                    {
                        // Priority goes down and we already have solutions.
                        // Stop solving.
                        break;
                    }

                    // No solutions yet. Continue with the next level of priority.
                    priority = solver.Priority;
                }

                // Add all solutions if they are correct and unique.
                solutionSet.SafeAdd(solver.Solve(ResourceSet, v));
            }

            return(solutionSet);
        }
コード例 #5
0
ファイル: FsMathTests.cs プロジェクト: lulzzz/Lyzard
        public void RungeKutta_solver_test_simple_ODE()
        {
            var func   = Converters.convert3 <double, double, double>((x, y) => Math.Exp(x));
            var result = Solvers.RungeKutta4(0.0, 1.0, 0.01, 1.0, func);

            Assert.That(result.Length == 100);
        }
コード例 #6
0
ファイル: Solver.cs プロジェクト: Levvy055/AiRTech
 public static Solver GetSolverFor(SubjectType subjectType)
 {
     if (Solvers.ContainsKey(subjectType))
     {
         return(Solvers[subjectType]);
     }
     return(null);
 }
コード例 #7
0
        /// <summary>
        /// Validates the options and also ensures that all <c>null</c> properties are
        /// initialized to their default values.
        /// </summary>
        /// <param name="clusterDefinition">The cluster definition.</param>
        /// <exception cref="ClusterDefinitionException">Thrown if the definition is not valid.</exception>
        public void Validate(ClusterDefinition clusterDefinition)
        {
            Covenant.Requires <ArgumentNullException>(clusterDefinition != null, nameof(clusterDefinition));

            var acmeIssuerPrefix = $"{nameof(AcmeIssuer)}";

            if (string.IsNullOrEmpty(Server))
            {
                Server = "https://acme-v02.api.letsencrypt.org/directory";
            }

            Solvers = Solvers ?? new List <AcmeChallengeSolver>();

            if (!Solvers.Any(solver => solver.Dns01?.Webhook?.SolverName == "neoncluster_io"))
            {
                var neonWebhookSolver = new AcmeIssuerDns01ProviderWebhook()
                {
                    Config = new Dictionary <string, object>()
                    {
                        { "Registrar", "route53" }
                    },
                    GroupName  = "acme.neoncloud.io",
                    SolverName = "neoncluster_io"
                };

                Solvers.Add(new AcmeChallengeSolver()
                {
                    Dns01 = new AcmeChallengeSolverDns01()
                    {
                        Webhook = neonWebhookSolver
                    },
                    Selector = new CertificateDnsNameSelector()
                    {
                        DnsZones = new List <string>()
                        {
                            "neoncluster.io"
                        }
                    }
                });
            }

            foreach (var solver in Solvers)
            {
                solver.Validate(clusterDefinition);
            }

            PrivateKeySecretRef = PrivateKeySecretRef ?? new AcmeSecretKeySelector()
            {
                Name = "neon-acme-issuer-account-key",
                Key  = "tls.key"
            };

            if (ExternalAccountBinding != null)
            {
                ExternalAccountBinding.Validate(clusterDefinition);
            }
        }
コード例 #8
0
        public CurlingSimViewModel()
        {
            GenerateRandomCommand = new SimpleDelegateCommand(() => GenerateRandom());
            SolveCommand          = new SimpleDelegateCommand(() => Solve());
            CloseCommand          = new SimpleDelegateCommand(() => Close());

            Solvers.Add(new CurlingSimSolverRunner("Discrete Solver", (r, x) => new DiscreteSolver(r, x)));
            Solvers.Add(new CurlingSimSolverRunner("Proximity Solver", (r, x) => new ProximitySolver(r, x)));
            Solvers.Add(new CurlingSimSolverRunner("Brute Solver", (r, x) => new BruteSolver(r, x)));
        }
コード例 #9
0
        public void BouncingBallTest(double h, double bounce, double window, double expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            int actual = solvers.BouncingBall(h, bounce, window);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #10
0
        public void GreetTest(string expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            string actual = solvers.Greet();

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #11
0
        public void NarcissisticTest(int value, bool expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            bool actual = solvers.Narcissistic(value);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #12
0
        public void GetSumTest(int a, int b, int expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            int actual = solvers.GetSum(a, b);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #13
0
        public void CombatTest(int health, int damage, float expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            float actual = solvers.Combat(health, damage);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #14
0
        public void ReverseWordsTest(string str, string expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            string actual = solvers.ReverseWords(str);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #15
0
        public void EvenOrOddTest(int number, string expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            string actual = solvers.EvenOrOdd(number);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #16
0
        public void IsDivisibleTest(int wallLength, int pixelSize, bool expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            bool actual = solvers.IsDivisible(wallLength, pixelSize);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #17
0
        public void IsLockNessMonsterTest(string sentance, bool expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            bool actual = solvers.IsLockNessMonster(sentance);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #18
0
        public void RGBToHexTest(int r, int g, int b, string expected)
        {
            //Arrange
            Solvers solver = new Solvers();

            //Act
            string actual = solver.RGBToHex(r, g, b);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #19
0
        public void BmiTest(double weight, double height, string expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            string actual = solvers.Bmi(weight, height);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #20
0
        public void SolutionTest(int value, int expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            int actual = solvers.Solution(value);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #21
0
        public void NthFib(int n, int expected)
        {
            //Arrange
            Solvers solvers = new Solvers();

            //Act
            int actual = solvers.NthFib(n);

            //Assert
            Assert.Equal(expected, actual);
        }
コード例 #22
0
        public void intersectPrimitive(Ray r, int primID, IntersectionState state)
        {
            // intersect in local space
            float rd2x = r.dx * r.dx;
            float rd2y = r.dy * r.dy;
            float rd2z = r.dz * r.dz;
            float ro2x = r.ox * r.ox;
            float ro2y = r.oy * r.oy;
            float ro2z = r.oz * r.oz;
            // compute some common factors
            double alpha = rd2x + rd2y + rd2z;
            double beta  = 2 * (r.ox * r.dx + r.oy * r.dy + r.oz * r.dz);
            double gamma = (ro2x + ro2y + ro2z) - ri2 - ro2;
            // setup quartic coefficients
            double A = alpha * alpha;
            double B = 2 * alpha * beta;
            double C = beta * beta + 2 * alpha * gamma + 4 * ro2 * rd2z;
            double D = 2 * beta * gamma + 8 * ro2 * r.oz * r.dz;
            double E = gamma * gamma + 4 * ro2 * ro2z - 4 * ro2 * ri2;

            // solve equation
            double[] t = Solvers.solveQuartic(A, B, C, D, E);
            if (t != null)
            {
                // early rejection
                if (t[0] >= r.getMax() || t[t.Length - 1] <= r.getMin())
                {
                    return;
                }
                // find first intersection in front of the ray
                for (int i = 0; i < t.Length; i++)
                {
                    if (t[i] > r.getMin())
                    {
                        r.setMax((float)t[i]);
                        state.setIntersection(0);
                        return;
                    }
                }
            }
        }
コード例 #23
0
        public void intersectPrimitive(Ray r, int primID, IntersectionState state)
        {
            // intersect in local space
            float rd2x = r.dx * r.dx;
            float rd2y = r.dy * r.dy;
            float rd2z = r.dz * r.dz;
            float ro2x = r.ox * r.ox;
            float ro2y = r.oy * r.oy;
            float ro2z = r.oz * r.oz;
            // setup the quartic coefficients
            // some common terms could probably be shared across these
            double A = (rd2y * rd2y + rd2z * rd2z + rd2x * rd2x);
            double B = 4 * (r.oy * rd2y * r.dy + r.oz * r.dz * rd2z + r.ox * r.dx * rd2x);
            double C = (-rd2x - rd2y - rd2z + 6 * (ro2y * rd2y + ro2z * rd2z + ro2x * rd2x));
            double D = 2 * (2 * ro2z * r.oz * r.dz - r.oz * r.dz + 2 * ro2x * r.ox * r.dx + 2 * ro2y * r.oy * r.dy - r.ox * r.dx - r.oy * r.dy);
            double E = 3.0f / 8.0f + (-ro2z + ro2z * ro2z - ro2y + ro2y * ro2y - ro2x + ro2x * ro2x);

            // solve equation
            double[] t = Solvers.solveQuartic(A, B, C, D, E);
            if (t != null)
            {
                // early rejection
                if (t[0] >= r.getMax() || t[t.Length - 1] <= r.getMin())
                {
                    return;
                }
                // find first intersection in front of the ray
                for (int i = 0; i < t.Length; i++)
                {
                    if (t[i] > r.getMin())
                    {
                        r.setMax((float)t[i]);
                        state.setIntersection(0);
                        return;
                    }
                }
            }
        }
コード例 #24
0
ファイル: JuliaFractal.cs プロジェクト: Jimbobicus/PhotonPump
        public void intersectPrimitive(Ray r, int primID, IntersectionState state)
        {
            // intersect with bounding sphere
            float qc = ((r.ox * r.ox) + (r.oy * r.oy) + (r.oz * r.oz)) - BOUNDING_RADIUS2;
            float qt = r.getMin();

            if (qc > 0)
            {
                // we are starting outside the sphere, find intersection on the
                // sphere
                float    qa = r.dx * r.dx + r.dy * r.dy + r.dz * r.dz;
                float    qb = 2 * ((r.dx * r.ox) + (r.dy * r.oy) + (r.dz * r.oz));
                double[] t  = Solvers.solveQuadric(qa, qb, qc);
                // early rejection
                if (t == null || t[0] >= r.getMax() || t[1] <= r.getMin())
                {
                    return;
                }
                qt = (float)t[0];
            }
            float dist         = float.PositiveInfinity;
            float rox          = r.ox + qt * r.dx;
            float roy          = r.oy + qt * r.dy;
            float roz          = r.oz + qt * r.dz;
            float invRayLength = (float)(1 / Math.Sqrt(r.dx * r.dx + r.dy * r.dy + r.dz * r.dz));

            // now we can start intersection
            while (true)
            {
                float zw = rox;
                float zx = roy;
                float zy = roz;
                float zz = 0;

                float zpw = 1;
                float zpx = 0;
                float zpy = 0;
                float zpz = 0;

                // run several iterations
                float dotz = 0;
                for (int i = 0; i < maxIterations; i++)
                {
                    {
                        // zp = 2 * (z * zp)
                        float nw = zw * zpw - zx * zpx - zy * zpy - zz * zpz;
                        float nx = zw * zpx + zx * zpw + zy * zpz - zz * zpy;
                        float ny = zw * zpy + zy * zpw + zz * zpx - zx * zpz;
                        zpz = 2 * (zw * zpz + zz * zpw + zx * zpy - zy * zpx);
                        zpw = 2 * nw;
                        zpx = 2 * nx;
                        zpy = 2 * ny;
                    }
                    {
                        // z = z*z + c
                        float nw = zw * zw - zx * zx - zy * zy - zz * zz + cw;
                        zx = 2 * zw * zx + cx;
                        zy = 2 * zw * zy + cy;
                        zz = 2 * zw * zz + cz;
                        zw = nw;
                    }
                    dotz = zw * zw + zx * zx + zy * zy + zz * zz;
                    if (dotz > ESCAPE_THRESHOLD)
                    {
                        break;
                    }
                }
                float normZ = (float)Math.Sqrt(dotz);
                dist = 0.5f * normZ * (float)Math.Log(normZ) / Length(zpw, zpx, zpy, zpz);
                rox += dist * r.dx;
                roy += dist * r.dy;
                roz += dist * r.dz;
                qt  += dist;
                if (dist * invRayLength < epsilon)
                {
                    break;
                }
                if (rox * rox + roy * roy + roz * roz > BOUNDING_RADIUS2)
                {
                    return;
                }
            }
            // now test t value again
            if (!r.isInside(qt))
            {
                return;
            }
            if (dist * invRayLength < epsilon)
            {
                // valid hit
                r.setMax(qt);
                state.setIntersection(0);
            }
        }
コード例 #25
0
 public override Workflow Copy(string id, string name = null, string parentName = null)
 {
     return(new WorkflowReversedModel(id, Description, ModelDataInputs.ToList(), ModelDataOutputs.ToList(),
                                      Model, Solvers.ToList(), parentName ?? parentName));
 }
コード例 #26
0
ファイル: SphereLight.cs プロジェクト: rzel/sunflowsharp
        public void getSamples(ShadingState state)
        {
            if (getNumSamples() <= 0)
            {
                return;
            }
            Vector3 wc = Point3.sub(center, state.getPoint(), new Vector3());
            float   l2 = wc.LengthSquared();

            if (l2 <= r2)
            {
                return; // inside the sphere?
            }
            // top of the sphere as viewed from the current shading point
            float topX = wc.x + state.getNormal().x *radius;
            float topY = wc.y + state.getNormal().y *radius;
            float topZ = wc.z + state.getNormal().z *radius;

            if (state.getNormal().dot(topX, topY, topZ) <= 0)
            {
                return; // top of the sphere is below the horizon
            }
            float            cosThetaMax = (float)Math.Sqrt(Math.Max(0, 1 - r2 / Vector3.dot(wc, wc)));
            OrthoNormalBasis basis       = OrthoNormalBasis.makeFromW(wc);
            int   samples = state.getDiffuseDepth() > 0 ? 1 : getNumSamples();
            float scale   = (float)(2 * Math.PI * (1 - cosThetaMax));
            Color c       = Color.mul(scale / samples, radiance);

            for (int i = 0; i < samples; i++)
            {
                // random offset on unit square
                double randX = state.getRandom(i, 0, samples);
                double randY = state.getRandom(i, 1, samples);

                // cone sampling
                double  cosTheta = (1 - randX) * cosThetaMax + randX;
                double  sinTheta = Math.Sqrt(1 - cosTheta * cosTheta);
                double  phi      = randY * 2 * Math.PI;
                Vector3 dir      = new Vector3((float)(Math.Cos(phi) * sinTheta), (float)(Math.Sin(phi) * sinTheta), (float)cosTheta);
                basis.transform(dir);

                // check that the direction of the sample is the same as the
                // normal
                float cosNx = Vector3.dot(dir, state.getNormal());
                if (cosNx <= 0)
                {
                    continue;
                }

                float    ocx = state.getPoint().x - center.x;
                float    ocy = state.getPoint().y - center.y;
                float    ocz = state.getPoint().z - center.z;
                float    qa  = Vector3.dot(dir, dir);
                float    qb  = 2 * ((dir.x * ocx) + (dir.y * ocy) + (dir.z * ocz));
                float    qc  = ((ocx * ocx) + (ocy * ocy) + (ocz * ocz)) - r2;
                double[] t   = Solvers.solveQuadric(qa, qb, qc);
                if (t == null)
                {
                    continue;
                }
                LightSample dest = new LightSample();
                // compute shadow ray to the sampled point
                dest.setShadowRay(new Ray(state.getPoint(), dir));
                // FIXME: arbitrary bias, should handle as in other places
                dest.getShadowRay().setMax((float)t[0] - 1e-3f);
                // prepare sample
                dest.setRadiance(c, c);
                dest.traceShadow(state);
                state.addSample(dest);
            }
        }
コード例 #27
0
 public override Workflow Copy(string id, string name = null, string parentName = null)
 {
     return(new WorkflowGlobal(id, Description, ModelDataInputs.ToList(), ModelDataOutputs.ToList(),
                               Components.ToList(), ScheduledComponents.ToList(), Solvers.ToList(), IsAuxiliary, ScheduleMode, parentName ?? parentName));
 }
コード例 #28
0
 //TODO: will be filled in
 public void SimulateDiffusionDecay(float deltaTime)
 {
     Solvers.DiffusionDecaySolverConstantCoefficientsLOD3D(this, deltaTime);
 }
コード例 #29
0
ファイル: Solver.cs プロジェクト: Levvy055/AiRTech
 protected Solver(SubjectType subjectType)
 {
     SubjectType = subjectType;
     Solvers.Add(subjectType, this);
 }