Changeset 371f9ed in git for src/gfxcore.cc


Ignore:
Timestamp:
11/03/15 04:00:45 (5 years ago)
Author:
Olly Betts <olly@…>
Branches:
line_contents, master, stereo, travis-osx
Children:
47c62d04
Parents:
91756e4
Message:

src/gfxcore.cc,src/gfxcore.h: Factor out function to pick the colour
pen based on a value between 0 and 1.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gfxcore.cc

    r91756e4 r371f9ed  
    26562656    assert(how_far >= 0.0);
    26572657    assert(how_far <= 1.0);
    2658 
    2659     int band = int(floor(how_far * (GetNumColourBands() - 1)));
    2660     GLAPen pen1 = GetPen(band);
    2661     if (band < GetNumColourBands() - 1) {
    2662         const GLAPen& pen2 = GetPen(band + 1);
    2663 
    2664         Double interval = date_ext / (GetNumColourBands() - 1);
    2665         Double into_band = date_offset / interval - band;
    2666 
    2667         assert(into_band >= 0.0);
    2668         assert(into_band <= 1.0);
    2669 
    2670         pen1.Interpolate(pen2, into_band);
    2671     }
    2672     SetColour(pen1, factor);
     2658    SetColourFrom01(how_far, factor);
    26732659}
    26742660
     
    27322718    assert(how_far >= 0.0);
    27332719    if (how_far > 1.0) how_far = 1.0;
    2734 
    2735     int band = int(floor(how_far * (GetNumColourBands() - 1)));
    2736     GLAPen pen1 = GetPen(band);
    2737     if (band < GetNumColourBands() - 1) {
    2738         const GLAPen& pen2 = GetPen(band + 1);
    2739 
    2740         Double interval = MAX_ERROR / (GetNumColourBands() - 1);
    2741         Double into_band = E / interval - band;
    2742 
    2743         assert(into_band >= 0.0);
    2744         assert(into_band <= 1.0);
    2745 
    2746         pen1.Interpolate(pen2, into_band);
    2747     }
    2748     SetColour(pen1, factor);
     2720    SetColourFrom01(how_far, factor);
    27492721}
    27502722
     
    27872759    how_far = max(how_far, 0.0);
    27882760    how_far = min(how_far, 1.0);
    2789 
    2790     int band = int(floor(how_far * (GetNumColourBands() - 1)));
     2761    SetColourFrom01(how_far, factor);
     2762}
     2763
     2764void GfxCore::SetColourFrom01(double how_far, Double factor)
     2765{
     2766    double b;
     2767    double into_band = modf(how_far * (GetNumColourBands() - 1), &b);
     2768    int band(b);
    27912769    GLAPen pen1 = GetPen(band);
    2792     if (band < GetNumColourBands() - 1) {
     2770    // With 24bit colour, interpolating by less than this can have no effect.
     2771    if (into_band >= 1.0 / 512.0) {
    27932772        const GLAPen& pen2 = GetPen(band + 1);
    2794 
    2795         Double interval = LOG_LEN_MAX / (GetNumColourBands() - 1);
    2796         Double into_band = log_len / interval - band;
    2797 
    2798         assert(into_band >= 0.0);
    2799         assert(into_band <= 1.0);
    2800 
    28012773        pen1.Interpolate(pen2, into_band);
    28022774    }
Note: See TracChangeset for help on using the changeset viewer.