(
imageHeight: number, imageWidth: number,
interpolation: 'nearest'|'bilinear',
fillMode: 'constant'|'reflect'|'wrap'|'nearest', fillValue: number,
outShape: [number, number, number, number])
| 23 | userCode: string; |
| 24 | |
| 25 | constructor( |
| 26 | imageHeight: number, imageWidth: number, |
| 27 | interpolation: 'nearest'|'bilinear', |
| 28 | fillMode: 'constant'|'reflect'|'wrap'|'nearest', fillValue: number, |
| 29 | outShape: [number, number, number, number]) { |
| 30 | this.outputShape = outShape; |
| 31 | const interpolationModeId = interpolation === 'nearest' ? 1 : 2; |
| 32 | let fillModeId; |
| 33 | switch (fillMode) { |
| 34 | case 'constant': |
| 35 | fillModeId = 1; |
| 36 | break; |
| 37 | case 'reflect': |
| 38 | fillModeId = 2; |
| 39 | break; |
| 40 | case 'wrap': |
| 41 | fillModeId = 3; |
| 42 | break; |
| 43 | case 'nearest': |
| 44 | fillModeId = 4; |
| 45 | break; |
| 46 | default: |
| 47 | fillModeId = 1; |
| 48 | break; |
| 49 | } |
| 50 | this.userCode = ` |
| 51 | float mapCoord(float outCoord, float len) { |
| 52 | float inCoord = outCoord; |
| 53 | if(${fillModeId} == 2) { |
| 54 | if (inCoord < 0.0) { |
| 55 | if (len <= 1.0) { |
| 56 | inCoord = 0.0; |
| 57 | } else { |
| 58 | float sz2 = 2.0 * len; |
| 59 | if (inCoord < sz2) { |
| 60 | inCoord = sz2 * float(int(float(-inCoord / sz2))) + |
| 61 | inCoord; |
| 62 | } |
| 63 | inCoord = inCoord < -len ? inCoord + sz2 : -inCoord - 1.0; |
| 64 | } |
| 65 | } else if (inCoord > len - 1.0) { |
| 66 | if (len <= 1.0) { |
| 67 | inCoord = 0.0; |
| 68 | } else { |
| 69 | float sz2 = 2.0 * len; |
| 70 | inCoord -= sz2 * float(int(float(inCoord / sz2))); |
| 71 | if (inCoord >= len) { |
| 72 | inCoord = sz2 - inCoord - 1.0; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | return clamp(inCoord, 0.0, len - 1.0); |
| 77 | } else if (${fillModeId} == 3) { |
| 78 | if (inCoord < 0.0) { |
| 79 | if (len <= 1.0) { |
| 80 | inCoord = 0.0; |
| 81 | } else { |
| 82 | float sz = len - 1.0; |
nothing calls this directly
no outgoing calls
no test coverage detected