Пример #1
0
vector<int> Solution034::searchRange(vector<int> &nums, int target)
{
    vector<int> res;
    res.push_back( findLower(nums,target));
    res.push_back( findUpper(nums,target));
    return res;
}
Пример #2
0
void QwtLinearColorMap::ColorStops::insert( double pos, const QColor &color )
{
    // Lookups need to be very fast, insertions are not so important.
    // Anyway, a balanced tree is what we need here. TODO ...

    if ( pos < 0.0 || pos > 1.0 )
        return;

    int index;
    if ( _stops.size() == 0 )
    {
        index = 0;
        _stops.resize( 1 );
    }
    else
    {
        index = findUpper( pos );
        if ( index == _stops.size() ||
                qAbs( _stops[index].pos - pos ) >= 0.001 )
        {
            _stops.resize( _stops.size() + 1 );
            for ( int i = _stops.size() - 1; i > index; i-- )
                _stops[i] = _stops[i-1];
        }
    }

    _stops[index] = ColorStop( pos, color );
}
Пример #3
0
void QwtLinearColorMap::ColorStops::insert(double pos, const QColor &color)
{
    // Lookups need to be very fast, insertions are not so important.
    // Anyway, a balanced tree is what we need here. TODO ...

    if ( pos < 0.0 || pos > 1.0 )
        return;

    int index;
    if ( _stops.size() == 0 ) {
        index = 0;
#if QT_VERSION < 0x040000
        _stops.resize(1, QGArray::SpeedOptim);
#else
        _stops.resize(1);
#endif
    } else {
        index = findUpper(pos);
        if ( index == (int)_stops.size() ||
                qwtAbs(_stops[index].pos - pos) >= 0.001 ) {
#if QT_VERSION < 0x040000
            _stops.resize(_stops.size() + 1, QGArray::SpeedOptim);
#else
            _stops.resize(_stops.size() + 1);
#endif
            for ( int i = _stops.size() - 1; i > index; i-- )
                _stops[i] = _stops[i-1];
        }
    }

    _stops[index] = ColorStop(pos, color);
}
Пример #4
0
inline QRgb QwtLinearColorMap::ColorStops::rgb(
    QwtLinearColorMap::Mode mode, double pos ) const
{
    if ( pos <= 0.0 )
        return _stops[0].rgb;
    if ( pos >= 1.0 )
        return _stops[ _stops.size() - 1 ].rgb;

    const int index = findUpper( pos );
    if ( mode == FixedColors )
    {
        return _stops[index-1].rgb;
    }
    else
    {
        const ColorStop &s1 = _stops[index-1];
        const ColorStop &s2 = _stops[index];

        const double ratio = ( pos - s1.pos ) / ( s2.pos - s1.pos );

        const int r = s1.r + qRound( ratio * ( s2.r - s1.r ) );
        const int g = s1.g + qRound( ratio * ( s2.g - s1.g ) );
        const int b = s1.b + qRound( ratio * ( s2.b - s1.b ) );

        return qRgb( r, g, b );
    }
}