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

27
LINES

< > BotCompany Repo | #1036167 // ScaledDiagram

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

Transpiled version (10106L) is out of date.

sclass ScaledDiagram {
  settable int w = 600;
  settable int h = 400;
  settable int horizontalMargin = 10;
  settable int verticalMargin = 10;
  
  settable DoubleRange horizontalRange;
  settable DoubleRange verticalRange;

  // Ranges in pixels that we can paint in (image size minus margins)
  DoubleRange xRange() { ret doubleRange(horizontalMargin, w-horizontalMargin); }
  DoubleRange yRange() { ret doubleRange(h-verticalMargin, verticalMargin); }
  
  double xToScreen(double x) { ret transformBetweenDoubleRanges(x, horizontalRange(), xRange()); }
  double yToScreen(double y) { ret transformBetweenDoubleRanges(y, verticalRange(), yRange()); }
  
  int xToScreen_int(double x) { ret iround(xToScreen(x)); }
  int yToScreen_int(double y) { ret iround(yToScreen(y)); }
  
  double xFromScreen(double x) { ret transformBetweenDoubleRanges(x, xRange(), horizontalRange()); }
  double yFromScreen(double y) { ret transformBetweenDoubleRanges(y, yRange(), verticalRange()); }
  
  public int getWidth() { ret w; }
  public int getHeight() { ret h; }
  
  bool hasScale() { ret horizontalRange != null && verticalRange != null; }
}

Author comment

Began life as a copy of #1036145

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1036167
Snippet name: ScaledDiagram
Eternal ID of this version: #1036167/8
Text MD5: c699daae33bd5cd0fe3da259fb5b543d
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-03-12 18:06:34
Source code size: 1162 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 173 / 252
Version history: 7 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)