RepliCAD

Форк
0
101 строка · 2.2 Кб
1
import { expect, test } from "vitest";
2
import {
3
  drawRoundedRectangle,
4
  draw,
5
  drawCircle,
6
  drawPolysides,
7
  Drawing,
8
} from "../../src/index";
9

10
const ex1Vertexes = [
11
  [100, 100, -0.5],
12
  [80, 90, 0.374794619217547],
13
  [210, 0, 0],
14
  [230, 0, 1],
15
  [320, 0, -0.5],
16
  [280, 0, 0.5],
17
  [390, 210, 0],
18
  [280, 120, 0.5],
19
];
20

21
const ex2Vertexes = [
22
  [0, 25, 1],
23
  [0, 0, 0],
24
  [2, 0, 1],
25
  [10, 0, -0.5],
26
  [8, 9, 0.374794619217547],
27
  [21, 0, 0],
28
  [23, 0, 1],
29
  [32, 0, -0.5],
30
  [28, 0, 0.5],
31
  [39, 21, 0],
32
  [28, 12, 0],
33
];
34

35
const drawVertexes = (vertexes) => {
36
  const [x0, y0, b0] = vertexes[0];
37
  const d = draw([x0, y0]);
38

39
  let bulge = b0;
40

41
  for (let i = 1; i < vertexes.length; i++) {
42
    const [x, y, b] = vertexes[i];
43
    d.bulgeArcTo([x, y], bulge);
44
    bulge = b;
45
  }
46
  d.bulgeArcTo([x0, y0], bulge);
47
  return d.close();
48
};
49

50
const splineVase = ({
51
  height = 100,
52
  baseWidth = 20,
53
  lowerCircleRadius = 1.5,
54
  lowerCirclPosition = 0.25,
55
  higherCircleRadius = 0.75,
56
  higherCirclePosition = 0.75,
57
  topRadius = 0.9,
58
  bottomHeavy = true,
59
} = {}) => {
60
  const splinesConfig = [
61
    { position: lowerCirclPosition, radius: lowerCircleRadius },
62
    {
63
      position: higherCirclePosition,
64
      radius: higherCircleRadius,
65
      startFactor: bottomHeavy ? 3 : 1,
66
    },
67
    { position: 1, radius: topRadius, startFactor: bottomHeavy ? 3 : 1 },
68
  ];
69

70
  const sketchVaseProfile = draw().hLine(baseWidth);
71

72
  splinesConfig.forEach(({ position, radius, startFactor }) => {
73
    sketchVaseProfile.smoothSplineTo([baseWidth * radius, height * position], {
74
      endTangent: [0, 1],
75
      startFactor,
76
    });
77
  });
78
  return sketchVaseProfile.lineTo([0, height]).closeWithMirror();
79
};
80

81
test.each([-75, -50, -25, -10, -1, 1, 10, 25, 50])(
82
  "offset complex shape 1, with offset %d",
83
  (offsetVal) => {
84
    expect(
85
      drawVertexes(ex1Vertexes).offset(offsetVal).toSVG()
86
    ).toMatchSVGSnapshot();
87
  }
88
);
89

90
test.each([-10, -5, -2, -1, 1, 20])(
91
  "offset complex shape 2, with offset %d",
92
  (offsetVal) => {
93
    expect(
94
      drawVertexes(ex2Vertexes).offset(offsetVal).toSVG()
95
    ).toMatchSVGSnapshot();
96
  }
97
);
98

99
test.each([-1, 1, 5, 10])("offset vase, with offset %d", (offsetVal) => {
100
  expect(splineVase().offset(offsetVal).toSVG()).toMatchSVGSnapshot();
101
});
102

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.