Ticket #4218: interpolationSplit2016_9_24.diff

File interpolationSplit2016_9_24.diff, 5.5 KB (added by FeXoR, 8 years ago)

Patch as I think should be committed (removed "convolution" argument)

  • binaries/data/mods/public/globalscripts/BicubicInterpolation.js

     
    1 /**
    2  * From https://github.com/hughsk/bicubic licensed under MIT 2013 Hugh Kennedy - see /license_mit.txt
    3  * Two dimensional interpolation within a square grid using polynomials of 3rd degree.
    4  * @param {float} xf - X coordinate within the subgrid (see below) of the point to interpolate the value for
    5  * @param {float} yf - y coordinate within the subgrid (see below) of the point to interpolate the value for
    6  * @param {float} p00 - Value of the property to calculate at the origin of the naighbor grid
    7  * @param {float} pxy - Value at naighbor grid coordinates x/y, x/y in {0, 1, 2, 3}
    8  * @return {float} - Value at the given float coordinates in the small grid interpolated from it's values
    9   */
    10 function bicubicInterpolation(
    11     xf, yf,
    12     p00, p01, p02, p03,
    13     p10, p11, p12, p13,
    14     p20, p21, p22, p23,
    15     p30, p31, p32, p33
    16 )
    17 {
    18     var yf2 = yf * yf;
    19     var xf2 = xf * xf;
    20     var xf3 = xf * xf2;
    21 
    22     var x00 = p03 - p02 - p00 + p01;
    23     var x01 = p00 - p01 - x00;
    24     var x02 = p02 - p00;
    25     var x0 = x00*xf3 + x01*xf2 + x02*xf + p01;
    26 
    27     var x10 = p13 - p12 - p10 + p11;
    28     var x11 = p10 - p11 - x10;
    29     var x12 = p12 - p10;
    30     var x1 = x10*xf3 + x11*xf2 + x12*xf + p11;
    31 
    32     var x20 = p23 - p22 - p20 + p21;
    33     var x21 = p20 - p21 - x20;
    34     var x22 = p22 - p20;
    35     var x2 = x20*xf3 + x21*xf2 + x22*xf + p21;
    36 
    37     var x30 = p33 - p32 - p30 + p31;
    38     var x31 = p30 - p31 - x30;
    39     var x32 = p32 - p30;
    40     var x3 = x30*xf3 + x31*xf2 + x32*xf + p31;
    41 
    42     var y0 = x3 - x2 - x0 + x1;
    43     var y1 = x0 - x1 - y0;
    44     var y2 = x2 - x0;
    45 
    46     return y0*yf*yf2 + y1*yf2 + y2*yf + x1;
    47 }
  • binaries/data/mods/public/globalscripts/interpolation.js

     
     1/**
     2 * Two dimensional interpolation within four equidistant points using polynomials of 3rd degree.
     3 * @param {float} xf - Float coordinate relative to p1 to interpolate the property for
     4 * @param {float} p0 - Value of the property to calculate at the origin of four point scale
     5 * @param {float} px - Value at the property of the corresponding point on the scale
     6 * @return {float} - Value at the given float position in the 4-point scale interpolated from it's property values
     7 */
     8function cubicInterpolation(xf, p0, p1, p2, p3)
     9{
     10     return p1
     11        + (-0.5 * p0 + 0.5 * p2) * xf
     12        + (p0 - 2.5 * p1 + 2.0 * p2 - 0.5 * p3) * xf * xf
     13        + (-0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3) * xf * xf * xf;
     14}
     15
     16/**
     17 * Two dimensional interpolation within a square grid using polynomials of 3rd degree.
     18 * @param {float} xf - X coordinate relative to p1y of the point to interpolate the value for
     19 * @param {float} yf - y coordinate relative to px1 of the point to interpolate the value for
     20 * @param {float} p00 - Value of the property to calculate at the origin of the neighbor grid
     21 * @param {float} pxy - Value at neighbor grid coordinates x/y, x/y in {0, 1, 2, 3}
     22 * @return {float} - Value at the given float coordinates in the small grid interpolated from it's values
     23 */
     24function bicubicInterpolation
     25(
     26    xf, yf,
     27    p00, p01, p02, p03,
     28    p10, p11, p12, p13,
     29    p20, p21, p22, p23,
     30    p30, p31, p32, p33,
     31    convolution = false
     32)
     33{
     34    return cubicInterpolation(
     35        xf,
     36        cubicInterpolation(yf, p00, p01, p02, p03),
     37        cubicInterpolation(yf, p10, p11, p12, p13),
     38        cubicInterpolation(yf, p20, p21, p22, p23),
     39        cubicInterpolation(yf, p30, p31, p32, p33)
     40    );
     41}
  • binaries/data/mods/public/globalscripts/interpolation.js

  • binaries/data/mods/public/maps/random/rmgen2/gaia.js

    Property changes on: binaries/data/mods/public/globalscripts/interpolation.js
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    13041304                shift.y = - 1;
    13051305
    13061306            let neighbors = [];
    1307             for (let localYi = 0; localYi < 4; ++localYi)
    1308                 for (let localXi = 0; localXi < 4; ++localXi)
     1307            for (let localXi = 0; localXi < 4; ++localXi)
     1308                for (let localYi = 0; localYi < 4; ++localYi)
    13091309                    neighbors.push(heightmap[(hmTile.x + localXi + shift.x - 1) * hmSize + (hmTile.y + localYi + shift.y - 1)]);
    13101310
    13111311            setHeight(x, y, bicubicInterpolation(hmPoint.x - hmTile.x - shift.x, hmPoint.y - hmTile.y - shift.y, ...neighbors) / scale);
  • LICENSE.txt

     
    7979
    8080  /source/tools/atlas
    8181    GPL version 2 (or later) - see license_gpl-2.0.txt
    82 
    83   /binaries/data/mods/public/globalscripts/BicubicInterpolation.js
    84     MIT 2013 Hugh Kennedy - see license_mit.txt