//! Return the range of numbers that might be used with this format to //! represent a number within `x`. Interval FloatFormat::convert (const Interval& x) const { Interval ret; Interval tmp = x; if (x.hasNaN()) { // If NaN might be supported, NaN is a legal return value if (m_hasNaN != NO) ret |= TCU_NAN; // If NaN might not be supported, any (non-NaN) value is legal, // _subject_ to clamping. Hence we modify tmp, not ret. if (m_hasNaN != YES) tmp = Interval::unbounded(); } // Round both bounds _inwards_ to closest representable values. if (!tmp.empty()) ret |= clampValue(round(tmp.lo(), true)) | clampValue(round(tmp.hi(), false)); // If this format's precision is not exact, the (possibly out-of-bounds) // original value is also a possible result. if (!m_exactPrecision) ret |= x; return ret; }
void GameVisualScene::updateCamera() { static f32 rotz; static f32 rotx = 5.0; static f32 roty = 5.0; rotz += f32(game->inputSystem.getMouseMovement(2))/200.0f; //rotz = clampValue(rotz,1.0f,50.0f); rotz = clampValue(rotz,5.0f,25.0f); if(game->inputSystem.mouse.state.isBtnDown(1)) { rotx += (f32)game->inputSystem.getMouseMovement(0); roty += (f32)game->inputSystem.getMouseMovement(1); rotx = circularValue(rotx,0.0f,360.0f); roty = clampValue(roty,5.0f,85.0f); Ogre::Vector3 pos = Ogre::Vector3::ZERO; pos.z = rotz*cos(hmath::deg(rotx).asRad())*sin(hmath::deg(roty).asRad()); pos.x = rotz*sin(hmath::deg(rotx).asRad())*sin(hmath::deg(roty).asRad()); pos.y = rotz*cos(hmath::deg(roty).asRad()); game->visualSystem.getCamera()->setPosition(pos - Ogre::Vector3(2.5f,1.5f,0.0f)); game->inputSystem.resetMouseMovement(); } }
void DateTimeNumericFieldElement::stepDown() { if (m_hasValue) setValueAsInteger(m_value == m_range.minimum ? m_range.maximum : clampValue(m_value - 1), DispatchEvent); else setValueAsInteger(defaultValueForStepDown(), DispatchEvent); }
void DateTimeNumericFieldElement::stepUp() { if (m_hasValue) setValueAsInteger(m_value == m_range.maximum ? m_range.minimum : clampValue(m_value + 1), DispatchEvent); else setValueAsInteger(m_range.minimum, DispatchEvent); }
void DateTimeNumericFieldElement::setValueAsInteger(int value, EventBehavior eventBehavior) { m_value = clampValue(value); m_hasValue = true; updateVisibleValue(eventBehavior); m_lastDigitCharTime = 0; }
void EffectParameter::setMaximum(double maximum) { m_maximum = maximum; if (m_maximum > m_parameter.getMaximum()) { qWarning() << debugString() << "WARNING: Maximum value is less than plugin's absolute maximum, clamping."; m_maximum = m_parameter.getMaximum(); } if (m_maximum < m_minimum) { qWarning() << debugString() << "WARNING: New maximum was below the minimum, clamped."; m_maximum = m_minimum; } // There's a degenerate case here where the minimum could be larger // than the manifest maximum. If that's the case, then the maximum // value is currently above the manifest maximum. Since similar // guards exist in the setMinimum call, this should not be able to // happen. Q_ASSERT(m_maximum <= m_parameter.getMaximum()); if (clampValue()) { qWarning() << debugString() << "WARNING: Value was outside of new maximum, clamped."; } if (clampDefault()) { qWarning() << debugString() << "WARNING: Default was outside of new maximum, clamped."; } updateEngineState(); }
/*Does the brightness peration. *Uses clampValue to perform image saturation. * *Return: *An unsigned char from 0-255. */ unsigned char performBrt(double amount, unsigned char color) { unsigned char newVal = '\0'; double rawAdd = color + amount; newVal = clampValue(rawAdd); return newVal; }
/*Split the pixel value into values that evenly range from [-.5,.5], *perform contrast adjustment, and then convert back to unsigned char. * *Return: *The new pixel values that are unsigned char ranging from 0-255. */ unsigned char splitValues(double cnAdjust, unsigned char pixVal) { double adjustedValue = (double) pixVal/255; double newPixVal = adjustedValue - 0.5; newPixVal = (cnAdjust*newPixVal + .5) * 255; unsigned char send = clampValue(newPixVal); return send; }
void EffectParameter::setValue(double value) { // TODO(XXX) Handle inf, -inf, and nan m_value = value; if (clampValue()) { qWarning() << debugString() << "WARNING: Value was outside of limits, clamped."; } m_value = value; updateEngineState(); emit(valueChanged(m_value)); }
/* *Contains algorithm to convolve an image with a gaussian matrix. *Parameters: *orig: a pointer to our original pixel array *gmatrix: our gaussian matrix *size: the size of the gmatrix (it's always square) *center: the center of the gmatrix *x: the x location of the pixel we're convolving around *y: the y location of the pixel we're convolving around *colNum: the number of columns in our image *rowNum: the number of rows in our image * */ void convolve(Pixel* orig, Pixel* data, double** gmatrix, int size, int center, int x, int y,int colNum, int rowNum) { //variables for the sums of things we need. double sumR = 0; double sumG = 0; double sumB = 0; double sumGauss = 0; //loops around each value of the gmatrix for(int j=0; j<size; j++) { for(int i=0; i<size; i++) { //if the location of the value in the gmatrix is not on top of a pixel, we //don't want to attempt to convolve, or we segfault. if(((i-center) < 0) || ((j-center) < 0) || ((x+i-center+1)>colNum) || ((y+j-center+1)>rowNum)) { //don't do anything } //if it's a legitamate possible convolution: else { //add the gmatrix value to our sum sumGauss = sumGauss + gmatrix[j][i]; //add the gaussian-filtered pixel values to their respective sums sumR = sumR + gmatrix[j][i]*(orig[(y+(j-center))*colNum+(x+i-center)].r); sumG = sumG + gmatrix[j][i]*(orig[(y+(j-center))*colNum+(x+i-center)].g); sumB = sumB + gmatrix[j][i]*(orig[(y+(j-center))*colNum+(x+i-center)].b); } } } //normalize the values sumR = (sumR/sumGauss); sumG = (sumG/sumGauss); sumB = (sumB/sumGauss); //transfer the values to our data pixel array, making sure they're clamped. data[(y*colNum)+x].r = clampValue(sumR); data[(y*colNum)+x].g = clampValue(sumG); data[(y*colNum)+x].b = clampValue(sumB); return; }
QString WeatherApplet::convertTemperature(KUnitConversion::Unit format, float value, int type, bool rounded, bool degreesOnly) { KUnitConversion::Value v(value, static_cast<KUnitConversion::UnitId>(type)); v = v.convertTo(format); if (rounded) { int tempNumber = qRound(v.number()); if (degreesOnly) { return i18nc("temperature, unit", "%1%2", tempNumber, i18nc("Degree, unit symbol", "°")); } else { return i18nc("temperature, unit", "%1%2", tempNumber, v.unit().symbol()); } } else { const QString formattedTemp = QLocale().toString(clampValue(v.number(), 1), 'f', 1); if (degreesOnly) { return i18nc("temperature, unit", "%1%2", formattedTemp, i18nc("Degree, unit symbol", "°")); } else { return i18nc("temperature, unit", "%1%2", formattedTemp, v.unit().symbol()); } } }
/* *Contains algorithm to sharpen an image with specified values *Parameters: *sigma: the sigma for the preliminary blur *intensity: the intensity of the sharpening *img: a pointer to our image in memory. * * *return 0 if no errors were encountered, 1 otherwise. */ int sharpen(Image* img, double sigma, double intensity) { //if we don't have a file in memory, say so. if(img->data == NULL) { fprintf(stderr, "Error, no file currently in memory\n"); return 1; } //our temporary blurred image Image blurred; blurred.data = malloc(sizeof(Pixel)*(img->rowNum*img->colNum)); blurred.rowNum = img->rowNum; blurred.colNum = img->colNum; blurred.color = MAX_RGB_VALUE; //transfer the data from our real image into the blurred one for(int j = 0; j<(img->rowNum); j++) { for(int i = 0; i<(img->colNum); i++) { blurred.data[j*(img->colNum)+i].r = img->data[j*(img->colNum)+i].r; blurred.data[j*(img->colNum)+i].g = img->data[j*(img->colNum)+i].g; blurred.data[j*(img->colNum)+i].b = img->data[j*(img->colNum)+i].b; } } //our sharpened image Image sharp; sharp.data = malloc(sizeof(Pixel)*(img->rowNum*img->colNum)); sharp.rowNum = img->rowNum; sharp.colNum = img->colNum; sharp.color = MAX_RGB_VALUE; double rSharp = 0; double gSharp = 0; double bSharp = 0; //blur our "blurred" image blur(sigma, &blurred); //this does the sharpening algorithm for(int j=0; j<(img->rowNum);j++) { for(int i=0; i<(img->colNum);i++) { //for each pixel, compute the difference from the original and the blurred rSharp = (img->data[j*(img->colNum)+i].r) - (blurred.data[j*(img->colNum)+i].r); gSharp = (img->data[j*(img->colNum)+i].g) - (blurred.data[j*(img->colNum)+i].g); bSharp = (img->data[j*(img->colNum)+i].b) - (blurred.data[j*(img->colNum)+i].b); //multiply it by the intensity factor rSharp *= intensity; gSharp *= intensity; bSharp *= intensity; //clamp the value, saturating rather than overflowing sharp.data[j*(img->colNum)+i].r=clampValue(((rSharp) + (img->data[j*(img->colNum)+i].r))); sharp.data[j*(img->colNum)+i].g=clampValue(((gSharp) + (img->data[j*(img->colNum)+i].g))); sharp.data[j*(img->colNum)+i].b=clampValue(((bSharp) + (img->data[j*(img->colNum)+i].b))); } } //put the sharpened data into our image in memory for(int j = 0; j<(img->rowNum); j++) { for(int i = 0; i<(img->colNum); i++) { img->data[j*(img->colNum)+i].r = sharp.data[j*(img->colNum)+i].r; img->data[j*(img->colNum)+i].g = sharp.data[j*(img->colNum)+i].g; img->data[j*(img->colNum)+i].b = sharp.data[j*(img->colNum)+i].b; } } //free our temporary images. free(sharp.data); free(blurred.data); return 0; }
btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges) : btConcaveShape (), m_heightStickWidth(heightStickWidth), m_heightStickLength(heightStickLength), m_maxHeight(maxHeight), m_width((btScalar)heightStickWidth-1), m_length((btScalar)heightStickLength-1), m_heightfieldDataUnknown(heightfieldData), m_useFloatData(useFloatData), m_flipQuadEdges(flipQuadEdges), m_useDiamondSubdivision(false), m_upAxis(upAxis), m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)) { m_shapeType = TERRAIN_SHAPE_PROXYTYPE; btScalar quantizationMargin = 1.f; //enlarge the AABB to avoid division by zero when initializing the quantization values btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin); btVector3 halfExtents(0,0,0); switch (m_upAxis) { case 0: { halfExtents.setValue( btScalar(m_maxHeight), btScalar(m_width), //?? don't know if this should change btScalar(m_length)); break; } case 1: { halfExtents.setValue( btScalar(m_width), btScalar(m_maxHeight), btScalar(m_length)); break; }; case 2: { halfExtents.setValue( btScalar(m_width), btScalar(m_length), btScalar(m_maxHeight) ); break; } default: { //need to get valid m_upAxis btAssert(0); } } halfExtents*= btScalar(0.5); m_localAabbMin = -halfExtents - clampValue; m_localAabbMax = halfExtents + clampValue; btVector3 aabbSize = m_localAabbMax - m_localAabbMin; }
void WeatherApplet::updateDetailsModel(const Plasma::DataEngine::Data &data) { m_detailsModel.clear(); QLocale locale; const QString textId = QStringLiteral("text"); const QString iconId = QStringLiteral("icon"); // reused map for each row QVariantMap row; row.insert(iconId, QString()); row.insert(textId, QString()); const int reportTemperatureUnit = data[QStringLiteral("Temperature Unit")].toInt(); const KUnitConversion::Unit displayTemperatureUnit = temperatureUnit(); const QVariant windChill = data[QStringLiteral("Windchill")]; if (isValidData(windChill)) { // Use temperature unit to convert windchill temperature // we only show degrees symbol not actual temperature unit const QString temp = convertTemperature(displayTemperatureUnit, windChill, reportTemperatureUnit, false, true); row[textId] = i18nc("windchill, unit", "Windchill: %1", temp); m_detailsModel << row; } const QString humidex = data[QStringLiteral("Humidex")].toString(); if (isValidData(humidex)) { // TODO: this seems wrong, does the humidex have temperature as units? // Use temperature unit to convert humidex temperature // we only show degrees symbol not actual temperature unit QString temp = convertTemperature(displayTemperatureUnit, humidex, reportTemperatureUnit, false, true); row[textId] = i18nc("humidex, unit","Humidex: %1", temp); m_detailsModel << row; } const QVariant dewpoint = data[QStringLiteral("Dewpoint")]; if (isValidData(dewpoint)) { QString temp = convertTemperature(displayTemperatureUnit, dewpoint, reportTemperatureUnit); row[textId] = i18nc("ground temperature, unit", "Dewpoint: %1", temp); m_detailsModel << row; } const QVariant pressure = data[QStringLiteral("Pressure")]; if (isValidData(pressure)) { KUnitConversion::Value v(pressure.toDouble(), static_cast<KUnitConversion::UnitId>(data["Pressure Unit"].toInt())); v = v.convertTo(pressureUnit()); row[textId] = i18nc("pressure, unit","Pressure: %1 %2", locale.toString(clampValue(v.number(), 2), 'f', 2), v.unit().symbol()); m_detailsModel << row; } const QString pressureTendency = data["Pressure Tendency"].toString(); if (isValidData(pressureTendency)) { const QString i18nPressureTendency = i18nc("pressure tendency", pressureTendency.toUtf8().data()); row[textId] = i18nc("pressure tendency, rising/falling/steady", "Pressure Tendency: %1", i18nPressureTendency); m_detailsModel << row; } const QVariant visibility = data[QStringLiteral("Visibility")]; if (isValidData(visibility)) { const KUnitConversion::UnitId unitId = static_cast<KUnitConversion::UnitId>(data["Visibility Unit"].toInt()); if (unitId != KUnitConversion::NoUnit) { KUnitConversion::Value v(visibility.toDouble(), unitId); v = v.convertTo(visibilityUnit()); row[textId] = i18nc("distance, unit","Visibility: %1 %2", locale.toString(clampValue(v.number(), 1), 'f', 1), v.unit().symbol()); } else { row[textId] = i18nc("visibility from distance", "Visibility: %1", visibility.toString()); } m_detailsModel << row; } const QVariant humidity = data[QStringLiteral("Humidity")]; if (isValidData(humidity)) { row[textId] = i18nc("content of water in air", "Humidity: %1%2", locale.toString(clampValue(humidity.toFloat(), 0), 'f', 0), i18nc("Percent, measure unit", "%")); m_detailsModel << row; } const QVariant windSpeed = data[QStringLiteral("Wind Speed")]; if (isValidData(windSpeed)) { // TODO: missing check for windDirection validness const QString windDirection = data["Wind Direction"].toString(); row[iconId] = windDirection; bool isNumeric; const double windSpeedNumeric = windSpeed.toDouble(&isNumeric); if (isNumeric) { if (windSpeedNumeric != 0) { KUnitConversion::Value v(windSpeedNumeric, static_cast<KUnitConversion::UnitId>(data["Wind Speed Unit"].toInt())); v = v.convertTo(speedUnit()); const QString i18nWindDirection = i18nc("wind direction", windDirection.toUtf8().data()); row[textId] = i18nc("wind direction, speed","%1 %2 %3", i18nWindDirection, locale.toString(clampValue(v.number(), 1), 'f', 1), v.unit().symbol()); } else { row[textId] = i18nc("Wind condition", "Calm"); } } else { row[textId] = windSpeed.toString(); } m_detailsModel << row; row[iconId] = QString(); // reset } const QVariant windGust = data[QStringLiteral("Wind Gust")]; if (isValidData(windGust)) { // Convert the wind format for nonstandard types KUnitConversion::Value v(windGust.toDouble(), static_cast<KUnitConversion::UnitId>(data["Wind Speed Unit"].toInt())); v = v.convertTo(speedUnit()); row[textId] = i18nc("winds exceeding wind speed briefly", "Wind Gust: %1 %2", locale.toString(clampValue(v.number(), 1), 'f', 1), v.unit().symbol()); m_detailsModel << row; } }
bool EffectParameter::clampDefault() { return clampValue(&m_default, m_minimum, m_maximum); }
int DateTimeNumericFieldElement::clampValueForHardLimits(int value) const { return clampValue(value); }
bool EffectParameter::clampValue() { return clampValue(&m_value, m_minimum, m_maximum); }
// ###################################################################### void DirectFeedChannel::clampCoeffs(const double cmin, const double cmax) { killCaches(); for (uint i = 0; i < itsCoeff.size(); ++i) itsCoeff[i] = clampValue(itsCoeff[i], cmin, cmax); }