Ticket #4218: interpolationSplit2016_9_26.diff
File interpolationSplit2016_9_26.diff, 5.5 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/globalscripts/BicubicInterpolation.js
1 /**2 * From https://github.com/hughsk/bicubic licensed under MIT 2013 Hugh Kennedy - see /license_mit.txt3 * 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 for5 * @param {float} yf - y coordinate within the subgrid (see below) of the point to interpolate the value for6 * @param {float} p00 - Value of the property to calculate at the origin of the naighbor grid7 * @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 values9 */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, p3316 )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 * One dimensional interpolation within four uniformly spaced points using polynomials of 3rd degree. 3 * A uniform Catmull–Rom spline implementation. 4 * @param {float} xf - Float coordinate relative to p1 to interpolate the property for 5 * @param {float} p0 - Value of the property to calculate at the origin of four point scale 6 * @param {float} px - Value at the property of the corresponding point on the scale 7 * @return {float} - Value at the given float position in the 4-point scale interpolated from it's property values 8 */ 9 function cubicInterpolation(xf, p0, p1, p2, p3) 10 { 11 return p1 + 12 (-0.5 * p0 + 0.5 * p2) * xf + 13 (p0 - 2.5 * p1 + 2.0 * p2 - 0.5 * p3) * xf * xf + 14 (-0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3) * xf * xf * xf; 15 } 16 17 /** 18 * Two dimensional interpolation within a square grid using polynomials of 3rd degree. 19 * @param {float} xf - X coordinate relative to p1y of the point to interpolate the value for 20 * @param {float} yf - Y coordinate relative to px1 of the point to interpolate the value for 21 * @param {float} p00 - Value of the property to calculate at the origin of the neighbor grid 22 * @param {float} pxy - Value at neighbor grid coordinates x/y, x/y in {0, 1, 2, 3} 23 * @return {float} - Value at the given float coordinates in the small grid interpolated from it's values 24 */ 25 function bicubicInterpolation 26 ( 27 xf, yf, 28 p00, p01, p02, p03, 29 p10, p11, p12, p13, 30 p20, p21, p22, p23, 31 p30, p31, p32, p33 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
1304 1304 shift.y = - 1; 1305 1305 1306 1306 let neighbors = []; 1307 for (let local Yi = 0; localYi < 4; ++localYi)1308 for (let local Xi = 0; localXi < 4; ++localXi)1307 for (let localXi = 0; localXi < 4; ++localXi) 1308 for (let localYi = 0; localYi < 4; ++localYi) 1309 1309 neighbors.push(heightmap[(hmTile.x + localXi + shift.x - 1) * hmSize + (hmTile.y + localYi + shift.y - 1)]); 1310 1310 1311 1311 setHeight(x, y, bicubicInterpolation(hmPoint.x - hmTile.x - shift.x, hmPoint.y - hmTile.y - shift.y, ...neighbors) / scale); -
LICENSE.txt
79 79 80 80 /source/tools/atlas 81 81 GPL version 2 (or later) - see license_gpl-2.0.txt 82 83 /binaries/data/mods/public/globalscripts/BicubicInterpolation.js84 MIT 2013 Hugh Kennedy - see license_mit.txt