void DirectProcess11(
    std::vector<BinData2<1,3> >& data, const NCell& c1, const Cell& c2,
    const double dsq, const Position2D& r)
{
    xdbg<<std::string(recursen+1,'-')<<"Direct: d = "<<sqrt(dsq)<<std::endl;
    XAssert(c1.getSize()+c2.getSize() < sqrt(dsq)*b + 0.0001);
    XAssert(std::abs(c2.getMeanPos() - c1.getMeanPos() - r) < 0.0001);
    XAssert(std::abs(dsq - std::norm(r)) < 0.0001);

    Assert(dsq >= minsepsq);
    Assert(dsq < maxsepsq);

    std::complex<double> cr(r.getX(),r.getY());
    const std::complex<double> expm2iarg = SQR(conj(cr))/dsq;

    const double logr = log(dsq)/2.;
    Assert(logr >= logminsep);

    const int k = int(floor((logr - logminsep)/binsize));
    Assert(k >= 0); Assert(k<int(data.size()));

    const double nw = c1.getN()*c2.getWeight();
    const std::complex<double> net = -double(c1.getN())*c2.getWE()*expm2iarg;
    const double npairs = c1.getN()*c2.getN();

    BinData2<1,3>& crossbin = data[k];
    crossbin.meangammat += net;
    crossbin.weight += nw;
    crossbin.meanlogr += nw*logr;
    crossbin.npair += npairs;
}
void GameEntity::_move(Position2D newPosition, bool lockInWindowScreen)
{
    float x = newPosition.getX();
    float y = newPosition.getY();

    if (lockInWindowScreen)
    {
        _width = this->getINDIEntity()->getRegionWidth() / 2 - 18;
        _height = this->getINDIEntity()->getRegionHeight() / 2 - 15;

        if (x + _width > _masterInstance->_window->getWidth())
            x = _masterInstance->_window->getWidth() - _width;
        if (x - _width < 0)
            x = 0 + _width;
        if (y + _height > _masterInstance->_window->getHeight())
            y = _masterInstance->_window->getHeight() - _height;
        if (y - _height < 0)
            y = _height;
    }

    this->setPosition(Position3D(x, y, this->getPosition().getZ()));
}
void DirectProcess11(
    std::vector<BinData2<3,3> >& data, const Cell& c1, const Cell& c2,
    const double dsq, const Position2D& r)
{
    XAssert(c1.getSize()+c2.getSize() < sqrt(dsq)*b + 0.0001);
    XAssert(Dist(c2.getMeanPos() - c1.getMeanPos(),r) < 0.0001);
    XAssert(std::abs(dsq - DistSq(c1.getMeanPos(),c2.getMeanPos())) < 0.0001);

    Assert(dsq > minsepsq);
    Assert(dsq < maxsepsq);

    std::complex<double> cr(r.getX(),r.getY());
    std::complex<double> expm4iarg = conj(cr*cr)/dsq; // now expm2iarg
    expm4iarg *= expm4iarg; // now expm4iarg

    const double logr = log(dsq)/2.;
    Assert(logr >= logminsep);

    const int k = int(floor((logr - logminsep)/binsize));
    Assert(k >= 0); Assert(k<int(data.size()));

    const double ww = c1.getWeight()*c2.getWeight();
    const std::complex<double> e1 = c1.getWE();
    const std::complex<double> e2 = c2.getWE();

    const std::complex<double> ee = e1*e2*expm4iarg;
    const std::complex<double> eec = e1*conj(e2);

    const double npairs = c1.getN()*c2.getN();

    BinData2<3,3>& bindata = data[k];
    bindata.xiplus += eec;
    bindata.ximinus += ee;
    bindata.weight += ww;
    bindata.meanlogr += ww*logr;
    bindata.npair += npairs;

    ++bincount[k];
}