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

39
LINES

< > BotCompany Repo | #1005718 // class Pt - persistable/portable version of Point

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

Libraryless. Click here for Pure Java version (117L/1K).

1  
sclass Pt is Comparable<Pt>, IDoublePt {
2  
  int x, y;
3  
  
4  
  *() {}
5  
  *(Point p) {
6  
    x = p.x;
7  
    y = p.y;
8  
  }
9  
  *(int *x, int *y) {}
10  
  
11  
  Point getPoint() {
12  
    ret new Point(x, y);
13  
  }
14  
  
15  
  public bool equals(O o) {
16  
    ret o instanceof Pt && x == o/Pt.x && y == o/Pt.y;
17  
  }
18  
  
19  
  public int hashCode() {
20  
    ret boostHashCombine(x, y);
21  
  }
22  
  
23  
  // compare in scan order
24  
  public int compareTo(Pt p) {
25  
    if (y != p.y) ret cmp(y, p.y);
26  
    ret cmp(x, p.x);
27  
  }
28  
  
29  
  public S toString() {
30  
    ret x + ", " + y;
31  
  }
32  
  
33  
  double length() { ret sqrt(x*x+y*y); }
34  
  
35  
  public Pt minus(Pt p) { ret ptMinus(this, p); }
36  
  
37  
  public double x_double() { ret x; }
38  
  public double y_double() { ret y; }
39  
}

Author comment

Began life as a copy of #1005390

download  show line numbers  debug dex  old transpilations   

Travelled to 24 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, lulzaavyztxj, mowyntqkapby, mqqgnosmbjvj, odhhsrjjbcgr, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, snaazhdonpnp, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv, xrpafgyirdlv

No comments. add comment

Snippet ID: #1005718
Snippet name: class Pt - persistable/portable version of Point
Eternal ID of this version: #1005718/7
Text MD5: e111cdabf0e954c22739f86033d19c85
Transpilation MD5: 20cf1374bd59751b0b89228794f07617
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-12 22:21:06
Source code size: 730 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 670 / 8186
Version history: 6 change(s)
Referenced in: [show references]