geosolutions-it / jai-ext

Java Advanced Imaging Open Source Replacement Wannabe
Apache License 2.0
89 stars 38 forks source link

Implementations of Range.union misleading #276

Open ulrichloup opened 3 years ago

ulrichloup commented 3 years ago

The method Range.union(Range) in the package it.geosolutions.jaiext.range suggests that the resulting range represents the set-theoretic union of the two involved ranges. However, the concrete implementations, e.g. in RangeDouble do only return the smallest gapless range containing the union.

Did I miss a hint in the documentation on how unions of ranges are to be interpreted? Otherwise, I suggest to extend the implementations of the class Range to support also gaps, e.g., by introducing another container class for sets of ranges. A clue in the documentation or renaming the method union would also solve this problem.

Example Valid data is between 0 and 100, no-data values are the values from -9999 to 0 and from 100 to 9999 where 0 and 100 are excluded.

Range r1 = RangeFactory.create(-9999, true, 0, false);
Range r2 = RangeFactory.create(100, false, 9999, true);
Range r = r1.union(r2);

The resulting no-data range, however, is RangeInt[-9999, 9999], thus, covering also the valid data.