void Btree<T>::cutNode(T& x, unsigned xRST, unsigned ptr, unsigned pos, T& y, unsigned &yRST) // // Purpose: divides the node accessed by index ptr that contains // item x and index xRST at index pos. The new nodes are accessed // by pointers ptr and yRST. The median element is y. // // Parameters: // // input: x - the inserted data // xRST - the inserted index associated with item x // ptr - the index to the manipulated node // pos - the index of the dividing line // // output: // y - the new median // yRST - the index to the other node. // { unsigned median, i; Bstruct<T> *buf1, *buf2; buf1 = new Bstruct<T>; buf2 = new Bstruct<T>; readNode(buf1, ptr); // calculate the median element which also determines if // the new inserted item x is placed in the new left or the // new right nodes median = (pos <= BTREE_MIN) ? BTREE_MIN : BTREE_MIN + 1; // create a new tree node and put it on the right yRST = getNodeIndex(); for (i = 0; i <= BTREE_MAX; i++) buf2->nodeLink[i] = BTREE_NIL; numNodes++; // loop to move half of the keys for (i = median + 1; i <= BTREE_MAX; i++) { buf2->data[i - median] = buf1->data[i]; buf2->nodeLink[i - median] = buf1->nodeLink[i]; } buf2->count = BTREE_MAX - median; buf1->count = median; // push in the new data if (pos <= BTREE_MIN) pushIn(x, xRST, buf1, pos); else pushIn(x, xRST, buf2, pos - median); y = buf1->data[buf1->count]; buf2->nodeLink[0] = buf1->nodeLink[buf1->count--]; writeNode(buf1, ptr); writeNode(buf2, yRST); delete buf1; delete buf2; }
void slop::GLSelectRectangle::findOptimalGlassPosition() { // Try to move the glass next to the mouse. m_glassx = xengine->m_mousex+m_glassPixels/2+5-m_glassBorder; m_glassy = xengine->m_mousey+m_glassPixels/2+5-m_glassBorder; XRectangle view, selection, combined; view.x = xengine->m_mousex-(m_glassPixels+1+m_glassBorder)/2; view.y = xengine->m_mousey-(m_glassPixels+1+m_glassBorder)/2; view.width = m_glassPixels+1; view.height = m_glassPixels+1; selection.x = m_x-m_border; selection.y = m_y-m_border; selection.width = m_width+m_border*2; selection.height = m_height+m_border*2; combined.x = std::min( selection.x, view.x ); combined.y = std::min( selection.y, view.y ); combined.width = selection.width + std::max( selection.x-view.x, (view.x+view.width)-(selection.x+selection.width) ); combined.height = selection.height + std::max( selection.y-view.y, (view.y+view.height)-(selection.y+selection.height) ); for ( unsigned int i=0;i<m_monitors.size();i++ ) { XRRCrtcInfo* monitor = m_monitors[ i ]; // Push the glass inside the monitor the mouse is on. if ( (int)xengine->m_mousex >= (int)monitor->x && (int)xengine->m_mousex <= (int)(monitor->x + monitor->width) && (int)xengine->m_mousey >= (int)monitor->y && (int)xengine->m_mousey <= (int)(monitor->y + monitor->height) ) { pushIn( &m_glassx, &m_glassy, m_glassPixels*m_glassSize+m_glassBorder*2, m_glassPixels*m_glassSize+m_glassBorder*2, monitor->x, monitor->y, monitor->width, monitor->height ); break; } } // Push the glass outside of the selection, but only if we are left clicking, and always keep it out of the "shot" if ( xengine->getCursor() != slop::Left ) { pushOut( &m_glassx, &m_glassy, m_glassPixels*m_glassSize+m_glassBorder*2, m_glassPixels*m_glassSize+m_glassBorder*2, combined.x, combined.y, combined.width, combined.height ); } else { pushOut( &m_glassx, &m_glassy, m_glassPixels*m_glassSize+m_glassBorder*2, m_glassPixels*m_glassSize+m_glassBorder*2, view.x, view.y, view.width, view.height ); } m_glassx += m_glassBorder; m_glassy += m_glassBorder; }
void SignalHandlerImpl::handleSignal() { int recievedSignal; int error = sigwait(&set,&recievedSignal); if (error != 0) { char buffer[40]; strerror_r(error,buffer,sizeof(buffer)); printf("it was invalid set %d %s\n",error,buffer); exit(1); } switch(recievedSignal) { case SIGINT: printf("I have been cntr-c ed\n"); if (!stoppedCapturer) { capturer->pushIn(&ScreenCapturer::stopCapture); stoppedCapturer = true; } else { exit(1); } break; default: printf("Unknown signal\n"); exit(1); }; pushIn(&SignalHandler::handleSignal); }
Boolean Btree<T>::pushDown(T& x, unsigned ptr, T& item, unsigned &itemRST) // // Purpose: recursive function that inserts item x in the B-tree. // The function returns TRUE if a the height of the B-tree needs // to be increased. Otherwise, the function yields FALSE. // // Parameters: // // input: x - the inserted data // ptr - the index to the manipulated node // // output: // item - the median element // itemRST - the index to the right subtree of the node // which contains item // { unsigned i; Bstruct<T> *buf; if (ptr == BTREE_NIL) { // cannot insert into an empty tree item = x; itemRST = BTREE_NIL; return TRUE; } else { buf = new Bstruct<T>; readNode(buf, ptr); // attempt to isnert a duplicate key in the current node? if (searchNode(x, buf, i)) { strcpy(errMsg, "Cannot insert duplicates"); return FALSE; } // reinsert the median element if (pushDown(x, buf->nodeLink[i], item, itemRST)) { if (buf->count < BTREE_MAX) { pushIn(item, itemRST, buf, i); writeNode(buf, ptr); delete buf; return FALSE; } else { cutNode(item, itemRST, ptr, i, item, itemRST); delete buf; return TRUE; } } else { delete buf; return FALSE; } } }
void Foam::faceOnlySet::calcSamples ( DynamicList<point>& samplingPts, DynamicList<label>& samplingCells, DynamicList<label>& samplingFaces, DynamicList<label>& samplingSegments, DynamicList<scalar>& samplingCurveDist ) const { // distance vector between sampling points if (mag(end_ - start_) < SMALL) { FatalErrorIn("faceOnlySet::calcSamples()") << "Incorrect sample specification :" << " start equals end point." << endl << " start:" << start_ << " end:" << end_ << exit(FatalError); } const vector offset = (end_ - start_); const vector normOffset = offset/mag(offset); const vector smallVec = tol*offset; const scalar smallDist = mag(smallVec); // Force calculation of minimum-tet decomposition. (void) mesh().tetBasePtIs(); // Get all boundary intersections List<pointIndexHit> bHits = searchEngine().intersections ( start_ - smallVec, end_ + smallVec ); point bPoint(GREAT, GREAT, GREAT); label bFaceI = -1; if (bHits.size()) { bPoint = bHits[0].hitPoint(); bFaceI = bHits[0].index(); } // Get first tracking point. Use bPoint, bFaceI if provided. point trackPt; label trackCellI = -1; label trackFaceI = -1; //Info<< "before getTrackingPoint : bPoint:" << bPoint // << " bFaceI:" << bFaceI << endl; getTrackingPoint ( offset, start_, bPoint, bFaceI, trackPt, trackCellI, trackFaceI ); //Info<< "after getTrackingPoint : " // << " trackPt:" << trackPt // << " trackCellI:" << trackCellI // << " trackFaceI:" << trackFaceI // << endl; if (trackCellI == -1) { // Line start_ - end_ does not intersect domain at all. // (or is along edge) // Set points and cell/face labels to empty lists //Info<< "calcSamples : Both start_ and end_ outside domain" // << endl; return; } if (trackFaceI == -1) { // No boundary face. Check for nearish internal face trackFaceI = findNearFace(trackCellI, trackPt, smallDist); } //Info<< "calcSamples : got first point to track from :" // << " trackPt:" << trackPt // << " trackCell:" << trackCellI // << " trackFace:" << trackFaceI // << endl; // // Track until hit end of all boundary intersections // // current segment number label segmentI = 0; // starting index of current segment in samplePts label startSegmentI = 0; // index in bHits; current boundary intersection label bHitI = 1; while(true) { if (trackFaceI != -1) { //Info<< "trackPt:" << trackPt << " on face so use." << endl; samplingPts.append(trackPt); samplingCells.append(trackCellI); samplingFaces.append(trackFaceI); samplingCurveDist.append(mag(trackPt - start_)); } // Initialize tracking starting from trackPt passiveParticle singleParticle ( mesh(), trackPt, trackCellI ); bool reachedBoundary = trackToBoundary ( singleParticle, samplingPts, samplingCells, samplingFaces, samplingCurveDist ); // fill sampleSegments for (label i = samplingPts.size() - 1; i >= startSegmentI; --i) { samplingSegments.append(segmentI); } if (!reachedBoundary) { //Info<< "calcSamples : Reached end of samples: " // << " samplePt now:" << singleParticle.position() // << endl; break; } // Go past boundary intersection where tracking stopped // Use coordinate comparison instead of face comparison for // accuracy reasons bool foundValidB = false; while (bHitI < bHits.size()) { scalar dist = (bHits[bHitI].hitPoint() - singleParticle.position()) & normOffset; //Info<< "Finding next boundary : " // << "bPoint:" << bHits[bHitI].hitPoint() // << " tracking:" << singleParticle.position() // << " dist:" << dist // << endl; if (dist > smallDist) { // hitpoint is past tracking position foundValidB = true; break; } else { bHitI++; } } if (!foundValidB) { // No valid boundary intersection found beyond tracking position break; } // Update starting point for tracking trackFaceI = bHits[bHitI].index(); trackPt = pushIn(bHits[bHitI].hitPoint(), trackFaceI); trackCellI = getBoundaryCell(trackFaceI); segmentI++; startSegmentI = samplingPts.size(); } }
void Foam::uniformSet::calcSamples ( DynamicList<point>& samplingPts, dynamicLabelList& samplingCells, dynamicLabelList& samplingFaces, dynamicLabelList& samplingSegments, DynamicList<scalar>& samplingCurveDist ) const { // distance vector between sampling points if ((nPoints_ < 2) || (mag(end_ - start_) < SMALL)) { FatalErrorIn("uniformSet::calcSamples()") << "Incorrect sample specification. Either too few points or" << " start equals end point." << endl << "nPoints:" << nPoints_ << " start:" << start_ << " end:" << end_ << exit(FatalError); } const vector offset = (end_ - start_)/(nPoints_ - 1); const vector normOffset = offset/mag(offset); const vector smallVec = tol*offset; const scalar smallDist = mag(smallVec); // Get all boundary intersections List<pointIndexHit> bHits = searchEngine().intersections ( start_ - smallVec, end_ + smallVec ); point bPoint(GREAT, GREAT, GREAT); label bFaceI = -1; if (bHits.size()) { bPoint = bHits[0].hitPoint(); bFaceI = bHits[0].index(); } // Get first tracking point. Use bPoint, bFaceI if provided. point trackPt; label trackCellI = -1; label trackFaceI = -1; bool isSample = getTrackingPoint ( offset, start_, bPoint, bFaceI, trackPt, trackCellI, trackFaceI ); if (trackCellI == -1) { // Line start_ - end_ does not intersect domain at all. // (or is along edge) // Set points and cell/face labels to empty lists return; } if (isSample) { samplingPts.append(start_); samplingCells.append(trackCellI); samplingFaces.append(trackFaceI); samplingCurveDist.append(0.0); } // // Track until hit end of all boundary intersections // // current segment number label segmentI = 0; // starting index of current segment in samplePts label startSegmentI = 0; label sampleI = 0; point samplePt = start_; // index in bHits; current boundary intersection label bHitI = 1; while(true) { // Initialize tracking starting from trackPt Cloud<passiveParticle> particles(mesh(), IDLList<passiveParticle>()); passiveParticle singleParticle ( particles, trackPt, trackCellI ); bool reachedBoundary = trackToBoundary ( singleParticle, samplePt, sampleI, samplingPts, samplingCells, samplingFaces, samplingCurveDist ); // fill sampleSegments for(label i = samplingPts.size() - 1; i >= startSegmentI; --i) { samplingSegments.append(segmentI); } if (!reachedBoundary) { if (debug) { Info<< "calcSamples : Reached end of samples: " << " samplePt now:" << samplePt << " sampleI now:" << sampleI << endl; } break; } bool foundValidB = false; while (bHitI < bHits.size()) { scalar dist = (bHits[bHitI].hitPoint() - singleParticle.position()) & normOffset; if (debug) { Info<< "Finding next boundary : " << "bPoint:" << bHits[bHitI].hitPoint() << " tracking:" << singleParticle.position() << " dist:" << dist << endl; } if (dist > smallDist) { // hitpoint is past tracking position foundValidB = true; break; } else { bHitI++; } } if (!foundValidB) { // No valid boundary intersection found beyond tracking position break; } // Update starting point for tracking trackFaceI = bFaceI; trackPt = pushIn(bPoint, trackFaceI); trackCellI = getBoundaryCell(trackFaceI); segmentI++; startSegmentI = samplingPts.size(); } }