void GuiPart::updateConnectorPoints( bool add ) { ICNDocument *icnd = dynamic_cast<ICNDocument*>(p_parent->itemDocument()); if ( !icnd) return; Cells * cells = icnd->cells(); if (!cells) return; if ( !isVisible() ) add = false; if ( add == b_pointsAdded ) return; b_pointsAdded = add; int mult = add ? 1 : -1; int sx = roundDown( x(), 8 ); int sy = roundDown( y(), 8 ); int ex = roundDown( x()+width(), 8 ); int ey = roundDown( y()+height(), 8 ); for ( int x=sx; x<=ex; ++x ) { for ( int y=sy; y<=ey; ++y ) { if ( cells->haveCell( x, y ) ) cells->cell( x, y ).CIpenalty += mult*ICNDocument::hs_item/2; } } }
void DateTimeNumericFieldElement::stepDown() { int newValue = roundDown(m_hasValue ? m_value - 1 : defaultValueForStepDown()); if (!m_range.isInRange(newValue)) newValue = roundDown(m_range.maximum); m_typeAheadBuffer.clear(); setValueAsInteger(newValue, DispatchEvent); }
void task_free(Task *t) { ASSERT_int_disable(); ASSERT(t == task_curr); ipc_task_free(t); task_curr_free_files(); uint32_t count_brk = (roundUp(t->pgdir.end_brk) - roundDown(t->pgdir.start_brk)) / 0x1000; /* code, heap ve stack alanlari toplami user alanina esit olmali */ ASSERT(t->pgdir.count_stack + t->pgdir.count_program + count_brk == t->pgdir.count_user); task_free_vm_user(t); ASSERT(t->pgdir.count_user == 0); /* * kernel stack ve pagedir daha sonra zombie list uzerinden silinecek. * task structini bulundugu listeden cikar, zombie olarak isaretle ve * task_zombie_list'e ekle. */ t->list_node.__list->erase(t->list_node.get_iterator()); t->state = Task::State_zombie; task_zombie_list.push_back(&t->list_node); if (t->alarm_list_node.__list) t->alarm_list_node.__list->erase(&t->alarm_list_node); }
void VdbGrid::generateSuperGrid() { const int offset = _supergridSubsample/2; auto divideCoord = [&](const openvdb::Coord &a) { return openvdb::Coord( roundDown(a.x() + offset, _supergridSubsample), roundDown(a.y() + offset, _supergridSubsample), roundDown(a.z() + offset, _supergridSubsample)); }; _superGrid = Vec2fGrid::create(openvdb::Vec2s(0.0f)); auto accessor = _superGrid->getAccessor(); Vec2fGrid::Ptr minMaxGrid = Vec2fGrid::create(openvdb::Vec2s(1e30f, 0.0f)); auto minMaxAccessor = minMaxGrid->getAccessor(); for (openvdb::FloatGrid::ValueOnCIter iter = _grid->cbeginValueOn(); iter.test(); ++iter) { openvdb::Coord coord = divideCoord(iter.getCoord()); float d = *iter; accessor.setValue(coord, openvdb::Vec2s(accessor.getValue(coord).x() + d, 0.0f)); openvdb::Vec2s minMax = minMaxAccessor.getValue(coord); minMaxAccessor.setValue(coord, openvdb::Vec2s(min(minMax.x(), d), max(minMax.y(), d))); } float normalize = 1.0f/cube(_supergridSubsample); const float Gamma = 2.0f; const float D = std::sqrt(3.0f)*_supergridSubsample; for (Vec2fGrid::ValueOnIter iter = _superGrid->beginValueOn(); iter.test(); ++iter) { openvdb::Vec2s minMax = minMaxAccessor.getValue(iter.getCoord()); float muMin = minMax.x(); float muMax = minMax.y(); float muAvg = iter->x()*normalize; float muR = muMax - muMin; float muC = clamp(muMin + muR*(std::pow(Gamma, 1.0f/(D*muR)) - 1.0f), muMin, muAvg); iter.setValue(openvdb::Vec2s(muC, 0.0f)); } for (openvdb::FloatGrid::ValueOnCIter iter = _grid->cbeginValueOn(); iter.test(); ++iter) { openvdb::Coord coord = divideCoord(iter.getCoord()); openvdb::Vec2s v = accessor.getValue(coord); float residual = max(v.y(), std::abs(*iter - v.x())); accessor.setValue(coord, openvdb::Vec2s(v.x(), residual)); } }
quint32 howManyFitHorizontally(const qreal cellWidthF,const qreal areaWidthF) { if (isZeroF(cellWidthF)) { return 0; } return (quint32)roundDown(areaWidthF / cellWidthF); }
//use this for "smaller squares into bigger square" class of problems quint32 howManyFitHorizontally(const quint32 cellWidth,const quint32 areaWidth) { if (cellWidth == 0) { return 0; } return (quint32)roundDown((qreal)areaWidth / (qreal)cellWidth); }
//Radians float convertToAngle(float x,float y) { x=roundDown(x,5); y=roundDown(y,5); float addAngle=0; if (x==0 && y>0) { return PI/2; } else if (x==0 && y<0) { return 3*PI/2; } else if (x==0 && y==0) { return 0; }; float absX=x; float absY=y; if (x<0) { absX*=-1; }; if (y<0) { absY*=-1; }; float angle=atan(absY/absX); if (y>=0 && x<0) { angle=PI-angle; } else if (y<0 && x<0) { angle=PI+angle; } else if (y<0 && x>=0) { angle=2*PI-angle; } else { }; return angle; };
float Math::normalizeAngle(float radians) { radians += PI; float d = (float)(roundDown(radians / TWO_PI)); radians -= d * TWO_PI; radians -= PI; return radians; }
void AbgasTemperatureView(void) { uint16_t i,y; MEASUREMENT_VIEW_struct * viewMem = pt100_getViewMem(); LCD_ClearScreen(); LCD_SetPenColor(1); LCD_SetFont(0); LCD_PrintXY(30,0,"ABGAS:"); LCD_PrintXY(80,0,viewMem->cur_value); LCD_SetFont(0); int max = roundUp(viewMem->max); int min = roundDown(viewMem->min); int diff = max-min; int span; if(!diff) { span = 10; if(min) min -= 10; }else { span = diff/3; } if(span < 10) span = 10; char dummy[10]; sprintf(dummy,"%4u-",min+(span*3)); LCD_PrintXY(0,0, dummy); sprintf(dummy,"%4u-",min+(span*2)); LCD_PrintXY(0,18,dummy); sprintf(dummy,"%4u-",min+(span*1)); LCD_PrintXY(0,37,dummy); sprintf(dummy,"%4u-",min); LCD_PrintXY(0,56,dummy); LCD_DrawLine(27,0,27,63); diff = (span*3); for(i=27;i<128;i++) { y = viewMem->Mem[127-i]; y = 64 - ((double)(y-min)*(double)(64.0/diff)); LCD_PutPixel(i,y,1); LCD_PutPixel(i,y+1,1); } }
MemoryTable::MemoryTable(void *base, size_t size, bool initialize) : mBase(0) , mSize(0) { #ifndef __GNUG__ #error "Alignment testing required" #endif // base address must be aligned for the metadata struct if (!base) { qWarning() << "Invalid address for table:" << base; return; } if ((reinterpret_cast<size_t>(base) % __alignof__(TableMetadata)) != 0) { qWarning() << "Invalid address alignment for table:" << base << "requires:" << __alignof__(TableMetadata); return; } // We must align the allocation space with the Allocation struct size_t managedSize = roundDown(size, __alignof__(Allocation)); if (managedSize <= sizeof(TableMetadata)) { qWarning() << "Invalid size alignment for table:" << base << "requires:" << __alignof__(Allocation); return; } TableMetadata *table = reinterpret_cast<TableMetadata *>(base); if (initialize) { table->size = static_cast<quint64>(managedSize); table->count = 0; table->freeOffset = table->size; table->freeList = 0; } else { if (table->size != managedSize) { qWarning() << "Invalid size for initialized table:" << table->size << "!=" << managedSize; return; } } mBase = base; mSize = table->size; }
quint32 maxCellWidth(const quint32 howManyCells,const qreal areaWidthF) { return (quint32)roundDown(areaWidthF / (qreal)howManyCells); }
quint32 maxCellWidth(const quint32 howManyCells,const quint32 areaWidth) { return (quint32)roundDown((qreal)areaWidth / (qreal)howManyCells); }
quint32 fractionalSize(quint32 v,quint32 fractional) { return (quint32)roundDown((qreal)v/(qreal)fractional); }
float Math::fractionalPart(float x) { return x - roundDown(x); }
int roundDown(float numberToRound, double threshold) { return roundDown(static_cast<double>(numberToRound), threshold); }
void CNItem::updateConnectorPoints( bool add ) { if ( b_deleted || !isVisible() ) add = false; if ( b_pointsAdded == add ) return; b_pointsAdded = add; Cells *cells = p_icnDocument->cells(); if (!cells) return; // Get translation matrix // Hackish... QWMatrix m; if ( Component *c = dynamic_cast<Component*>(this) ) m = c->transMatrix( c->angleDegrees(), c->flipped(), int(x()), int(y()), false ); // Convention used here: _UM = unmapped by both matrix and cell reference, _M = mapped const QPoint start_UM = QPoint( int(x()+offsetX())-8, int(y()+offsetY())-8 ); const QPoint end_UM = start_UM + QPoint( width()+2*8, height()+2*8 ); const QPoint start_M = roundDown( m.map(start_UM), 8 ); const QPoint end_M = roundDown( m.map(end_UM), 8 ); int sx_M = start_M.x(); int ex_M = end_M.x(); int sy_M = start_M.y(); int ey_M = end_M.y(); // Normalise start and end points if ( sx_M > ex_M ) { const int temp = sx_M; sx_M = ex_M; ex_M = temp; } if ( sy_M > ey_M ) { const int temp = sy_M; sy_M = ey_M; ey_M = temp; } ex_M++; ey_M++; const int mult = add ? 1 : -1; for ( int x = sx_M; x < ex_M; x++ ) { for ( int y = sy_M; y < ey_M; y++ ) { if ( cells->haveCell( x, y ) ) { if ( x != sx_M && y != sy_M && x != (ex_M-1) && y != (ey_M-1) ) { cells->cell( x, y ).CIpenalty += mult*ICNDocument::hs_item; } else { // (*cells)[x][y].CIpenalty += mult*ICNDocument::hs_item/2; cells->cell( x, y ).CIpenalty += mult*ICNDocument::hs_connector*5; } } } } #if 0 // And subtract the positions of the node on the border NodeInfoMap::iterator end = m_nodeMap.end(); for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it ) { const int x = (int)((it->second.node->x()-4)/cellSize); const int y = (int)((it->second.node->y()-4)/cellSize); if ( p_icnDocument->isValidCellReference(x,y) ) { (*cells)[x][y].CIpenalty -= mult*ICNDocument::hs_connector*5; } } #endif const TextMap::iterator textMapEnd = m_textMap.end(); for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it ) { it.data()->updateConnectorPoints(add); } const WidgetMap::iterator widgetMapEnd = m_widgetMap.end(); for ( WidgetMap::iterator it = m_widgetMap.begin(); it != widgetMapEnd; ++it ) { it.data()->updateConnectorPoints(add); } }