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

39
LINES

< > BotCompany Repo | #1009184 // class DoubleRect - floating point version of Rectangle

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

Transpiled version (181L) is out of date.

sclass DoubleRect {
  double x, y, w, h;
  
  *() {}
  *(Rectangle r) {
    x = r.x;
    y = r.y;
    w = r.width;
    h = r.height;
  }
  *(double *x, double *y, double *w, double *h) {}
  
  // Huh. not implementing equals()/hashCode? Stefan is mysterious
  bool eq(O o) {
    if (!o instanceof DoubleRect) false;
    if (o == this) true;
    DoubleRect r = cast o;
    ret x == r.x && y == r.y && w == r.w && h == r.h;
  }
  
  toString {
    ret x + "," + y + " / " + w + "," + h;
  }
  
  double x1() { ret x; }
  double y1() { ret y; }
  double x2() { ret x + w; }
  double y2() { ret y + h; }
  
  bool contains(Pt p) {
    ret contains(p.x, p.y);
  }
  
  bool contains(double _x, double _y) {
    ret _x >= x && _y >= y && _x < x+w && _y < y+h;
  }
  
  bool empty() { ret w <= 0 || h <= 0; }
}

Author comment

Began life as a copy of #1005390

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009184
Snippet name: class DoubleRect - floating point version of Rectangle
Eternal ID of this version: #1009184/4
Text MD5: b85c19f028f023781273dc277c160fdb
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-10 17:01:48
Source code size: 841 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 585 / 1216
Version history: 3 change(s)
Referenced in: [show references]