view.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { iso, type Flat, type Plan, type Point3, type Projection } from "../../kit/iso-kit";
  2. export const WIDTH = 600;
  3. export const HEIGHT = 340;
  4. const PAD = 34;
  5. export const AZIMUTH = 57;
  6. export const BASE: Plan = { x: -134, y: -82, w: 298, d: 150, r: 9 };
  7. export const BASE_H = 9;
  8. export const FOOT_H = 5;
  9. export const FRAME_X = 101;
  10. export const FRAME_Y = 37;
  11. export const BAR = 9;
  12. export const BAR_H = 12;
  13. export const ROD_Y = 18;
  14. export const ROD_Z = 6;
  15. export const ROD_HALF = 2;
  16. export const COIL_R = 4.2;
  17. export const COIL_TURNS = 6;
  18. export const CARRIAGE: Plan = { x: -72, y: -26, w: 144, d: 52, r: 4 };
  19. export const CARRIAGE_Z = 3;
  20. export const CARRIAGE_H = 5;
  21. export const CARRIAGE_TOP = CARRIAGE_Z + CARRIAGE_H;
  22. export const BUSH_END = 80;
  23. export const BUSH_W = 14;
  24. export const BUSH_D = 12;
  25. export const GLASS_Z = CARRIAGE_TOP;
  26. export const GLASS_H = 10;
  27. export const GLASS_TOP = GLASS_Z + GLASS_H;
  28. export const PLUNGER_Z = 6;
  29. export const DIAL: Flat = [131, 0];
  30. export const DIAL_R = 15;
  31. export const DIAL_Z = 3;
  32. export const DIAL_H = 8;
  33. export const DIAL_TOP = DIAL_Z + DIAL_H;
  34. export const DIAL_SPAN = 20;
  35. export const RAIL_Y = -66;
  36. export const RAIL_D = 8;
  37. export const RAIL_Z = 50;
  38. export const RAIL_H = 8;
  39. export const POST_L = -124;
  40. export const POST_R = 66;
  41. export const POST = 12;
  42. export const PROBE_HOME = 45;
  43. export const PROBE_MIN = -98;
  44. export const PROBE_MAX = 48;
  45. export const HOUSING_R = 5.5;
  46. export const HOUSING_Z = 44;
  47. export const HOUSING_H = 20;
  48. export const PAD_R = 4.4;
  49. export const PAD_H = 3;
  50. export const HOVER = 12;
  51. export const STEM = 28;
  52. export const GRAB_MOST = 52;
  53. export const FINGER_MOST = 62;
  54. function fit(points: Point3[]): Projection {
  55. const unit: Projection = { origin: [0, 0], scale: 1, azimuth: AZIMUTH };
  56. const flat = points.map((point) => iso(point, unit));
  57. const xs = flat.map(([x]) => x);
  58. const ys = flat.map(([, y]) => y);
  59. const left = Math.min(...xs);
  60. const right = Math.max(...xs);
  61. const up = Math.min(...ys);
  62. const down = Math.max(...ys);
  63. const scale = Math.min((WIDTH - PAD * 2) / (right - left), (HEIGHT - PAD * 2) / (down - up));
  64. return { origin: [WIDTH / 2 - ((left + right) / 2) * scale, HEIGHT / 2 - ((up + down) / 2) * scale], scale, azimuth: AZIMUTH };
  65. }
  66. const corners = ({ x, y, w, d }: Plan, z0: number, z1: number): Point3[] => {
  67. const out: Point3[] = [];
  68. for (const px of [x, x + w]) for (const py of [y, y + d]) for (const z of [z0, z1]) out.push([px, py, z]);
  69. return out;
  70. };
  71. export const P = fit([
  72. ...corners(BASE, -BASE_H - FOOT_H, 0),
  73. ...corners({ x: POST_L, y: RAIL_Y - RAIL_D / 2, w: POST_R + POST - POST_L, d: RAIL_D, r: 0 }, RAIL_Z, RAIL_Z + RAIL_H + 6),
  74. ]);
  75. export const at = (point: Point3) => iso(point, P);
  76. const ORIGIN = at([0, 0, 0]);
  77. const minus = (a: Flat, b: Flat): Flat => [a[0] - b[0], a[1] - b[1]];
  78. export const EX = minus(at([1, 0, 0]), ORIGIN);
  79. export const EZ = minus(at([0, 0, 1]), ORIGIN);
  80. const fine = (value: number) => Math.round(value * 100) / 100;
  81. export const shift = (x: number, z = 0) => `translate(${fine(EX[0] * x + EZ[0] * z)} ${fine(EX[1] * x + EZ[1] * z)})`;