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

59
LINES

< > BotCompany Repo | #1035702 // CompressToInterpolatedDoubleArray

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

Transpiled version (13569L) is out of date.

1  
sclass CompressToInterpolatedDoubleArray {
2  
  // raw data to compress (integers)
3  
  int[] data;
4  
  
5  
  // output
6  
  InterpolatedDoubleArray result;
7  
  
8  
  // options
9  
  settable double slopeTolerance = 0.01;
10  
  
11  
  // internal
12  
  new IntBuffer indices;
13  
  new DoubleBuffer values;
14  
  
15  
  *(int[] *data) {}
16  
  
17  
  InterpolatedDoubleArray get() {
18  
    int iData = 0;
19  
    while (iData < data.length) {
20  
      int startValue = data[iData];
21  
      // possible range of actual floating point starting value
22  
      DoubleRange startValueRange = doubleRange(startValue-0.5, startValue+0.5);
23  
      
24  
      // see how far the straight line goes from iData
25  
      DoubleRange totalSlopeRange = null;
26  
      int jData; // our straight line ends at jData-1
27  
      for (jData = iData+1; jData < data.length; jData++) {
28  
        double x = data[jData], h = jData-iData;
29  
        
30  
        // possible range of actual floating point value
31  
        DoubleRange xRange = doubleRange(x-0.5, x+0.5);
32  
        
33  
        // most generous range for possible slope depending
34  
        // on possible floating point values at start and end
35  
        DoubleRange slopeRange = doubleRange(
36  
          (xRange.start-startValueRange.end)/h,
37  
          (xRange.end-startValueRange.start)/h);
38  
        
39  
        // grow range a little to avoid size 0 ranges
40  
        slopeRange = growRange(slopeTolerance, slopeRange);
41  
        //printVars(+iData, +jData, +slopeRange, +totalSlopeRange);
42  
        if (totalSlopeRange == null)
43  
          totalSlopeRange = slopeRange;
44  
        else {
45  
          slopeRange = intersectRanges(slopeRange, totalSlopeRange);
46  
          if (empty(slopeRange))
47  
            break;
48  
          else
49  
            totalSlopeRange = slopeRange;
50  
        }
51  
      }
52  
      indices.add(iData);
53  
      values.add(data[iData]);
54  
      iData = max(iData+1, jData-1);
55  
    }
56  
    
57  
    ret result = new InterpolatedDoubleArray(indices.toArrayNonNull(), values.toArrayNonNull());
58  
  }
59  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1035702
Snippet name: CompressToInterpolatedDoubleArray
Eternal ID of this version: #1035702/12
Text MD5: f3d50df57f486f8da9f9d281831aa712
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-11 23:01:01
Source code size: 1970 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 98 / 168
Version history: 11 change(s)
Referenced in: [show references]