void QwtHistogram::draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const { if ( !painter || dataSize() <= 0 ) return; if (to < 0) to = dataSize() - 1; painter->save(); painter->setPen(QwtPainter::scaledPen(pen())); painter->setBrush(brush()); const double ref = yMap.transform(baseline()) + 1; const double dx = abs(xMap.transform(x(from + 1)) - xMap.transform(x(from))); const double bar_width = dx*(1 - gap()*0.01); const double half_width = 0.5*(dx - bar_width); const double xOffset = 0.01*offset()*bar_width + half_width; if (gap()){ for (int i = from; i <= to; i++){ const double py = yMap.transform(y(i)); painter->drawRect(QRectF(xMap.transform(x(i)) + xOffset, py, bar_width, (ref - py))); } } else { for (int i = from; i < to; i++){ painter->drawRect(QRectF(QPointF(xMap.transform(x(i)) + xOffset, yMap.transform(y(i))), QPointF(xMap.transform(x(i + 1)) + xOffset, ref))); } const double py = yMap.transform(y(to)); painter->drawRect(QRectF(xMap.transform(x(to)) + xOffset, py, bar_width, (ref - py))); } painter->restore(); }
/*! * \ingroup WlzConvexHull * \return angle of the minimum width rectangle * \brief extract angle (as scaled sin, cos) of minimum width rectangle * from convex hull (it is relatively obvious that minimum width * rectangle long side must be parallel to a chord of convex hull, * and all sides must have at least one vertex of convex hull * lying within them). * * \param cvh input convex hull * \param dstErr destination error */ double WlzMwrAngle(WlzObject *cvh, WlzErrorNum *dstErr) { WlzPolygonDomain *pdom; WlzChord *chr, *ch; WlzConvHullValues *cdom; int i; double c=1.0, s=0.0, h, w, minwidth; WlzErrorNum errNum = WLZ_ERR_NONE; if (cvh == NULL) { errNum = WLZ_ERR_OBJECT_NULL; } else if (cvh->type == WLZ_EMPTY_OBJ) { return 0.0; } else if (cvh->type != WLZ_CONV_HULL) { errNum = WLZ_ERR_OBJECT_TYPE; } else { pdom = cvh->domain.poly; cdom = cvh->values.c; ch = cdom->ch; minwidth = gap(ch,pdom); chr = ch++; for (i=1; i<cdom->nchords; i++) { if ((w=gap(ch,pdom)) < minwidth) { minwidth = w; chr = ch; } ch++; } c = chr->acon; s = chr->bcon; h = sqrt (s*s + c*c); s /= h; c /= h; } if(dstErr) { *dstErr = errNum; } return(atan2(c,s)); }
std::string OGC_Layer::ToString( const int& offset )const { // Stringstream std::stringstream sin; std::string gap( offset, ' '); // Print info sin << gap << "OGC_Layer:" << std::endl; sin << gap << " Name: " << m_name << std::endl; sin << gap << " Title: " << m_title << std::endl; // Internal layers sin << gap << " Layers:\n"; for( auto it=m_layers.begin(); it != m_layers.end(); it++ ) { sin << (*it)->ToString(offset+4) << std::endl; } // CRS List sin << gap << " CRS List:\n"; for( auto it=m_crs_list.begin(); it != m_crs_list.end(); it++ ) { sin << gap << gap << gap << (*it) << std::endl; } // BBox List sin << gap << " BBox List:\n"; for( auto it=m_bbox_list.begin(); it != m_bbox_list.end(); it++ ) { sin << (*it).ToString(offset+4) << std::endl; } // return string result return sin.str(); }
void ofxMarchingCubes::setupGrid(){ ofPoint gap(gridSize.x / (gridResX-1), gridSize.y / (gridResY-1), gridSize.z / (gridResZ-1)); ofPoint gridShift = gridSize * -0.5f; gridPoints.resize(gridResX); for(int i=0; i<gridResX; ++i){ gridPoints[i].resize(gridResY); for(int j=0; j<gridResY; ++j){ gridPoints[i][j].resize(gridResZ); for(int k=0; k<gridResZ; ++k){ gridPoints[i][j][k].set(i*gap.x, j*gap.y, k*gap.z); gridPoints[i][j][k] += gridShift; gridPoints[i][j][k] += iniGridPos; } } } isoValues.resize(gridResX); for(int i=0; i<gridResX; i++){ isoValues[i].resize(gridResY); for(int j=0; j<gridResY; j++){ isoValues[i][j].resize(gridResZ); for(int k=0; k<gridResZ; k++){ isoValues[i][j][k] = 0; } } } numTriangles = 0; }
void QwtHistogram::draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const { if ( !painter || dataSize() <= 0 ) return; if (to < 0) to = dataSize() - 1; painter->save(); painter->setPen(QwtPlotCurve::pen()); painter->setBrush(QwtPlotCurve::brush()); const int ref= yMap.transform(baseline()); const int dx=abs(xMap.transform(x(from+1)) - xMap.transform(x(from))); const int bar_width=int(dx*(1-gap()*0.01)); const int half_width = int(0.5*(dx-bar_width)); const int xOffset = int(0.01*offset()*bar_width); for (int i=from; i<=to; i++){ const int px1 = xMap.transform(x(i)); const int py1 = yMap.transform(y(i)); painter->drawRect(px1+half_width+xOffset,py1,bar_width+1,(ref-py1+1)); } painter->restore(); }
Stringifier::Stringifier(ExecState* exec, const Local<Unknown>& replacer, const Local<Unknown>& space) : m_exec(exec) , m_replacer(replacer) , m_usingArrayReplacer(false) , m_arrayReplacerPropertyNames(exec) , m_replacerCallType(CallTypeNone) , m_gap(gap(exec, space.get())) { if (!m_replacer.isObject()) return; if (m_replacer.asObject()->inherits(&JSArray::s_info)) { m_usingArrayReplacer = true; Handle<JSObject> array = m_replacer.asObject(); unsigned length = array->get(exec, exec->globalData().propertyNames->length).toUInt32(exec); for (unsigned i = 0; i < length; ++i) { JSValue name = array->get(exec, i); if (exec->hadException()) break; if (name.isObject()) { if (!asObject(name)->inherits(&NumberObject::s_info) && !asObject(name)->inherits(&StringObject::s_info)) continue; } m_arrayReplacerPropertyNames.add(Identifier(exec, name.toString(exec)->value(exec))); } return; } m_replacerCallType = m_replacer.asObject()->methodTable()->getCallData(m_replacer.asObject().get(), m_replacerCallData); }
std::string A_CLI_Manager_Configuration::To_Log_String(int offset) const { std::string gap(offset, ' '); std::stringstream sin; sin << gap << " - " << m_class_name << std::endl; sin << gap << " - Connection-Manager Configs (" << m_connection_manager_configurations.size() << ")" << std::endl; for( auto config : m_connection_manager_configurations ) { sin << config->To_Log_String(offset + 4); } sin << gap << " - Render-Driver Configs (" << m_render_driver_configs.size() << ")\n"; for( auto config : m_render_driver_configs ) { sin << config.second->To_Log_String(offset+4); } if( m_command_parser != nullptr ){ sin << m_command_parser->To_Log_String(offset+4); } else { sin << " - Command-Parser Is Null" << std::endl; } sin << m_event_manager_config.To_Log_String(offset+4); sin << m_command_queue_config.To_Log_String(offset+4); return sin.str(); }
void DecomposeTable<DCP_CABDOOR_BOARD_TYPE>::PostDecompose(soci::session& sql, soci::session& sqlInsert) { DecomposeTable<DCP_CABDOOR_BOARD_SEAL_TYPE> seal(StatusInfo_, InfoSPtr_, JD_BoardSealInfo, VerCode_); seal.Decompose(sql,sqlInsert); DecomposeTable<DCP_CABDOOR_BOARD_GAP_TYPE> gap(StatusInfo_, InfoSPtr_, JD_BoardGapInfo, VerCode_); gap.Decompose(sql,sqlInsert); }
QVariant Spacer::getProperty(P_ID propertyId) const { switch(propertyId) { case P_ID::SPACE: return gap(); default: return Element::getProperty(propertyId); } }
void CRKWindow::WinKeyL(const TKeyEvent &aKey,const TTime &aTime) { if (aKey.iCode==EKeyEscape) { CActiveScheduler::Stop(); iTest->iAbort=ETrue; } #if defined(LOGGING) TLogMessageText logMessageText; _LIT(KKey,"CRKWindow::WinKeyL Code=%d (%c) State=%d RepeatCount=%d"); logMessageText.Format(KKey,aKey.iScanCode,aKey.iScanCode,iState,iRepCount); iTest->LOG_MESSAGE(logMessageText); #endif if (aKey.iCode==32) { switch(iState) { case EStateWaitingForKeyCode: SetState(EStateWaitingForFirstRepeat); iPrevTime=aTime; break; case EStateWaitingForFirstRepeat: iRepCount=1; iInitialGap = I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64()); SetState(EStateWaitingForNthRepeat); break; case EStateWaitingForNthRepeat: if (iRepCount==5) SetState(EStateWaitingForKeyUp); else { TTimeIntervalMicroSeconds32 gap(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64())); #if defined(LOGGING) TLogMessageText logMessageText; _LIT(KRepeatGap,"Repeat after %d"); logMessageText.AppendFormat(KRepeatGap,gap.Int()); iTest->LOG_MESSAGE(logMessageText); TheClient->Flush(); #endif if (gap<iMinGap) iMinGap=gap; if (gap>iMaxGap) iMaxGap=gap; iTotalGap=iTotalGap.Int()+gap.Int(); // Horrible way to do a += iRepCount++; SetState(EStateWaitingForNthRepeat); } case EStateWaitingForKeyUp: // Do nothing here break; default: //iTest->Test(EFalse); iTest->TestBase()->SimulateKey(TRawEvent::EKeyUp,EStdKeySpace); CActiveScheduler::Stop(); } iPrevTime=aTime; } }
// do multiple var flips bool Simplex::findPivotCol2() { pivot_col = -1; long double leeway = pr_violation; vec<int> pivot_cands; for (int i = 0; i < R_nz.size(); i++) { int k = R_nz[i]; if ((shift[k] == 0 && row[k] < 0) || (shift[k] == 1 && row[k] > 0)) { assert(ctor[k] == -1); pivot_cands.push(k); ratio[k] = -obj[k] / row[k]; } } if (pivot_cands.size() == 0) return false; // sort based on ratio asc, then pivot size asc sort((int*) pivot_cands, (int*) pivot_cands + pivot_cands.size(), sort_col_ratio); long double best_psize = 0; for (int i = 0; i < pivot_cands.size(); i++) { int k = pivot_cands[i]; long double r = (shift[k] ? row[k] : -row[k]); if (r > best_psize || (!AVOID_SMALL_PIVOT && r >= 0.001)) { best_psize = r; pivot_col = k; } leeway -= r * gap(k); if (leeway < 0) break; } if (SIMPLEX_DEBUG) fprintf(stderr, "Pivot col = %d\n", pivot_col); assert(pivot_col != -1); if (ctor[pivot_col] != -1) { fprintf(stderr, "%d %d %d %d %d %.18Lf %.18Lf\n", shift[pivot_col], pivot_row, rtoc[pivot_row], pivot_col, ctor[pivot_col], row[pivot_col], obj[pivot_col]); } assert(ctor[pivot_col] == -1); if (SIMPLEX_DEBUG && best_psize < pivot_limit) fprintf(stderr, "Very small pivot %d, %.18Lf\n", pivot_col, best_psize); // do bound swap for all vars with smaller ratio than pivot_col for (int i = 0; ratio[pivot_cands[i]] < ratio[pivot_col]; i++) { // fprintf(stderr, "Bound swapping %d\n", pivot_cands[i]); boundSwap(pivot_cands[i]); } return true; }
Interactor* Builder::Body () { return new HBox( new HGlue(gap(), gap(), hfil), new VBox( new VGlue(gap(), gap(), vfil), Title(), new VGlue(spc(2), spc(2), 0), Controls(), new VGlue(gap(), gap(), vfil) ), new HGlue(gap(), gap(), hfil) ); }
/** Score due to flip. Again, left and right refer to order on the <emph>target</emph> side. */ void LexicalReorderingFeatureFunction::doFlipUpdate( const TranslationOption* leftOption, const TranslationOption* rightOption, const TargetGap& leftGap, const TargetGap& rightGap, FVector& scores) { if (leftGap.segment.GetEndPos() + 1 == rightGap.segment.GetStartPos()) { TargetGap gap(leftGap.leftHypo,rightGap.rightHypo, WordsRange(leftGap.segment.GetStartPos(),rightGap.segment.GetEndPos())); doContiguousPairedUpdate(leftOption,rightOption,gap,scores); } else { doDiscontiguousPairedUpdate(leftOption,rightOption,leftGap,rightGap,scores); } }
Stringifier::Stringifier(ExecState* exec, JSValue replacer, JSValue space) : m_nextStringifierToMark(exec->globalData().firstStringifierToMark) , m_exec(exec) , m_replacer(replacer) , m_usingArrayReplacer(false) , m_arrayReplacerPropertyNames(exec) , m_replacerCallType(CallTypeNone) , m_gap(gap(exec, space)) { exec->globalData().firstStringifierToMark = this; if (!m_replacer.isObject()) return; if (asObject(m_replacer)->inherits(&JSArray::info)) { m_usingArrayReplacer = true; JSObject* array = asObject(m_replacer); unsigned length = array->get(exec, exec->globalData().propertyNames->length).toUInt32(exec); for (unsigned i = 0; i < length; ++i) { JSValue name = array->get(exec, i); if (exec->hadException()) break; UString propertyName; if (name.getString(exec, propertyName)) { m_arrayReplacerPropertyNames.add(Identifier(exec, propertyName)); continue; } double value = 0; if (name.getNumber(value)) { m_arrayReplacerPropertyNames.add(Identifier::from(exec, value)); continue; } if (name.isObject()) { if (!asObject(name)->inherits(&NumberObject::info) && !asObject(name)->inherits(&StringObject::info)) continue; propertyName = name.toString(exec); if (exec->hadException()) break; m_arrayReplacerPropertyNames.add(Identifier(exec, propertyName)); } } return; } m_replacerCallType = asObject(m_replacer)->getCallData(m_replacerCallData); }
static void CatAdjustSize(OBJECT x, FULL_LENGTH *b, FULL_LENGTH *f, BOOLEAN ratm, OBJECT y, int dim) { OBJECT link; OBJECT pg, prec_def, sg, sd; FULL_LENGTH beffect, feffect, seffect; int side; int bb = 0, ff = 0; /* initial values unused */ debug6(DSA, DD, "CatAdjustSize(%s x, %s, %s, %s, %s y, %s)", Image(type(x)), EchoLength(*b), EchoLength(*f), bool(ratm), Image(type(y)), dimen(dim)); debug2(DSA,DD, "x(%s,%s) =", EchoLength(back(x,dim)), EchoLength(fwd(x,dim))); ifdebug(DSA, DD, DebugObject(x)); debug2(DSA,DD, "y(%s,%s) =", EchoLength(back(y,dim)), EchoLength(fwd(y,dim))); ifdebug(DSA, DD, DebugObject(y)); /* DO_ADJUST ACAT is a special case because adjustment affects its size */ if( dim==COLM && type(y)==ACAT && display_style(save_style(y)) == DO_ADJUST ) { back(x, dim) = *b; fwd(x, dim) = *f; *b = back(y, dim); *f = fwd(y, dim); debug2(DSA, DD, "CatAdjustSize ACAT %s,%s", EchoLength(*b), EchoLength(*f)); return; } link = UpDim(x, dim); SetNeighbours(link, ratm, &pg, &prec_def, &sg, &sd, &side); { ifdebug(DSA, DD, if( pg != nilobj && mode(gap(pg)) == NO_MODE ) { debug1(DSA, DD, "NO_MODE gap pg, is_indefinite(x) == %s, y =", bool(is_indefinite(type(x))) ); ifdebug(DSA, DD, DebugObject(y)); } if( sg != nilobj && mode(gap(sg)) == NO_MODE ) { debug1(DSA, DD, "NO_MODE gap sg, is_indefinite(x) == %s, y =", bool(is_indefinite(type(x))) ); ifdebug(DSA, DD, DebugObject(y)); } ); }
/** Score due to flip. Again, left and right refer to order on the <emph>target</emph> side. */ void DiscriminativeLMBigramFeatureFunction::doFlipUpdate(const TranslationOption* leftOption,const TranslationOption* rightOption, const TargetGap& leftGap, const TargetGap& rightGap, FVector& scores) { if (leftGap.segment.GetEndPos()+1 == rightGap.segment.GetStartPos()) { //contiguous Phrase gapPhrase(leftOption->GetTargetPhrase()); gapPhrase.Append(rightOption->GetTargetPhrase()); TargetGap gap(leftGap.leftHypo, rightGap.rightHypo, WordsRange(leftGap.segment.GetStartPos(), rightGap.segment.GetEndPos())); doUpdate(gapPhrase,gap,scores); } else { //discontiguous doUpdate(leftOption->GetTargetPhrase(), leftGap,scores); doUpdate(rightOption->GetTargetPhrase(), rightGap,scores); } }
std::string A_Connection_Manager_Socket::To_Log_String(int offset) const { std::string gap(offset, ' '); std::stringstream sin; sin << gap << " - " << m_class_name << std::endl; sin << gap << " - Session-Type: " << CORE::SessionTypeToString(m_configuration->Get_Session_Type()) << "\n"; sin << gap << " - Connection-Type: " << CORE::ConnectionTypeToString(m_configuration->Get_ConnectionType()) << "\n"; sin << gap << " - Is-Running: " << std::boolalpha << m_is_running << std::endl; sin << gap << " - Connection List (Size: " + std::to_string(m_connection_list.size()) + ")\n"; for( auto conn : m_connection_list ) { } return sin.str(); }
void CRKWindow::WinKeyL(const TKeyEvent &aKey,const TTime &aTime) { if (aKey.iCode==EKeyEscape) { CActiveScheduler::Stop(); iTest->iAbort=ETrue; } if (aKey.iCode==32) { switch(iState) { case EStateWaitingForKeyCode: SetState(EStateWaitingForFirstRepeat); iPrevTime=aTime; break; case EStateWaitingForFirstRepeat: iRepCount=1; iInitialGap = I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64()); SetState(EStateWaitingForNthRepeat); break; case EStateWaitingForNthRepeat: if (iRepCount==5) SetState(EStateWaitingForKeyUp); else { TTimeIntervalMicroSeconds32 gap(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64())); if (gap<iMinGap) iMinGap=gap; if (gap>iMaxGap) iMaxGap=gap; iTotalGap=iTotalGap.Int()+gap.Int(); // Horrible way to do a += iRepCount++; SetState(EStateWaitingForNthRepeat); } case EStateWaitingForKeyUp: // Do nothing here break; default: iTest->TestL(EFalse); } iPrevTime=aTime; } }
void MaxFlowPushPreFlow::discharge(int v) { int old_h = h[v]; int cur = current_push[v]; while (e[v] > 0) { if (cur == graph.graph[v].size()) { cur = 0; relable(v); } else { if (h[v] == h[graph.graph[v][cur]->to] + 1 && graph.graph[v][cur]->cap > 0) { push(graph.graph[v][cur]); } else { ++cur; } } } current_push[v] = cur; h_count[old_h] -= 1; h_count[h[v]] += 1; if (old_h < graph.n && h_count[old_h] == 0) gap(old_h); }
int findMinDifference(vector<string>& timePoints) { sort(timePoints.begin(), timePoints.end(), [](const string& s1, const string& s2) { int h1 = stoi(s1.substr(0, 2)), h2 = stoi(s2.substr(0, 2)); if (h1 < h2) return true; if (h1 > h2) return false; int m1 = stoi(s1.substr(3, 2)), m2 = stoi(s2.substr(3, 2)); return m1 < m2; }); int result = 24 * 60, n = timePoints.size(); timePoints.push_back(timePoints[0]); if (timePoints[n][1] > '5') { timePoints[n][0] += 3; timePoints[n][1] += 4 - 10; } else { timePoints[n][0] += 2; timePoints[n][1] += 4; } for (int i = 0; i != n; ++i) result = min(result, gap(timePoints[i], timePoints[i + 1])); return result; }
std::string A_Command_Argument::To_Debug_String( int const& offset )const { // Create output stream std::stringstream sin; std::string gap( offset, ' '); // Start adding info sin << gap << m_class_name << ":\n"; sin << gap << " Name : " << m_name << std::endl; sin << gap << " Arg Type : " << CommandArgumentTypeToString(m_type) << std::endl; sin << gap << " Description : " << m_description << std::endl; sin << gap << " Default : " << m_default_value << std::endl; sin << gap << " Required : " << std::boolalpha << m_required << std::endl; sin << gap << " Autocomplete Terms: " << std::endl; for( size_t i=0; i<m_autocomplete_terms.size(); i++ ){ sin << gap << " " << i << " : " << m_autocomplete_terms[i] << std::endl; } // return output return sin.str(); }
void SetNeighbours(OBJECT link, BOOLEAN ratm, OBJECT *pg, OBJECT *pdef, OBJECT *sg, OBJECT *sdef, int *side) { OBJECT plink, slink; /* find preceding definite; if it exists, set *pg */ *pg = nilobj; for( plink = PrevDown(link); type(plink) == LINK; plink = PrevDown(plink) ) { Child(*pdef, plink); if( type(*pdef) == SPLIT ? SplitIsDefinite(*pdef) : is_definite(type(*pdef)) ) { Child(*pg, PrevDown(link)); while( is_index(type(*pg)) ) { link = PrevDown(link); Child(*pg, PrevDown(link)); } assert( type(*pg) == GAP_OBJ, "SetNeighbours: type(*pg)!" ); break; } } /* find succeeding definite; if it exists, set *sg */ *sg = nilobj; for( slink = NextDown(link); type(slink) == LINK; slink = NextDown(slink) ) { Child(*sdef, slink); if( type(*sdef) == SPLIT ? SplitIsDefinite(*sdef) : is_definite(type(*sdef)) ) { Child(*sg, PrevDown(slink)); while( is_index(type(*sg)) ) { slink = PrevDown(slink); Child(*sg, PrevDown(slink)); } assert( type(*sg) == GAP_OBJ, "SetNeighbours: type(*sg)!" ); break; } } *side = ratm ? BACK : *pg == nilobj || mark(gap(*pg)) ? ON : FWD; debug4(DSA, DD, "SetNeighbours: ratm == %s, pg %s nilobj, sg %s nilobj, side == %s", bool(ratm), *pg == nilobj ? "==" : "!=", *sg == nilobj ? "==" : "!=", *side == BACK ? "BACK" : *side == ON ? "ON" : "FWD"); } /* end SetNeighbours */
void PushRelabel::relabel (uint32_t vertex) { if (vertex == network_->getSource() || excess_[vertex] == 0) return; uint32_t nOfVertices = network_->getNOfVertices(); usedHeight_[height_[vertex]]--; uint32_t minHeight = 2 * nOfVertices; // maximum height possible (@see Cormen) uint32_t oldHeight = height_[vertex]; for (uint32_t curVertex = 0; curVertex < nOfVertices; curVertex++) { if (network_->getTubes()(vertex, curVertex).isSaturated()) continue; minHeight = std::min (minHeight, height_[curVertex] + 1); } height_[vertex] = minHeight; usedHeight_[height_[vertex]]++; if (usedHeight_[oldHeight] == 0) gap (oldHeight); }
void checkSphWallLubricationForce() { const uint_t timestep (timeloop_->getCurrentTimeStep()+1); // variables for output of total force - requires MPI-reduction pe::Vec3 forceSphr1(0); // temporary variables real_t gap (0); for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt ) { for( auto curSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); curSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++curSphereIt ) { pe::SphereID sphereI = ( curSphereIt.getBodyID() ); if ( sphereI->getID() == id1_ ) { for( auto globalBodyIt = globalBodyStorage_->begin(); globalBodyIt != globalBodyStorage_->end(); ++globalBodyIt) { if( globalBodyIt->getID() == id2_ ) { pe::PlaneID planeJ = static_cast<pe::PlaneID>( globalBodyIt.getBodyID() ); gap = pe::getSurfaceDistance(sphereI, planeJ); break; } } break; } } } WALBERLA_MPI_SECTION() { mpi::reduceInplace( gap, mpi::MAX ); } WALBERLA_ROOT_SECTION() { if (gap < real_comparison::Epsilon<real_t>::value ) { gap = walberla::math::Limits<real_t>::inf(); WALBERLA_LOG_INFO_ON_ROOT( "Sphere still too far from wall to calculate gap!" ); } else { WALBERLA_LOG_INFO_ON_ROOT( "Gap between sphere and wall: " << gap ); } } // get force on sphere for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt ) { for( auto bodyIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); bodyIt != pe::BodyIterator::end<pe::Sphere>(); ++bodyIt ) { if( bodyIt->getID() == id1_ ) { forceSphr1 += bodyIt->getForce(); } } } // MPI reduction of pe forces over all processes WALBERLA_MPI_SECTION() { mpi::reduceInplace( forceSphr1[0], mpi::SUM ); mpi::reduceInplace( forceSphr1[1], mpi::SUM ); mpi::reduceInplace( forceSphr1[2], mpi::SUM ); } WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id1_ << " : " << forceSphr1); if ( print_ ) { WALBERLA_ROOT_SECTION() { std::ofstream file1; std::string filename1("Gap_LubricationForceBody1.txt"); file1.open( filename1.c_str(), std::ofstream::app ); file1.setf( std::ios::unitbuf ); file1.precision(15); file1 << gap << " " << forceSphr1[0] << std::endl; file1.close(); } } WALBERLA_ROOT_SECTION() { if ( timestep == uint_t(26399) ) { // according to the formula from Ding & Aidun 2003 // F = 6 * M_PI * rho_L * nu_L * relative velocity of both bodies=relative velocity of the sphere * r * r * 1/gap // the correct analytically calculated value is 339.292006996217 // in this geometry setup the relative error is 0.183515322065561 % real_t analytical = real_c(6.0) * walberla::math::M_PI * real_c(1.0) * nu_L_ * real_c(-vel_[0]) * radius_ * radius_ * real_c(1.0)/gap; real_t relErr = std::fabs( analytical - forceSphr1[0] ) / analytical * real_c(100.0); WALBERLA_CHECK_LESS( relErr, real_t(1) ); } } }
void checkSphSphLubricationForce() { const uint_t timestep (timeloop_->getCurrentTimeStep()+1); // variables for output of total force - requires MPI-reduction pe::Vec3 forceSphr1(0); pe::Vec3 forceSphr2(0); // temporary variables real_t gap (0); // calculate gap between the two spheres for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt ) { for( auto curSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); curSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++curSphereIt ) { pe::SphereID sphereI = ( curSphereIt.getBodyID() ); if ( sphereI->getID() == id1_ ) { for( auto blockIt2 = blocks_->begin(); blockIt2 != blocks_->end(); ++blockIt2 ) { for( auto oSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt2, bodyStorageID_); oSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++oSphereIt ) { pe::SphereID sphereJ = ( oSphereIt.getBodyID() ); if ( sphereJ->getID() == id2_ ) { gap = pe::getSurfaceDistance( sphereI, sphereJ ); break; } } } break; } } } WALBERLA_MPI_SECTION() { mpi::reduceInplace( gap, mpi::MAX ); } WALBERLA_ROOT_SECTION() { if (gap < real_comparison::Epsilon<real_t>::value ) { // shadow copies have not been synced yet as the spheres are outside the overlap region gap = walberla::math::Limits<real_t>::inf(); WALBERLA_LOG_INFO_ON_ROOT( "Spheres still too far apart to calculate gap!" ); } else { WALBERLA_LOG_INFO_ON_ROOT( "Gap between sphere 1 and 2: " << gap ); } } // get force on spheres for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt ) { for( auto bodyIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); bodyIt != pe::BodyIterator::end<pe::Sphere>(); ++bodyIt ) { if( bodyIt->getID() == id1_ ) { forceSphr1 += bodyIt->getForce(); } else if( bodyIt->getID() == id2_ ) { forceSphr2 += bodyIt->getForce(); } } } // MPI reduction of pe forces over all processes WALBERLA_MPI_SECTION() { mpi::reduceInplace( forceSphr1[0], mpi::SUM ); mpi::reduceInplace( forceSphr1[1], mpi::SUM ); mpi::reduceInplace( forceSphr1[2], mpi::SUM ); mpi::reduceInplace( forceSphr2[0], mpi::SUM ); mpi::reduceInplace( forceSphr2[1], mpi::SUM ); mpi::reduceInplace( forceSphr2[2], mpi::SUM ); } WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id1_ << " : " << forceSphr1); WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id2_ << " : " << forceSphr2); if ( print_ ) { WALBERLA_ROOT_SECTION() { std::ofstream file1; std::string filename1("Gap_LubricationForceBody1.txt"); file1.open( filename1.c_str(), std::ofstream::app ); file1.setf( std::ios::unitbuf ); file1.precision(15); file1 << gap << " " << forceSphr1[0] << std::endl; file1.close(); std::ofstream file2; std::string filename2("Gap_LubricationForceBody2.txt"); file2.open( filename2.c_str(), std::ofstream::app ); file2.setf( std::ios::unitbuf ); file2.precision(15); file2 << gap << " " << forceSphr2[0] << std::endl; file2.close(); } } WALBERLA_ROOT_SECTION() { if ( timestep == uint_t(1000) ) { // both force x-components should be the same only with inverted signs WALBERLA_CHECK_FLOAT_EQUAL ( forceSphr2[0], -forceSphr1[0] ); // according to the formula from Ding & Aidun 2003 // F = 3/2 * M_PI * rho_L * nu_L * relative velocity of both spheres * r * r * 1/gap // the correct analytically calculated value is 339.2920063998 // in this geometry setup the relative error is 0.1246489711 % real_t analytical = real_c(3.0)/real_c(2.0) * walberla::math::M_PI * real_c(1.0) * nu_L_ * real_c(2.0) * real_c(vel_[0]) * radius_ * radius_ * real_c(1.0)/gap; real_t relErr = std::fabs( analytical - forceSphr2[0] ) / analytical * real_c(100.0); WALBERLA_CHECK_LESS( relErr, real_t(1) ); } } }
int AttachGalley(OBJECT hd, OBJECT *inners, OBJECT *suspend_pt) { OBJECT hd_index; /* the index of hd in the enclosing galley */ OBJECT hd_inners; /* inner galleys of hd, if unsized */ OBJECT dest; /* the target @Galley hd empties into */ OBJECT dest_index; /* the index of dest */ OBJECT target; /* the target indefinite containing dest */ OBJECT target_index; /* the index of target */ OBJECT target_galley; /* the body of target, made into a galley */ OBJECT tg_inners; /* inner galleys of target_galley */ BOOLEAN need_precedes = FALSE;/* true if destination lies before galley */ OBJECT recs; /* list of recursive definite objects */ OBJECT link, y = nilobj; /* for scanning through the components of hd */ CONSTRAINT c; /* temporary variable holding a constraint */ OBJECT env, n1, tmp, zlink, z, sym; /* placeholders and temporaries */ BOOLEAN was_sized; /* true if sized(hd) initially */ int dim; /* the galley direction */ FULL_LENGTH perp_back, perp_fwd; OBJECT why, junk; debug2(DGA, D, "[ AttachGalley(Galley %s into %s)", SymName(actual(hd)), SymName(whereto(hd))); ifdebug(DGA, DD, DebugGalley(hd, nilobj, 4)); assert( Up(hd) != hd, "AttachGalley: no index!" ); Parent(hd_index, Up(hd)); assert( type(hd_index) == UNATTACHED, "AttachGalley: not UNATTACHED!" ); hd_inners = tg_inners = nilobj; was_sized = sized(hd); dim = gall_dir(hd); for(;;) { /*************************************************************************/ /* */ /* Search for a destination for hd. If hd is unsized, search for */ /* inner galleys preceding it first of all, then for receptive objects */ /* following it, possibly in inner galleys. If no luck, exit. */ /* If hd is sized, search only for receptive objects in the current */ /* galley below the current spot, and fail if cannot find any. */ /* */ /*************************************************************************/ sym = whereto(hd); if( sized(hd) ) { /* sized galley case: search on from current spot */ target_index = SearchGalley(Up(hd_index), sym, TRUE, FALSE, TRUE, TRUE); if( target_index == nilobj ) { /* search failed to find any new target, so kill the galley */ for( link = Down(hd); link != hd; link = NextDown(link) ) { Child(y, link); if( type(y) == SPLIT ) Child(y, DownDim(y, dim)); if( is_definite(type(y)) ) break; } if( link != hd ) Error(19, 1, "galley %s deleted from here (no target)", WARN, &fpos(y), SymName(actual(hd))); if( hd_inners != nilobj ) DisposeObject(hd_inners), hd_inners=nilobj; if( tg_inners != nilobj ) DisposeObject(tg_inners), tg_inners=nilobj; KillGalley(hd, FALSE); *inners = nilobj; debug0(DGA, D, "] AttachGalley returning ATTACH_KILLED"); return ATTACH_KILLED; } else if( actual(actual(target_index)) == InputSym ) { /* search found input object, so suspend on that */ DeleteNode(hd_index); Link(target_index, hd); *inners = nilobj; debug0(DGA, D, "] AttachGalley returning ATTACH_INPUT"); return ATTACH_INPUT; } } else /* unsized galley, either backwards or normal */ { if( foll_or_prec(hd) == GALL_PREC ) { target_index= SearchGalley(Up(hd_index), sym, FALSE, TRUE,TRUE,FALSE); need_precedes = FALSE; } else { target_index = SearchGalley(Up(hd_index), sym, FALSE,TRUE,FALSE,FALSE); need_precedes = (target_index != nilobj); if( target_index == nilobj ) target_index = SearchGalley(Up(hd_index), sym, TRUE,TRUE,TRUE,FALSE); } /* if no luck, exit without error */ if( target_index == nilobj ) { *inners = nilobj; debug0(DGA, D, "] AttachGalley returning ATTACH_NOTARGET"); return ATTACH_NOTARGET; } } assert( type(target_index) == RECEPTIVE, "AttachGalley: target_index!" ); target = actual(target_index); assert( type(target) == CLOSURE, "AttachGalley: target!" ); /* set target_galley to the expanded value of target */ debug1(DYY, D, "[ EnterErrorBlock(FALSE) (expanding target %s)", SymName(actual(target))); EnterErrorBlock(FALSE); New(target_galley, HEAD); force_gall(target_galley) = FALSE; enclose_obj(target_galley) = limiter(target_galley) = nilobj; ClearHeaders(target_galley); opt_components(target_galley) = opt_constraints(target_galley) = nilobj; gall_dir(target_galley) = external_hor(target) ? COLM : ROWM; FposCopy(fpos(target_galley), fpos(target)); actual(target_galley) = actual(target); whereto(target_galley) = ready_galls(target_galley) = nilobj; foll_or_prec(target_galley) = GALL_FOLL; must_expand(target_galley) = FALSE; sized(target_galley) = FALSE; /* get perpendicular constraint (none if horizontal galley) */ if( dim == ROWM ) { Constrained(target, &c, 1-dim, &junk); if( !constrained(c) ) Error(19, 2, "receptive symbol %s has unconstrained width", FATAL, &fpos(target), SymName(actual(target))); debug2(DSC, DD, "Constrained( %s, 1-dim ) = %s", EchoObject(target), EchoConstraint(&c)); if( !FitsConstraint(0, 0, c) ) { debug0(DGA, D, " reject: target_galley horizontal constraint is -1"); y = nilobj; goto REJECT; } } else /* actually unused */ SetConstraint(c, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH); debug1(DGA, DDD, " expanding %s", EchoObject(target)); tmp = CopyObject(target, no_fpos); Link(target_galley, tmp); env = DetachEnv(tmp); debug4(DGM, D, " external_ver(%s) = %s, external_hor(%s) = %s", SymName(actual(target)), bool(external_ver(target)), SymName(actual(target)), bool(external_hor(target))); SizeGalley(target_galley, env, external_ver(target) || external_hor(target), threaded(target), non_blocking(target_index), trigger_externs(target_index), &save_style(target), &c, whereto(hd), &dest_index, &recs, &tg_inners, enclose_obj(hd) != nilobj ? CopyObject(enclose_obj(hd), no_fpos):nilobj); debug1(DGA, DD, " SizeGalley tg_inners: %s", DebugInnersNames(tg_inners)); if( recs != nilobj ) ExpandRecursives(recs); dest = actual(dest_index); if( underline(dest) == UNDER_UNDEF ) underline(dest) = UNDER_OFF; /* verify that hd satisfies any horizontal constraint on dest */ if( dim == ROWM ) { debug1(DGA, DDD, " checking hor fit of hd in %s",SymName(actual(dest))); Constrained(dest, &c, 1-dim, &junk); debug3(DSC, DD, "Constrained( %s, %s ) = %s", EchoObject(dest), dimen(1-dim), EchoConstraint(&c)); assert( constrained(c), "AttachGalley: dest unconstrained!" ); if( !FitsConstraint(0, 0, c) ) { debug0(DGA, D, " reject: hd horizontal constraint is -1"); y = nilobj; goto REJECT; } } /* manifest and size the galley if not done yet */ if( !sized(hd) ) { debug2(DYY, D, "[ EnterErrorBlock(TRUE) (sizing galley %s into %s)", SymName(actual(hd)), SymName(whereto(hd))); EnterErrorBlock(TRUE); n1 = nilobj; Child(y, Down(hd)); env = DetachEnv(y); /*** threaded() only defined in ROWM case SizeGalley(hd, env, TRUE, threaded(dest), non_blocking(target_index), TRUE, &save_style(dest), &c, nilobj, &n1, &recs, &hd_inners); *** */ SizeGalley(hd, env, TRUE, dim == ROWM ? threaded(dest) : FALSE, non_blocking(target_index), TRUE, &save_style(dest), &c, nilobj, &n1, &recs, &hd_inners, nilobj); debug1(DGA,DD," SizeGalley hd_inners: %s", DebugInnersNames(hd_inners)); if( recs != nilobj ) ExpandRecursives(recs); if( need_precedes ) /* need an ordering constraint */ { OBJECT index1, index2; New(index1, PRECEDES); New(index2, FOLLOWS); blocked(index2) = FALSE; tmp = MakeWord(WORD, STR_EMPTY, no_fpos); Link(index1, tmp); Link(index2, tmp); Link(Up(hd_index), index1); Link(Down(hd), index2); debug0(DGA, D, " inserting PRECEDES and FOLLOWS"); } LeaveErrorBlock(TRUE); debug0(DYY, D, "] LeaveErrorBlock(TRUE) (finished sizing galley)"); } if( dim == ROWM ) { if( !FitsConstraint(back(hd, 1-dim), fwd(hd, 1-dim), c) ) { debug3(DGA, D, " reject: hd %s,%s does not fit target_galley %s", EchoLength(back(hd, 1-dim)), EchoLength(fwd(hd, 1-dim)), EchoConstraint(&c)); Error(19, 3, "too little horizontal space for galley %s at %s", WARN, &fpos(hd), SymName(actual(hd)), SymName(actual(dest))); goto REJECT; } } /* check status of first component of hd */ debug0(DGA, DDD, " now ready to attach; hd ="); ifdebug(DGA, DDD, DebugObject(hd)); for( link = Down(hd); link != hd; link = NextDown(link) ) { Child(y, link); debug1(DGA, DDD, " examining %s", EchoIndex(y)); if( type(y) == SPLIT ) Child(y, DownDim(y, dim)); switch( type(y) ) { case EXPAND_IND: case SCALE_IND: case COVER_IND: case GALL_PREC: case GALL_FOLL: case GALL_FOLL_OR_PREC: case GALL_TARG: case CROSS_PREC: case CROSS_FOLL: case CROSS_FOLL_OR_PREC: case CROSS_TARG: case PAGE_LABEL_IND: break; case PRECEDES: case UNATTACHED: if( was_sized ) { /* SizeGalley was not called, so hd_inners was not set by it */ if( hd_inners == nilobj ) New(hd_inners, ACAT); Link(hd_inners, y); } break; case RECEPTIVE: goto SUSPEND; case RECEIVING: goto SUSPEND; case FOLLOWS: Child(tmp, Down(y)); if( Up(tmp) == LastUp(tmp) ) { link = pred(link, CHILD); debug0(DGA, DD, " disposing FOLLOWS"); DisposeChild(NextDown(link)); break; } Parent(tmp, Up(tmp)); assert(type(tmp) == PRECEDES, "Attach: PRECEDES!"); switch( CheckComponentOrder(tmp, target_index) ) { case CLEAR: DeleteNode(tmp); link = pred(link, CHILD); DisposeChild(NextDown(link)); break; case PROMOTE: break; case BLOCK: debug0(DGA, DD, "CheckContraint: BLOCK"); goto SUSPEND; case CLOSE: debug0(DGA, D, " reject: CheckContraint"); goto REJECT; } break; case GAP_OBJ: underline(y) = underline(dest); if( !join(gap(y)) ) seen_nojoin(hd) = TRUE; break; case BEGIN_HEADER: case END_HEADER: case SET_HEADER: case CLEAR_HEADER: /* do nothing until actually promoted out of here */ underline(y) = underline(dest); break; case CLOSURE: case CROSS: case FORCE_CROSS: case NULL_CLOS: case PAGE_LABEL: underline(y) = underline(dest); break; case WORD: case QWORD: case ONE_COL: case ONE_ROW: case WIDE: case HIGH: case HSHIFT: case VSHIFT: case HMIRROR: case VMIRROR: case HSCALE: case VSCALE: case HCOVER: case VCOVER: case HCONTRACT: case VCONTRACT: case HLIMITED: case VLIMITED: case HEXPAND: case VEXPAND: case START_HVSPAN: case START_HSPAN: case START_VSPAN: case HSPAN: case VSPAN: case ROTATE: case BACKGROUND: case SCALE: case KERN_SHRINK: case INCGRAPHIC: case SINCGRAPHIC: case PLAIN_GRAPHIC: case GRAPHIC: case LINK_SOURCE: case LINK_DEST: case LINK_DEST_NULL: case LINK_URL: case ACAT: case HCAT: case VCAT: case ROW_THR: case COL_THR: underline(y) = underline(dest); if( dim == ROWM ) { /* make sure y is not joined to a target below (vertical only) */ for( zlink = NextDown(link); zlink != hd; zlink = NextDown(zlink) ) { Child(z, zlink); switch( type(z) ) { case RECEPTIVE: if( non_blocking(z) ) { zlink = PrevDown(zlink); DeleteNode(z); } else { y = z; goto SUSPEND; } break; case RECEIVING: if( non_blocking(z) ) { zlink = PrevDown(zlink); while( Down(z) != z ) { Child(tmp, Down(y)); if( opt_components(tmp) != nilobj ) { DisposeObject(opt_components(tmp)); opt_components(tmp) = nilobj; debug3(DOG, D, "AttachGalley(%s) de-optimizing %s %s", SymName(actual(hd)), SymName(actual(tmp)), "(join)"); } DetachGalley(tmp); KillGalley(tmp, FALSE); } DeleteNode(z); } else { y = z; goto SUSPEND; } break; case GAP_OBJ: if( !join(gap(z)) ) zlink = PrevDown(hd); break; default: break; } } /* if HCAT, try vertical hyphenation (vertical galleys only) */ if( type(y) == HCAT ) VerticalHyphenate(y); } /* check availability of parallel space for the first component */ why = nilobj; Constrained(dest, &c, dim, &why); debug3(DGF, DD, " dest parallel Constrained(%s, %s) = %s", EchoObject(dest), dimen(dim), EchoConstraint(&c)); if( !FitsConstraint(back(y, dim), fwd(y, dim), c) ) { BOOLEAN scaled; /* if forcing galley doesn't fit, try scaling first component */ scaled = FALSE; if( force_gall(hd) && size(y, dim) > 0 ) { int scale_factor; scale_factor = ScaleToConstraint(back(y,dim), fwd(y,dim), &c); if( scale_factor > 0.5 * SF ) { char num1[20], num2[20]; sprintf(num1, "%.1fc", (float) size(y, dim) / CM); sprintf(num2, "%.1fc", (float) bfc(c) / CM); if( dim == ROWM ) Error(19, 4, "%s object too high for %s space; %s inserted", WARN, &fpos(y), num1, num2, KW_SCALE); else Error(19, 5, "%s object too wide for %s space; %s inserted", WARN, &fpos(y), num1, num2, KW_SCALE); y = InterposeScale(y, scale_factor, dim); scaled = TRUE; } } /* otherwise we must reject, and warn the user */ if( !scaled ) { char num1[20], num2[20]; debug3(DGA, D, " reject: vsize %s,%s in %s; y=", EchoLength(back(y, dim)), EchoLength(fwd(y, dim)), EchoConstraint(&c)); ifdebug(DGA, D, DebugObject(y)); if( size(y, dim) > 0 ) { sprintf(num1, "%.1fc", (float) size(y, dim) / CM); sprintf(num2, "%.1fc", (float) bfc(c) / CM); if( dim == ROWM ) Error(19, 12, "%s object too high for %s space; will try elsewhere", WARN, &fpos(y), num1, num2); else Error(19, 13, "%s object too wide for %s space; will try elsewhere", WARN, &fpos(y), num1, num2); } goto REJECT; } } /* check availability of perpendicular space for first component */ if( dim == ROWM ) { perp_back = back(hd, 1-dim); perp_fwd = fwd(hd, 1-dim); } else { perp_back = back(y, 1-dim); perp_fwd = fwd(y, 1-dim); } Constrained(dest, &c, 1-dim, &junk); debug3(DGF, DD, " dest perpendicular Constrained(%s, %s) = %s", EchoObject(dest), dimen(1-dim), EchoConstraint(&c)); if( !FitsConstraint(perp_back, perp_fwd, c) ) { BOOLEAN scaled; /* if forcing galley doesn't fit, try scaling first component */ scaled = FALSE; if( force_gall(hd) && perp_back + perp_fwd > 0 ) { int scale_factor; scale_factor = ScaleToConstraint(perp_back, perp_fwd, &c); if( scale_factor > 0.5 * SF ) { char num1[20], num2[20]; sprintf(num1, "%.1fc", (float) (perp_back + perp_fwd) / CM); sprintf(num2, "%.1fc", (float) bfc(c) / CM); if( 1-dim == ROWM ) Error(19, 6, "%s object too high for %s space; %s inserted", WARN, &fpos(y), num1, num2, KW_SCALE); else Error(19, 7, "%s object too wide for %s space; %s inserted", WARN, &fpos(y), num1, num2, KW_SCALE); y = InterposeScale(y, scale_factor, 1-dim); scaled = TRUE; } } /* otherwise we must reject, and warn the user */ if( !scaled ) { debug3(DGA, D, " reject: vsize %s,%s in %s; y=", EchoLength(perp_back), EchoLength(perp_fwd), EchoConstraint(&c)); ifdebug(DGA, D, DebugObject(y)); goto REJECT; } } /* dest seems OK, so perform its size adjustments */ debug0(DSA, D, "calling AdjustSize from AttachGalley (a)"); AdjustSize(dest, back(y, dim), fwd(y, dim), dim); debug0(DSA, D, "calling AdjustSize from AttachGalley (b)"); AdjustSize(dest, perp_back, perp_fwd, 1-dim); /* now check parallel space for target_galley in target */ Constrained(target, &c, dim, &why); debug3(DGF, DD, " target parallel Constrained(%s, %s) = %s", EchoObject(target), dimen(dim), EchoConstraint(&c)); Child(z, LastDown(target_galley)); /* works in all cases? */ assert( !is_index(type(z)), "AttachGalley: is_index(z)!" ); assert( back(z, dim)>=0 && fwd(z, dim)>=0, "AttachGalley: z size!" ); if( !FitsConstraint(back(z, dim), fwd(z, dim), c) ) { BOOLEAN scaled; debug2(DGA, D, " why = %d %s", (int) why, EchoObject(why)); debug2(DGA, D, " limiter = %d %s", (int) limiter(hd), EchoObject(limiter(hd))); /* if forcing galley doesn't fit, try scaling z */ scaled = FALSE; if( force_gall(hd) && size(z, dim) > 0 && limiter(hd) != why ) { int scale_factor; scale_factor = ScaleToConstraint(back(z,dim), fwd(z,dim), &c); if( scale_factor > 0.5 * SF ) { char num1[20], num2[20]; sprintf(num1, "%.1fc", (float) size(z, dim) / CM); sprintf(num2, "%.1fc", (float) bfc(c) / CM); if( dim == ROWM ) Error(19, 8, "%s object too high for %s space; %s inserted", WARN, &fpos(y), num1, num2, KW_SCALE); else Error(19, 9, "%s object too wide for %s space; %s inserted", WARN, &fpos(y), num1, num2, KW_SCALE); z = InterposeWideOrHigh(z, dim); z = InterposeScale(z, scale_factor, dim); scaled = TRUE; } } if( !scaled ) { char num1[20], num2[20]; limiter(hd) = why; debug3(DGA, D, " set limiter(%s) = %d %s", SymName(actual(hd)), (int) limiter(hd), EchoObject(limiter(hd))); debug3(DGA, D, " reject: size was %s,%s in %s; y =", EchoLength(back(z, dim)), EchoLength(fwd(z, dim)), EchoConstraint(&c)); ifdebug(DGA, D, DebugObject(y)); if( size(z, dim) > 0 ) { sprintf(num1, "%.1fc", (float) size(z, dim) / CM); sprintf(num2, "%.1fc", (float) bfc(c) / CM); if( dim == ROWM ) Error(19, 14, "%s object too high for %s space; will try elsewhere", WARN, &fpos(y), num1, num2); else Error(19, 15, "%s object too wide for %s space; will try elsewhere", WARN, &fpos(y), num1, num2); } goto REJECT; } } limiter(hd) = why; debug3(DGA, D, " set limiter(%s) = %d %s", SymName(actual(hd)), (int) limiter(hd), EchoObject(limiter(hd))); /* now check perpendicular space for target_galley in target */ Constrained(target, &c, 1-dim, &junk); debug3(DGF, DD, " target perpendicular Constrained(%s, %s) = %s", EchoObject(target), dimen(1-dim), EchoConstraint(&c)); Child(z, LastDown(target_galley)); /* works in all cases? */ assert( !is_index(type(z)), "AttachGalley: is_index(z)!" ); assert( back(z, 1-dim)>=0 && fwd(z, 1-dim)>=0, "AttachGalley: z size (perpendicular)!" ); if( !FitsConstraint(back(z, 1-dim), fwd(z, 1-dim), c) ) { BOOLEAN scaled; /* if forcing galley doesn't fit, try scaling z */ scaled = FALSE; if( force_gall(hd) && size(z, 1-dim) > 0 ) { int scale_factor; scale_factor = ScaleToConstraint(back(z,1-dim), fwd(z,1-dim), &c); if( scale_factor > 0.5 * SF ) { char num1[20], num2[20]; sprintf(num1, "%.1fc", (float) size(z, 1-dim) / CM); sprintf(num2, "%.1fc", (float) bfc(c) / CM); if( 1-dim == ROWM ) Error(19, 10, "%s object too high for %s space; %s inserted", WARN, &fpos(y), num1, num2, KW_SCALE); else Error(19, 11, "%s object too wide for %s space; %s inserted", WARN, &fpos(y), num1, num2, KW_SCALE); z = InterposeWideOrHigh(z, 1-dim); z = InterposeScale(z, scale_factor, 1-dim); scaled = TRUE; } } if( !scaled ) { debug3(DGA, D, " reject: size was %s,%s in %s; y =", EchoLength(back(z, 1-dim)), EchoLength(fwd(z, 1-dim)), EchoConstraint(&c)); ifdebug(DGA, D, DebugObject(y)); goto REJECT; } } /* target seems OK, so adjust sizes and accept */ if( external_hor(target) ) { /* don't adjust any sizes, none to adjust */ debug0(DSA, D, "not calling AdjustSize from AttachGalley (c)"); } else if( external_ver(target) ) { /* adjust perp size only, to galley size */ debug0(DSA, D, "calling AdjustSize from AttachGalley (d)"); AdjustSize(target, back(target_galley, 1-dim), fwd(target_galley, 1-dim), 1-dim); } else { /* adjust both directions, using z (last component) */ Child(z, LastDown(target_galley)); debug0(DSA, D, "AttachGalley AdjustSize using z ="); ifdebug(DSA, D, DebugObject(z)); debug0(DSA, D, "calling AdjustSize from AttachGalley (e)"); AdjustSize(target, back(z, dim), fwd(z, dim), dim); debug0(DSA, D, "calling AdjustSize from AttachGalley (f)"); AdjustSize(target, back(z, 1-dim), fwd(z, 1-dim), 1-dim); } goto ACCEPT; default: assert1(FALSE, "AttachGalley:", Image(type(y))); break; } /* end switch */ } /* end for */ /* null galley: promote whole galley without expanding the target */ debug0(DGA, D, " null galley"); if( tg_inners != nilobj ) DisposeObject(tg_inners), tg_inners = nilobj; DisposeObject(target_galley); LeaveErrorBlock(FALSE); debug0(DYY, D, "] LeaveErrorBlock(FALSE) (null galley)"); /* kill off any null objects within the galley, then transfer it */ /* don't use Promote() since it does extra unwanted things here */ for( link = Down(hd); link != hd; link = NextDown(link) ) { Child(y, link); switch( type(y) ) { case GAP_OBJ: case CLOSURE: case CROSS: case FORCE_CROSS: case NULL_CLOS: case PAGE_LABEL: link = PrevDown(link); debug1(DGA, D, " null galley, disposing %s", Image(type(y))); DisposeChild(NextDown(link)); break; default: break; } } TransferLinks(NextDown(hd), hd, Up(target_index)); /* attach hd temporarily to target_index */ MoveLink(Up(hd), target_index, PARENT); assert( type(hd_index) == UNATTACHED, "AttachGalley: type(hd_index)!" ); DeleteNode(hd_index); /* return; only hd_inners needs to be flushed now */ *inners = hd_inners; debug0(DGA, D, "] AttachGalley returning ATTACH_NULL"); return ATTACH_NULL; REJECT: /* reject first component */ /* debug1(DGA, D, " reject %s", EchoObject(y)); */ debug0(DGA, D, " reject first component"); LeaveErrorBlock(TRUE); debug0(DYY, D, "] LeaveErrorBlock(TRUE) (REJECT)"); if( tg_inners != nilobj ) DisposeObject(tg_inners), tg_inners = nilobj; DisposeObject(target_galley); if( foll_or_prec(hd) == GALL_PREC && !sized(hd) ) { /* move to just before the failed target */ MoveLink(Up(hd_index), Up(target_index), PARENT); } else { /* move to just after the failed target */ MoveLink(Up(hd_index), NextDown(Up(target_index)), PARENT); } continue; SUSPEND: /* suspend at first component */ debug1(DGA, D, " suspend %s", EchoIndex(y)); blocked(y) = TRUE; LeaveErrorBlock(FALSE); debug0(DYY, D, "] LeaveErrorBlock(FALSE) (SUSPEND)"); if( tg_inners != nilobj ) DisposeObject(tg_inners), tg_inners = nilobj; DisposeObject(target_galley); MoveLink(Up(hd_index), Up(target_index), PARENT); if( was_sized ) { /* nothing new to flush if suspending and already sized */ if( hd_inners != nilobj ) DisposeObject(hd_inners), hd_inners=nilobj; *inners = nilobj; } else { /* flush newly discovered inners if not sized before */ *inners = hd_inners; } debug0(DGA, D, "] AttachGalley returning ATTACH_SUSPEND"); *suspend_pt = y; return ATTACH_SUSPEND; ACCEPT: /* accept first component; now committed to the attach */ debug3(DGA, D, " accept %s %s %s", Image(type(y)), EchoObject(y), EchoFilePos(&fpos(y))); LeaveErrorBlock(TRUE); debug0(DYY, D, "] LeaveErrorBlock(TRUE) (ACCEPT)"); /* attach hd to dest */ MoveLink(Up(hd), dest_index, PARENT); assert( type(hd_index) == UNATTACHED, "AttachGalley: type(hd_index)!" ); DeleteNode(hd_index); /* move first component of hd into dest */ /* nb Interpose must be done after all AdjustSize calls */ if( dim == ROWM && !external_ver(dest) ) Interpose(dest, VCAT, hd, y); else if( dim == COLM && !external_hor(dest) ) { Interpose(dest, ACAT, y, y); Parent(junk, Up(dest)); assert( type(junk) == ACAT, "AttachGalley: type(junk) != ACAT!" ); StyleCopy(save_style(junk), save_style(dest)); adjust_cat(junk) = padjust(save_style(junk)); } debug1(DGS, D, "calling Promote(hd, %s) from AttachGalley/ACCEPT", link == hd ? "hd" : "NextDown(link)"); Promote(hd, link == hd ? hd : NextDown(link), dest_index, TRUE); /* move target_galley into target */ /* nb Interpose must be done after all AdjustSize calls */ if( !(external_ver(target) || external_hor(target)) ) { Child(z, LastDown(target_galley)); Interpose(target, VCAT, z, z); } debug0(DGS, D, "calling Promote(target_galley) from AttachGalley/ACCEPT"); Promote(target_galley, target_galley, target_index, TRUE); DeleteNode(target_galley); assert(Down(target_index)==target_index, "AttachGalley: target_ind"); if( blocked(target_index) ) blocked(dest_index) = TRUE; DeleteNode(target_index); /* return; both tg_inners and hd_inners need to be flushed now; */ /* if was_sized, hd_inners contains the inners of the first component; */ /* otherwise it contains the inners of all components, from SizeGalley */ if( tg_inners == nilobj ) *inners = hd_inners; else if( hd_inners == nilobj ) *inners = tg_inners; else { TransferLinks(Down(hd_inners), hd_inners, tg_inners); DeleteNode(hd_inners); *inners = tg_inners; } debug0(DGA, D, "] AttachGalley returning ATTACH_ACCEPT"); ifdebug(DGA, D, if( dim == COLM && !external_hor(dest) ) { OBJECT z; Parent(z, Up(dest)); debug2(DGA, D, " COLM dest_encl on exit = %s %s", Image(type(z)), EchoObject(z)); } ) return ATTACH_ACCEPT; } /* end for */
static int vgap(QWidget *widget1, QWidget *widget2) { return gap(widget1, widget2).height(); }
static int hgap(QWidget *widget1, QWidget *widget2) { return gap(widget1, widget2).width(); }
void BasicBlockLocation::insertGap(int startOffset, int endOffset) { std::pair<int, int> gap(startOffset, endOffset); if (!m_gaps.contains(gap)) m_gaps.append(gap); }
inline VGlue* vgap (int n = 1) { return new VGlue(gap(n), gap(n), gap(2*n)); }