Example #1
0
long irc::portparser::GetToken()
{
	if (in_range > 0)
	{
		in_range++;
		if (in_range <= range_end)
		{
			if (!Overlaps(in_range))
			{
				return in_range;
			}
			else
			{
				while (((Overlaps(in_range)) && (in_range <= range_end)))
					in_range++;

				if (in_range <= range_end)
					return in_range;
			}
		}
		else
			in_range = 0;
	}

	std::string x;
	sep.GetToken(x);

	if (x.empty())
		return 0;

	while (Overlaps(atoi(x.c_str())))
	{
		if (!sep.GetToken(x))
			return 0;
	}

	std::string::size_type dash = x.rfind('-');
	if (dash != std::string::npos)
	{
		std::string sbegin = x.substr(0, dash);
		std::string send = x.substr(dash+1, x.length());
		range_begin = atoi(sbegin.c_str());
		range_end = atoi(send.c_str());

		if ((range_begin > 0) && (range_end > 0) && (range_begin < 65536) && (range_end < 65536) && (range_begin < range_end))
		{
			in_range = range_begin;
			return in_range;
		}
		else
		{
			/* Assume its just the one port */
			return atoi(sbegin.c_str());
		}
	}
	else
	{
		return atoi(x.c_str());
	}
}
Example #2
0
CRect& CRect::ClipTo(const CRect& r)
{

	if (! Overlaps(r))
	{
		m_Left = 0;
		m_Top = 0;
		m_Right = 0;
		m_Bottom = 0;
	}
	else
	{
		if (m_Left < r.m_Left)
		{
			m_Left = r.m_Left;
		}
		if (m_Top < r.m_Top)
		{
			m_Top = r.m_Top;
		}
		if (m_Right > r.m_Right)
		{
			m_Right = r.m_Right;
		}
		if (m_Bottom > r.m_Bottom)
		{
			m_Bottom = r.m_Bottom;
		}
	}

	return *this;
}
Example #3
0
File: mem.c Project: Kozakura/3dmoo
static int AddMapping(uint32_t base, uint32_t size)
{
    if(size == 0)
        return 0;

    if(num_mappings == MAX_MAPPINGS) {
        DEBUG("too many mappings.\n");
        return 1;
    }

    size_t i = num_mappings, j;
    mappings[i].base = base;
    mappings[i].size = size;

    for(j=0; j<num_mappings; j++) {
        if(Overlaps(&mappings[j], &mappings[i])) {
            DEBUG("trying to add overlapping mapping %08x, size=%08x.\n",
                  base, size);
            return 2;
        }
    }

    mappings[i].phys = calloc(sizeof(uint8_t), size);
    if(mappings[i].phys == NULL) {
        DEBUG("calloc failed for %08x, size=%08x\n", base, size);
        return 3;
    }

    num_mappings++;
    return 0;
}
Example #4
0
File: mem.c Project: Kozakura/3dmoo
int mem_AddMappingShared(uint32_t base, uint32_t size, u8* data)
{
    if (size == 0)
        return 0;

    if (num_mappings == MAX_MAPPINGS) {
        DEBUG("too many mappings.\n");
        return 1;
    }

    size_t i = num_mappings, j;
    mappings[i].base = base;
    mappings[i].size = size;

    for (j = 0; j<num_mappings; j++) {
        if (Overlaps(&mappings[j], &mappings[i])) {
            DEBUG("trying to add overlapping mapping %08x, size=%08x.\n",
                  base, size);
            return 2;
        }
    }

    mappings[i].phys = data;

    num_mappings++;
    return 0;
}
Example #5
0
bool GoChainCondition::Overlaps(const SgVectorOf<GoChainCondition>& 
                                conditions) const
{
    for (SgVectorIteratorOf<GoChainCondition> it(conditions); it; ++it)
    {
        if (Overlaps(**it))
            /* */ return true; /* */
    }
    return false;
}
static void NQN(Node * N, int Q, int start, int end, int K)
{
    int mid = (start + end) / 2, d;
    Node *T = KDTree[mid], P;
    int axis = T->Axis;

    if (start <= end && T != N && Contains(T, Q, N) &&
        !InCandidateSet(N, T) &&
        (!c || c(N, T) - N->Pi - T->Pi <= Radius) &&
        (d = Distance(N, T) * Precision) <= Radius) {
        int i = Candidates;
        while (--i >= 0 && d < CandidateSet[i].Cost)
            CandidateSet[i + 1] = CandidateSet[i];
        CandidateSet[i + 1].To = T;
        CandidateSet[i + 1].Cost = d;
        if (Candidates < K)
            Candidates++;
        if (Candidates == K)
            Radius = CandidateSet[Candidates - 1].Cost;
    }
    if (start < end && BoxOverlaps(T, Q, N)) {
        double diff = Coord(T, axis) - Coord(N, axis);
        P.X = axis == 0 ? T->X : N->X;
        P.Y = axis == 1 ? T->Y : N->Y;
        P.Z = axis == 2 ? T->Z : N->Z;
        P.Pi = 0;
        if (diff >= 0) {
            if (Overlaps(Q, diff, 0, axis))
                NQN(N, Q, start, mid - 1, K);
            if (Overlaps(Q, diff, 1, axis) &&
                (!c || c(N, &P) - N->Pi <= Radius) &&
                Distance(N, &P) * Precision <= Radius)
                NQN(N, Q, mid + 1, end, K);
        } else {
            if (Overlaps(Q, diff, 1, axis))
                NQN(N, Q, mid + 1, end, K);
            if (Overlaps(Q, diff, 0, axis) &&
                (!c || c(N, &P) - N->Pi <= Radius) &&
                Distance(N, &P) * Precision <= Radius)
                NQN(N, Q, start, mid - 1, K);
        }
    }
}
Example #7
0
unsigned
FlatBoundingBox::Distance(const FlatBoundingBox &f) const
{
  if (Overlaps(f))
    return 0;

  int dx = std::max(0, std::min(f.bb_ll.x - bb_ur.x,
                                bb_ll.x - f.bb_ur.x));
  int dy = std::max(0, std::min(f.bb_ll.y - bb_ur.y,
                                bb_ll.y - f.bb_ur.y));

  return ihypot(dx, dy);
}
Example #8
0
inline void IASRect::Intersect(const ADMRect& a)
{
	if (left < a.left)
		left = a.left;
	if (top < a.top)
		top = a.top;
	if (right > a.right)
		right = a.right;
	if (bottom > a.bottom)
		bottom = a.bottom;
		
	if (!Overlaps(a))
		SetEmpty();	
}
Example #9
0
inline void IASRealRectCartesian::Intersect(const AIRealRect &a)
{
	if (left < a.left)
		left = a.left;
	if (top > a.top)
		top = a.top;
	if (right > a.right)
		right = a.right;
	if (bottom < a.bottom)
		bottom = a.bottom;
		
	if (!Overlaps(a))
		SetEmpty();	
}
Example #10
0
bool CMatchBlock::OverlapAndSplit(const CMatchBlock & other, CMatchBlockVector & additionalBlocks)
{
	//  Three Senarios:  Other overlaps start of this.  Other Overlaps end of this.  This is contained between start and end of Other.
	ATLASSERT(m_length <= other.m_length);
	if (BaseOverlaps(other) && CompOverlaps(other)) //This is contained in Other
	{
	}
	else if (BaseOverlaps(other))
	{
	}
	else if(CompOverlaps(other))
	{
	}
	else
	{
		ATLASSERT(!Overlaps(other));
		return false;
	}
	return true;
}
Example #11
0
unsigned int BVHNode<BoundingVolumeType>::GetPotentialContactsWith(PotentialContact* contacts, unsigned int limit, BVHNode<BoundingVolumeType>* other)
{
    if (limit == 0)
        return 0;
        
    // If this region doesn't overlap with the other, there are no potential collisions
    if (!Overlaps(other))
        return 0;

    // Base case - If both regions are leaf nodes, we have a potential collision
    if (IsLeaf() && other->IsLeaf())
    {
        // We only consider potential collisions where at least one collider is dynamic
        if (!m_collider->IsStatic() || !other->m_collider->IsStatic())
        {
            contacts->colliders[0] = m_collider;
            contacts->colliders[1] = other->m_collider;
            return 1;
        }
        return 0;
    }

    // Determine which node to descend into:
    // If one region is a leaf, descend into the other.
    // Otherwise, descend into the node that has a larger volume
    BVHNode<BoundingVolumeType>* recursionNode = other;
    BVHNode<BoundingVolumeType>* nonRecursionNode = this;
    if (other->IsLeaf() || (!IsLeaf() && m_volume.GetSize() >= other->m_volume.GetSize()))
    {
        recursionNode = this;
        nonRecursionNode = other;
    }

    // Recurse:
    unsigned int count = recursionNode->m_children[0]->GetPotentialContactsWith(contacts, limit, nonRecursionNode);
    if (limit > count)
    {
        count += recursionNode->m_children[1]->GetPotentialContactsWith(contacts + count, limit - count, nonRecursionNode);
    }
    return count;
}
Example #12
0
inline void IASRealRectCartesian::Intersect(const AIRealRect &a, const AIRealRect &b)
{
	if (b.left < a.left)
		left = a.left;
	else
		left = b.left;
	if (b.top > a.top)
		top = a.top;
	else
		top = b.top;
	if (b.right > a.right)
		top = a.right;
	else
		top = b.right;
	if (b.bottom < a.bottom)
		bottom = a.bottom;
	else
		bottom = b.bottom;			
	if (!Overlaps(a))
		SetEmpty();	
} 
Example #13
0
inline void IASRect::Intersect(const ADMRect& a, const ADMRect& b)
{
	if (b.left < a.left)
		left = a.left;
	else
		left = b.left;
	if (b.top < a.top)
		top = a.top;
	else
		top = b.top;
	if (b.right > a.right)
		right = a.right;
	else
		right = b.right;
	if (b.bottom > a.bottom)
		bottom = a.bottom;
	else
		bottom = b.bottom;			
	if (!Overlaps(a))
		SetEmpty();	
} 
Example #14
0
BOOL CLogFile::FindTouchingWriteCommands(int iStartIndex, CArrayIntAndPointer* papvOverlapping, filePos iPosition, filePos iLength, BOOL bMustOverlap)
{
	int						iIndex;
	CLogFileCommandWrite*	psWrite;
	CLogFileCommand*		psCommand;
	BOOL					bInitialised;

	bInitialised = FALSE;
	if (!bMustOverlap)
	{
		iPosition--;
		iLength+=2;
	}

	for (iIndex = iStartIndex; iIndex < macCommands.NumElements(); iIndex++)
	{
		macCommands.Get(iIndex, (void**)&psCommand);
		if (psCommand->IsWrite())
		{
			psWrite = (CLogFileCommandWrite*)psCommand;
			if (Overlaps(iPosition, iLength, psWrite))
			{
				if (!bInitialised)
				{
					papvOverlapping->Init(8);
					bInitialised = TRUE;
				}

				papvOverlapping->Add(psWrite, iIndex);
			}
		}
		else
		{
			break;
		}
	}

	return bInitialised;
}
Example #15
0
bool Curve::recursiveIntersect(const Ray &ray, Float *tHit,
                               SurfaceInteraction *isect, const Point3f cp[4],
                               const Transform &rayToObject, Float u0, Float u1,
                               int depth) const {
    // Try to cull curve segment versus ray

    // Compute bounding box of curve segment, _curveBounds_
    Bounds3f curveBounds =
        Union(Bounds3f(cp[0], cp[1]), Bounds3f(cp[2], cp[3]));
    Float maxWidth = std::max(Lerp(u0, common->width[0], common->width[1]),
                              Lerp(u1, common->width[0], common->width[1]));
    curveBounds = Expand(curveBounds, 0.5 * maxWidth);

    // Compute bounding box of ray, _rayBounds_
    Float rayLength = ray.d.Length();
    Float zMax = rayLength * ray.tMax;
    Bounds3f rayBounds(Point3f(0, 0, 0), Point3f(0, 0, zMax));
    if (Overlaps(curveBounds, rayBounds) == false) return false;
    if (depth > 0) {
        // Split curve segment into sub-segments and test for intersection
        Float uMid = 0.5f * (u0 + u1);
        Point3f cpSplit[7];
        SubdivideBezier(cp, cpSplit);
        return (recursiveIntersect(ray, tHit, isect, &cpSplit[0], rayToObject,
                                   u0, uMid, depth - 1) ||
                recursiveIntersect(ray, tHit, isect, &cpSplit[3], rayToObject,
                                   uMid, u1, depth - 1));
    } else {
        // Intersect ray with curve segment

        // Test ray against segment endpoint boundaries
        Vector2f segmentDirection = Point2f(cp[3]) - Point2f(cp[0]);

        // Test sample point against tangent perpendicular at curve start
        Float edge =
            (cp[1].y - cp[0].y) * -cp[0].y + cp[0].x * (cp[0].x - cp[1].x);
        if (edge < 0) return false;

        // Test sample point against tangent perpendicular at curve end
        // TODO: update to match the starting test.
        Vector2f endTangent = Point2f(cp[2]) - Point2f(cp[3]);
        if (Dot(segmentDirection, endTangent) < 0) endTangent = -endTangent;
        if (Dot(endTangent, Vector2f(cp[3])) < 0) return false;

        // Compute line $w$ that gives minimum distance to sample point
        Float denom = Dot(segmentDirection, segmentDirection);
        if (denom == 0) return false;
        Float w = Dot(-Vector2f(cp[0]), segmentDirection) / denom;

        // Compute $u$ coordinate of curve intersection point and _hitWidth_
        Float u = Clamp(Lerp(w, u0, u1), u0, u1);
        Float hitWidth = Lerp(u, common->width[0], common->width[1]);
        Normal3f nHit;
        if (common->type == CurveType::Ribbon) {
            // Scale _hitWidth_ based on ribbon orientation
            Float sin0 = std::sin((1 - u) * common->normalAngle) *
                         common->invSinNormalAngle;
            Float sin1 =
                std::sin(u * common->normalAngle) * common->invSinNormalAngle;
            nHit = sin0 * common->n[0] + sin1 * common->n[1];
            hitWidth *= AbsDot(nHit, -ray.d / rayLength);
        }

        // Test intersection point against curve width
        Vector3f dpcdw;
        Point3f pc = EvalBezier(cp, Clamp(w, 0, 1), &dpcdw);
        Float ptCurveDist2 = pc.x * pc.x + pc.y * pc.y;
        if (ptCurveDist2 > hitWidth * hitWidth * .25) return false;
        if (pc.z < 0 || pc.z > zMax) return false;

        // Compute $v$ coordinate of curve intersection point
        Float ptCurveDist = std::sqrt(ptCurveDist2);
        Float edgeFunc = dpcdw.x * -pc.y + pc.x * dpcdw.y;
        Float v = (edgeFunc > 0.) ? 0.5f + ptCurveDist / hitWidth
                                  : 0.5f - ptCurveDist / hitWidth;

        // Compute hit _t_ and partial derivatives for curve intersection
        if (tHit != nullptr) {
            // FIXME: this tHit isn't quite right for ribbons...
            *tHit = pc.z / rayLength;
            // Compute error bounds for curve intersection
            Vector3f pError(2 * hitWidth, 2 * hitWidth, 2 * hitWidth);

            // Compute $\dpdu$ and $\dpdv$ for curve intersection
            Vector3f dpdu, dpdv;
            EvalBezier(common->cpObj, u, &dpdu);
            if (common->type == CurveType::Ribbon)
                dpdv = Normalize(Cross(nHit, dpdu)) * hitWidth;
            else {
                // Compute curve $\dpdv$ for flat and cylinder curves
                Vector3f dpduPlane = (Inverse(rayToObject))(dpdu);
                Vector3f dpdvPlane =
                    Normalize(Vector3f(-dpduPlane.y, dpduPlane.x, 0)) *
                    hitWidth;
                if (common->type == CurveType::Cylinder) {
                    // Rotate _dpdvPlane_ to give cylindrical appearance
                    Float theta = Lerp(v, -90., 90.);
                    Transform rot = Rotate(-theta, dpduPlane);
                    dpdvPlane = rot(dpdvPlane);
                }
                dpdv = rayToObject(dpdvPlane);
            }
            *isect = (*ObjectToWorld)(SurfaceInteraction(
                ray(pc.z), pError, Point2f(u, v), -ray.d, dpdu, dpdv,
                Normal3f(0, 0, 0), Normal3f(0, 0, 0), ray.time, this));
        }
        ++nHits;
        return true;
    }
}
Example #16
0
void LAYER::LayPath( int32_t wX, int32_t wY )
{
	int DeltaDir;
	LOGICAL bLoop = FALSE, bIsRetry;  // no looping....
	int tx, ty;
	int nPathLayed = 0;
	int nDir, nNewDir;
	LOGICAL bBackTrace = FALSE,
		bFailed = FALSE;

	PLAYER_PATH_NODE node;
	lprintf( WIDE("Laying path %p to %d,%d"), this, wX, wY );
	node = (PLAYER_PATH_NODE)PeekData( &pds_path );
	// sanity validations...
	// being done already, etc...
	wX -= LAYER::x;
	wY -= LAYER::y;
	if( node )
	{
		if( node->x == wX && node->y == wY )
		{
			lprintf( WIDE("Already at this end point, why are you telling me to end where I already did?") );
			return;
		}
		// should range check wX and wY to sane limits
		// but for now we'll trust the programmer...
		if( abs( node->x - wX ) > 100 || abs( node->y - wY ) > 100 )
		{
			DebugBreak();
			lprintf( WIDE("Laying a LONG path - is this okay?!") );
		}
	}

	#ifdef DEBUG_BACKTRACE
		Log( WIDE("Enter...") );
	#endif

		//------------ FORWARD DRAWING NOW .....
	bIsRetry = FALSE;
	DeltaDir = 0;
	{
		PLAYER_PATH_NODE node;
		// get the last node in the path.
		node = (PLAYER_PATH_NODE)PeekData( &pds_path );
		while( node )
		{
			nNewDir = FindDirection( node->x
										  , node->y
										  , wX, wY );
			if( nNewDir == NOWHERE )
			{
				// already have this node at the current spot...
				lprintf( WIDE("Node has ended here...") );
				break;
			}
			nDir = NOWHERE; // intialize this, in case we missed a path below...
			if( node->flags.BackDir == NOWHERE )
			{
				// if it is newdir, we're okay to go ahead with this plan.
				if( node->flags.ForeDir != nNewDir && flags.bForced )
				{
					lprintf( WIDE("Have a forced begin point, and no way to get there from here....") );
					DebugBreak();
					if( NearDir( node->flags.ForeDir, nNewDir ) == 10 )
					{
						lprintf( WIDE("MUST go %d , have to go %d from here.  Go nowhere."), node->flags.ForeDir, nNewDir );
						lprintf( WIDE("Okay - consider a arbitrary jump to go forward... until we can go backward.") );
					}
					else
					{
						lprintf( WIDE("It's just not quite right... return, a less radical assumption may be made.") );
					}
					return;
				}
				// else, just go ahead, we returned above here.
				node->flags.ForeDir = nNewDir;
			}
			else
			{
				// need to determine a valid foredir based on nNewDir desire, and nBackDir given.
				lprintf( WIDE("%d, %d = %d")
						 , Opposite( node->flags.BackDir )
						 , nNewDir
						 , NearDir(Opposite( node->flags.BackDir )
									 , nNewDir ) );
				lprintf( WIDE("newdir = %d backdir = %d"), nNewDir, node->flags.BackDir );
				//pold->TopLayer->ForeDir;
				if( NearDir( nNewDir, Opposite( node->flags.BackDir ) ) != 10 )
				{
					// this is a valid direction to go.
					node->flags.ForeDir = nNewDir;
				}
				else
				{
					lprintf( WIDE("Unlay path cause we can't get there from here.") );
					node = UnlayPath( nPathLayed + 1 );
					// at this point always unlay at least one more than we put down.
					nPathLayed = 1;
					continue;
#if 0
               int nBase = Opposite( node->flags.BackDir );
					nDir = ( node->flags.BackDir + 2 ) & 7;
					if( NearDir( nNewDir, nDir ) != 10 )
					{
						//node->flags.ForeDir = (nBase + 6) &7;
						node->flags.ForeDir = Right( nBase );
					}
					else if( NearDir( nNewDir, Opposite( nDir ) ) != 10 )
					{
						node->flags.ForeDir = Left(nBase);
					}
					else
					{

						// this should be a random chance to go left or right...
						// maybe tend to the lower x or higher x ?
						lprintf( WIDE("Choosing an arbitrary directino of 1, and only on1") );
						//node->flags.ForeDir = Right( nBase + 1 );
						node->flags.bFlopped = 0;
						node->flags.bTry = 1;
						node->flags.bForced = 1;
						node->flags.ForeDir = LeftOrRight( nBase, node->flags.bFlopped );
						// set a flag in this node for which way to go...
						// but a left/right node needs the ability
						// to remain forced for a single unlay, and move in a direction...

					}
#endif
				}
			}
			{
				int  n;
				tx = node->x + DirDeltaMap[node->flags.ForeDir].x;
				ty = node->y + DirDeltaMap[node->flags.ForeDir].y;
				lprintf( WIDE("New coordinate will be %d,%d"), tx, ty );
				if( n = Overlaps( tx, ty ) ) // aleady drew something here...
					// the distance of the overlap is n layers, including Nth layer
					// for( ; n; PopData(&pds_stack), n-- )
					// and some fixups which unlay path does.
				{
					lprintf( WIDE("Unlaying path %d steps to overlap") , n );
					node = UnlayPath( n );
					// at an unlay point of forced, unlay path should be 'smart' and 'wait'
					// otherwise we may unwind to our tail and be confused... specially when moving away
					// and coming back to reside at the center.
					// if the force direction to go from a forced node is excessive, that definatly
					// breaks force, and releases the path node.
					// there may be board conditions which also determine the pathing.
					// okay try this again from the top do {
					// startin laying path again.
					continue;
				}
				// otherwise we're good to go foreward.
				// at least we won't add this node if it would have
				// already been there, heck, other than that via's
				// don't exist, sometimes we'll even get the exact node
				// that this should be....
				{
					LAYER_PATH_NODE newnode;
					// this may be set intrinsically by being an excessive force
					// causing a large direction delta
					newnode.flags.bForced = FALSE;
					newnode.flags.ForeDir = NOWHERE;
					// this of course must start(?) exactly how the other ended(?)...
					newnode.flags.BackDir = Opposite( node->flags.ForeDir );
					newnode.x = tx;
					newnode.y = ty;
					{
						int xx = tx + x;
						int yy = ty + y;
						if( xx < min_x )
						{
							w += min_x - xx;
							min_x = xx;
						}
						if( xx >= ( min_x + (int32_t)w ) )
							w = xx - min_x + 1;
						if( yy < min_y )
						{
							h += min_y - yy;
							min_y = yy;
						}
						if( yy >= ( min_y + (int32_t)h ) )
							h = yy - min_y + 1;

					}
					lprintf( WIDE("Push path %d,%d  min=%d,%d size=%d,%d"), newnode.x, newnode.y, min_x, min_y, w, h );
					PushData( &pds_path, &newnode );
					nPathLayed++;
					node = (PLAYER_PATH_NODE)PeekData( &pds_path ); // okay this is now where we are.
				}
			}
		}
	}
}
Example #17
0
static void SplitAndDistributData(RSTREE R,
                                  int depth,
                                  typDATAent *newentry,
                                  int M,
                                  int m)

{
  ValueArray edgearray, spacearray;
  RectArray rectarray;
  refparameters par;
  refDATAnode n;
  refinterval re;
  
  IndexArray I;
  Side sortside, currsortside, axsortside;
  int axis;
  int mlow, mhigh,
      index, backind,
      axisindex;
  typrect leftrect, rightrect;
  double leftspace, rightspace,
         leftedge, rightedge, edge, validedge, backvaledge, axisedge,
         ovlp,
         value, validvalue, backvalvalue;
  int i, j, ii;
  
  par= &(*R).parameters._;
  
  (*R).Ntosplit= (*R).N[depth];
  (*R).N[depth]= (*R).helpdatanode;
  (*R).helpdatanode= (*R).Ntosplit;
  for (j= 0; j <= M; j++) {
    I[j]= j;
  }
  mhigh= M-m+1;
  mlow= m-1;
  
  n= &(*(*R).Ntosplit).DATA;
  
  (*n).entries[M]= *newentry;
  for (i= 0; i <= (*par).maxdim; i++) {
    sortside= low;
    currsortside= low;
    QuickSortDataEnt(0,M,i,low,(*n).entries,I);
    CopyRect(R,(*n).entries[I[M]].rect,rightrect);
    rightrect[i].l= (*n).entries[I[mhigh]].rect[i].l;
    for (j= M-1; j >= m; j--) {
      for (ii= 0; ii <= (*par).maxdim; ii++) {
        
        re= &(*n).entries[I[j]].rect[ii];
        
        if ((*re).l < rightrect[ii].l) {
          rightrect[ii].l= (*re).l;
        }
        if ((*re).h > rightrect[ii].h) {
          rightrect[ii].h= (*re).h;
        }
      }
      if (j <= mhigh) {
        rightedge= 0.0; rightspace= 1.0;
        for (ii= 0; ii <= (*par).maxdim; ii++) {
          rightedge+= rightrect[ii].h - rightrect[ii].l;
          rightspace*= rightrect[ii].h - rightrect[ii].l;
        }
        CopyRect(R,rightrect,rectarray[j]);
        edgearray[j]= rightedge;
        spacearray[j]= rightspace;
      }
    }
    /* fill array from M-m+1 down to m
       with rightrect, rightedge, rightspace */
    CopyRect(R,(*n).entries[I[0]].rect,leftrect);
    for (j= 1; j < mhigh; j++) {
      for (ii= 0; ii <= (*par).maxdim; ii++) {
        
        re= &(*n).entries[I[j]].rect[ii];
        
        if ((*re).l < leftrect[ii].l) {
          leftrect[ii].l= (*re).l;
        }
        if ((*re).h > leftrect[ii].h) {
          leftrect[ii].h= (*re).h;
        }
      }
      if (j >= mlow) {
        leftedge= 0.0;
        for (ii= 0; ii <= (*par).maxdim; ii++) {
          leftedge+= leftrect[ii].h - leftrect[ii].l;
        }
        if (Overlaps(R,leftrect,rectarray[j+1])) {
          GetOverlap(R,leftrect,rectarray[j+1],&ovlp);
          if (j == mlow) {
            validedge= leftedge+edgearray[j+1];
            validvalue= ovlp;
            index= m;
          }
          else {
            edge= leftedge+edgearray[j+1];
            validedge= validedge+edge;
            value= ovlp;
            if (value < validvalue) {
              validvalue= value;
              index= j+1;
            }
          }
        }
        else {
          leftspace= 1.0;
          for (ii= 0; ii <= (*par).maxdim; ii++) {
            leftspace*= leftrect[ii].h - leftrect[ii].l;
          }
          if (j == mlow) {
            validedge= leftedge+edgearray[j+1];
            validvalue= -1.0/(leftspace+spacearray[j+1]);
            index= m;
          }
          else {
            edge= leftedge+edgearray[j+1];
            validedge= validedge+edge;
            value= -1.0/(leftspace+spacearray[j+1]);
            if (value < validvalue) {
              validvalue= value;
              index= j+1;
            }
          }
        }
      }
    }
    /* Compute sum of the edges
       from leftedge[m-1]+rightedge[m]
       up to leftedge[M-m]+rightedge[M-m+1], -> axis;
       minimal area resp. overlap, -> index. */
    currsortside= high;
    QuickSortDataEnt(0,M,i,high,(*n).entries,I);
    CopyRect(R,(*n).entries[I[0]].rect,leftrect);
    leftrect[i].h= (*n).entries[I[mlow]].rect[i].h;
    for (j= 1; j < mhigh; j++) {
      for (ii= 0; ii <= (*par).maxdim; ii++) {
        
        re= &(*n).entries[I[j]].rect[ii];
        
        if ((*re).l < leftrect[ii].l) {
          leftrect[ii].l= (*re).l;
        }
        if ((*re).h > leftrect[ii].h) {
            leftrect[ii].h= (*re).h;
        }
      }
      if (j >= mlow) {
        leftedge= 0.0; leftspace= 1.0;
        for (ii= 0; ii <= (*par).maxdim; ii++) {
          leftedge+= leftrect[ii].h - leftrect[ii].l;
          leftspace*= leftrect[ii].h - leftrect[ii].l;
        }
        CopyRect(R,leftrect,rectarray[j]);
        edgearray[j]= leftedge;
        spacearray[j]= leftspace;
      }
    }
    /* fill array from m-1 up to M-m
       with leftrect, leftedge, leftspace */
    CopyRect(R,(*n).entries[I[M]].rect,rightrect);
    for (j= M-1; j >= m; j--) {
      for (ii= 0; ii <= (*par).maxdim; ii++) {
        
        re = &(*n).entries[I[j]].rect[ii];
        
        if ((*re).l < rightrect[ii].l) {
          rightrect[ii].l= (*re).l;
        }
        if ((*re).h > rightrect[ii].h) {
          rightrect[ii].h= (*re).h;
        }
      }
      if (j <= mhigh) {
        rightedge= 0.0;
        for (ii= 0; ii <= (*par).maxdim; ii++) {
          rightedge+= rightrect[ii].h- rightrect[ii].l;
        }
        if (Overlaps(R,rightrect,rectarray[j-1])) {
          GetOverlap(R,rightrect,rectarray[j-1],&ovlp);
          if (j == mhigh) {
            backvaledge= rightedge+edgearray[j-1];
            backvalvalue= ovlp;
            backind= j;
          }
          else {
            edge= rightedge+edgearray[j-1];
            backvaledge= backvaledge+edge;
            value= ovlp;
            if (value < backvalvalue) {
              backvalvalue= value;
              backind= j;
            }
          }
        }
        else {
          rightspace= 1.0;
          for (ii= 0; ii <= (*par).maxdim; ii++) {
            rightspace*= rightrect[ii].h - rightrect[ii].l;
          }
          if (j == mhigh) {
            backvaledge= rightedge+edgearray[j-1];
            backvalvalue= -1.0/(rightspace+spacearray[j-1]);
            backind= j;
          }
          else {
            edge= rightedge+edgearray[j-1];
            backvaledge= backvaledge+edge;
            value= -1.0/(rightspace+spacearray[j-1]);
            if (value < backvalvalue) {
              backvalvalue= value;
              backind= j;
            }
          }
        }
      }
    }
    /* Compute sum of the edges
       from rightedge[M-m+1]+leftedge[M-m]
       down to rightedge[m] +leftedge[m-1], -> axis;
       minimal area resp. overlap, -> index. */
    if (backvalvalue <= validvalue) {
      sortside= high;
      index= backind;
    }
    validedge= validedge+backvaledge;
    if (i == 0) {
      axsortside= sortside;
      axis= i;
      axisedge= validedge;
      axisindex= index;
    }
    else if (validedge < axisedge) {
      axsortside= sortside;
      axis= i;
      axisedge= validedge;
      axisindex= index;
    }
    
  }
  if (axis != (*par).maxdim || axsortside != currsortside) {
    QuickSortDataEnt(0,M,axis,axsortside,(*n).entries,I);
  }
  
  n= &(*(*R).N[depth]).DATA;
  
  (*n).nofentries= axisindex;
  for (j= 0; j < (*n).nofentries; j++) {
    (*n).entries[j]= (*(*R).Ntosplit).DATA.entries[I[j]];
  }
  /* printf("%3d",axisindex); */
  /* N[depth] gets entries 0 up to axisindex-1 */
  
  n= &(*(*R).Nsibling).DATA;
  
  (*n).nofentries= M-axisindex+1;
  for (j= 0; j < (*n).nofentries; j++) {
    (*n).entries[j]= (*(*R).Ntosplit).DATA.entries[I[axisindex+j]];
  }
  /* printf("%3d",M-axisindex+1); */
  /* printf("%3d\n",M+1); */
}