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

31
LINES

< > BotCompany Repo | #1019120 // class DoubleRange - range of doubles (start/end)

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

Libraryless. Click here for Pure Java version (10166L/56K).

final sclass DoubleRange implements Comparable<DoubleRange> {
  gettable double start;
  gettable double end;
  
  *() {}
  *(double *start, double *end) {}
  
  [stdEq]
  
  double length() { ret end-start; }
  bool isEmpty() { ret start >= end; }
  double center() { ret (start+end)/2; }
  
  sS _fieldOrder = "start end";
  
  toString { ret "[" + start + ";" + end + "]"; }
  
  @Override public int compareTo(DoubleRange r) {
    int c = cmp(start, r.start);
    if (c != 0) ret c;
    ret cmp(end, r.end);
  }
  
  bool contains(double d) {
    ret d >= start && d <= end;
  }
  
  DoubleRange sort() {
    ret start > end ? doubleRange(end, start) : this;
  }
}

Author comment

Began life as a copy of #1008631

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019120
Snippet name: class DoubleRange - range of doubles (start/end)
Eternal ID of this version: #1019120/9
Text MD5: a009e097cd785914ac0d4314b5e1cd87
Transpilation MD5: cf631cb8b6baa373462eaa7d93188be6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-03-14 13:26:23
Source code size: 698 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 432 / 1189
Version history: 8 change(s)
Referenced in: [show references]