persistable sclass RegularPriceCells is PriceCells { // cell size settable double interval; // one of the cell limits settable double base; *(double *interval) {} *(double *base, double *interval) {} double remainder(double price) { ret mod(price-base, interval); } // TODO: not sure if this logic has rounding problems public bool isCellLimit(double price) { ret remainder(price) == 0; } public double nextCellLimit(double price) { double r = remainder(price); ret price+interval-r; } public double previousCellLimit(double price) { double r = remainder(price); ret price-(r == 0 ? interval : r); } public double nCellLimitsDown(double price, int n) { ret previousCellLimit(price)-(n-1)*interval; } public double nCellLimitsUp(double price, int n) { ret nextCellLimit(price)+n*interval; } public double priceToCellNumber(double price) { ret (price-base)/interval; } public double cellNumberToPrice(double cellNumber) { ret cellNumber*interval+base; } }