Esempio n. 1
0
            internal InternalKdNode Split(out LeafKdNode rightSibling)
            {
                Particle.Dim splitDirection =
                    Dimension(Particle.Dim.Horizontal) > Dimension(Particle.Dim.Vertical)
                    ? Particle.Dim.Horizontal : Particle.Dim.Vertical;
                Particle.Dim nonSplitDirection =
                    splitDirection == Particle.Dim.Horizontal
                    ? Particle.Dim.Vertical : Particle.Dim.Horizontal;
                int n = Size(), nLeft = n / 2, nRight = n - nLeft;

                Particle[][]
                leftParticles = new Particle[][] { new Particle[nLeft], new Particle[nLeft] },
                rightParticles = new Particle[][] { new Particle[nRight], new Particle[nRight] };
                int lCtr = 0, rCtr = 0;

                for (int i = 0; i < n; ++i)
                {
                    Particle p = particles[(int)splitDirection][i];
                    if (i < nLeft)
                    {
                        leftParticles[(int)splitDirection][i] = p;
                        p.splitLeft = true;
                    }
                    else
                    {
                        rightParticles[(int)splitDirection][i - nLeft] = p;
                        p.splitLeft = false;
                    }
                }
                for (int i = 0; i < n; ++i)
                {
                    Particle p = particles[(int)nonSplitDirection][i];
                    if (p.splitLeft)
                    {
                        leftParticles[(int)nonSplitDirection][lCtr++] = p;
                    }
                    else
                    {
                        rightParticles[(int)nonSplitDirection][rCtr++] = p;
                    }
                }
                Debug.Assert(lCtr == nLeft);
                Debug.Assert(rCtr == nRight);
                Disc parentMED = med;

                particles = leftParticles;
                ComputeMED();
                rightSibling = new LeafKdNode(rightParticles);
                return(new InternalKdNode(parentMED, this, rightSibling));
            }
Esempio n. 2
0
 private double Dimension(Particle.Dim d)
 {
     return(Max(d) - Min(d));
 }
Esempio n. 3
0
 private double Min(Particle.Dim d)
 {
     return(particles[(int)d][0].pos(d));
 }
Esempio n. 4
0
 private double Max(Particle.Dim d)
 {
     return(particles[(int)d][Size() - 1].pos(d));
 }
Esempio n. 5
0
 private Particle[] particlesBy(Particle.Dim d)
 {
     return((from Particle p in particles
             orderby p.pos(d)
             select p).ToArray());
 }