Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

76
LINES

< > BotCompany Repo | #1035700 // InterpolatedDoubleArray

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9488L/52K).

1  
persistable sclass InterpolatedDoubleArray is IntSize {
2  
  int[] indices;
3  
  double[] values;
4  
  
5  
  *(int[] *indices, double[] *values) {}
6  
  
7  
  public int size aka length() {
8  
    ret empty(indices) ? 0 : last(indices)+1;
9  
  }
10  
  
11  
  int nPillars() {
12  
    ret l(indices);
13  
  }
14  
  
15  
  double[] toDoubleArray aka get() {
16  
    int n = length();
17  
    double[] array = new[n];
18  
    for (int i = 0; i < indices.length; i++) {
19  
      int iEnd = indices[i];
20  
      double value = values[i];
21  
      array[iEnd] = value;
22  
      if (i > 0) {
23  
        int iStart = indices[i-1];
24  
        if (iStart+1 < iEnd) {
25  
          double startValue = values[i-1];
26  
          double step = (value-startValue)/(iEnd-iStart), val = startValue;
27  
          for (int j = iStart+1; j < iEnd; j++) {
28  
            val += step;
29  
            array[j] = val;
30  
          }
31  
        }
32  
      }
33  
    }
34  
    ret array;
35  
  }
36  
  
37  
  int[] rounded() {
38  
    ret iroundDoubleArray(get());
39  
  }
40  
  
41  
  double[] indicesAndValues() {
42  
    int n = nPillars();
43  
    double[] array = new[n*2];
44  
    for i to n: {
45  
      array[i*2] = indices[i];
46  
      array[i*2+1] = values[i];
47  
    }
48  
    ret array;
49  
  }
50  
  
51  
  double[] indicesAndValues_withoutFirstAndLastIndex() {
52  
    int n = nPillars();
53  
    double[] array = new[max(1, n*2-2)];
54  
    int j = 0;
55  
    for i to n: {
56  
      if (i != 0 && i != n-1)
57  
        array[j++] = indices[i];
58  
      array[j++] = values[i];
59  
    }
60  
    ret array;
61  
  }
62  
  
63  
  int nInts_withoutFirstAndLastIndex() {
64  
    ret max(1, nPillars()*2-2);
65  
  }
66  
  
67  
  int nInts() {
68  
    ret nPillars()*2;
69  
  }
70  
  
71  
  InterpolatedDoubleArray topPart(int nPillars) {
72  
    ret new InterpolatedDoubleArray(
73  
      takeFirst(nPillars, indices),
74  
      takeFirst(nPillars, values));
75  
  }
76  
}

Author comment

Began life as a copy of #1035699

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035700
Snippet name: InterpolatedDoubleArray
Eternal ID of this version: #1035700/15
Text MD5: 2e335225d6c7b3da4423cf3f06d5c65c
Transpilation MD5: bbefca06f04cd980f9035895afee5360
Author: stefan
Category: javax / geometric compression
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-07-25 14:37:20
Source code size: 1758 bytes / 76 lines
Pitched / IR pitched: No / No
Views / Downloads: 101 / 210
Version history: 14 change(s)
Referenced in: [show references]