Пример #1
0
        public async Task <bool> IsInTram(IEnumerable <SensorsReading> sensorsReading)
        {
            var replies = await GetReplies(sensorsReading);

            return(_metric.Calculate(replies));
        }
Пример #2
0
        protected void CalculateDistance(float x, float y, float z, out VoronoiDistance result)
        {
            result = new VoronoiDistance
            {
                Distance0 = float.MaxValue,
                Distance1 = float.MaxValue,
                Distance2 = float.MaxValue,
                Distance3 = float.MaxValue
            };

            int xi = MathExtension.Floor(x);
            int yi = MathExtension.Floor(y);
            int zi = MathExtension.Floor(z);

            // NOTE:
            //
            // Why does libnoise use cells in [-1, 2] ? For accuracy ?
            // Standard voronoi algorithms use cells in [-1, 1].

            // Inside each unit cube, there is a seed point at a random position.
            // Go through each of the nearby cubes until we find a cube with a seed point
            // that is closest to the specified position.
            for (int zz = zi - 1; zz <= zi + 1; zz++)
            {
                for (int yy = yi - 1; yy <= yi + 1; yy++)
                {
                    for (int xx = xi - 1; xx <= xi + 1; xx++)
                    {
                        //for (int zz = zi - 2; zz <= zi + 2; zz++)
                        //{
                        //    for (int yy = yi - 2; yy <= yi + 2; yy++)
                        //    {
                        //        for (int xx = xi - 2; xx <= xi + 2; xx++)
                        //        {
                        // Calculate the position and distance to the seed point
                        // inside of this unit cube.
                        float xp = xx + GetPosition(xx, yy, zz, seed);
                        float yp = yy + GetPosition(xx, yy, zz, seed + 1);
                        float zp = zz + GetPosition(xx, yy, zz, seed + 2);
                        float xd = xp - x;
                        float yd = yp - y;
                        float zd = zp - z;

                        // Calculate the distance with the specified metric.
                        float d = metric.Calculate(xd, yd, zd);

                        if (d < result.Distance0)
                        {
                            result.Distance3 = result.Distance2;
                            result.Distance2 = result.Distance1;
                            result.Distance1 = result.Distance0;
                            result.Distance0 = d;

                            result.Position3   = result.Position2;
                            result.Position2   = result.Position1;
                            result.Position1   = result.Position0;
                            result.Position0.X = xp;
                            result.Position0.Y = yp;
                            result.Position0.Z = zp;
                        }
                        else if (d < result.Distance1)
                        {
                            result.Distance3 = result.Distance2;
                            result.Distance2 = result.Distance1;
                            result.Distance1 = d;

                            result.Position3   = result.Position2;
                            result.Position2   = result.Position1;
                            result.Position1.X = xp;
                            result.Position1.Y = yp;
                            result.Position1.Z = zp;
                        }
                        else if (d < result.Distance2)
                        {
                            result.Distance3 = result.Distance2;
                            result.Distance2 = d;

                            result.Position3   = result.Position2;
                            result.Position2.X = xp;
                            result.Position2.Y = yp;
                            result.Position2.Z = zp;
                        }
                        else if (d < result.Distance3)
                        {
                            result.Distance3 = d;

                            result.Position3.X = xp;
                            result.Position3.Y = yp;
                            result.Position3.Z = zp;
                        }
                    }
                }
            }
        }