geometrix 0.5.10 → 0.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +505 -0
- package/dist/index.js +3848 -0
- package/package.json +7 -1
- package/.eslintignore +0 -17
- package/.eslintrc.cjs +0 -24
- package/.prettierignore +0 -15
- package/.prettierrc +0 -8
- package/src/aaExportContent.ts +0 -213
- package/src/aaExportFile.ts +0 -141
- package/src/aaParamGeom.ts +0 -62
- package/src/angle_utils.test.ts +0 -83
- package/src/angle_utils.ts +0 -98
- package/src/arc_to_stroke.ts +0 -73
- package/src/canvas_utils.test.ts +0 -28
- package/src/canvas_utils.ts +0 -159
- package/src/contour.test.ts +0 -37
- package/src/contour.ts +0 -806
- package/src/designParams.ts +0 -178
- package/src/figure.test.ts +0 -21
- package/src/figure.ts +0 -400
- package/src/index.ts +0 -16
- package/src/line.test.ts +0 -78
- package/src/line.ts +0 -359
- package/src/paramFile.ts +0 -52
- package/src/point.test.ts +0 -36
- package/src/point.ts +0 -246
- package/src/prepare_pax.ts +0 -102
- package/src/segment.test.ts +0 -26
- package/src/segment.ts +0 -701
- package/src/sub_design.ts +0 -16
- package/src/triangle_utils.test.ts +0 -38
- package/src/triangle_utils.ts +0 -112
- package/src/vector.test.ts +0 -28
- package/src/vector.ts +0 -122
- package/src/volume.ts +0 -50
- package/src/write_dxf.ts +0 -100
- package/src/write_openjscad.ts +0 -284
- package/src/write_openscad.ts +0 -305
- package/src/write_pax.ts +0 -73
- package/src/write_svg.ts +0 -101
- package/svg/any_triangle.svg +0 -156
- package/svg/arc_definition.svg +0 -506
- package/svg/construct_corner_rounded_ext_arc_ext_arc.svg +0 -378
- package/svg/construct_corner_rounded_int_arc_ext_arc.svg +0 -359
- package/svg/construct_corner_rounded_int_arc_int_arc.svg +0 -356
- package/svg/construct_corner_rounded_stroke_ext_arc.svg +0 -374
- package/svg/construct_corner_rounded_stroke_ext_arc_obtuse.svg +0 -370
- package/svg/construct_corner_rounded_stroke_ext_arc_obtuse_method2.svg +0 -311
- package/svg/construct_corner_rounded_stroke_int_arc.svg +0 -364
- package/svg/construct_corner_rounded_stroke_int_arc_obtuse.svg +0 -358
- package/svg/construct_corner_rounded_stroke_int_arc_obtuse_method2.svg +0 -237
- package/svg/construct_corner_rounded_stroke_stroke.svg +0 -280
- package/svg/construct_corner_wideacc.svg +0 -286
- package/svg/construct_corner_widened.svg +0 -278
- package/svg/construction_of_line_intersection_1.svg +0 -187
- package/svg/construction_of_line_intersection_2.svg +0 -189
- package/svg/contour_arc_definition_options.svg +0 -324
- package/svg/contour_point_absolute_relative.svg +0 -258
- package/svg/contour_tangential_two_arcs.svg +0 -531
- package/svg/contour_tangential_two_arcs_impossible_case.svg +0 -175
- package/svg/contour_tangential_two_arcs_requirements.svg +0 -364
- package/svg/corner_rounded_ext_arc_ext_arc.svg +0 -281
- package/svg/corner_rounded_int_arc_ext_arc.svg +0 -281
- package/svg/corner_rounded_int_arc_int_arc.svg +0 -279
- package/svg/corner_rounded_stroke_ext_arc.svg +0 -218
- package/svg/corner_rounded_stroke_int_arc.svg +0 -225
- package/svg/corner_rounded_stroke_stroke.svg +0 -174
- package/svg/geom_dev.svg +0 -14708
- package/svg/geom_modules.svg +0 -246
- package/svg/geom_user.svg +0 -58
- package/svg/line_axis_x_cases.svg +0 -1408
- package/svg/line_axis_y_cases.svg +0 -1369
- package/svg/line_distanceOrig.svg +0 -318
- package/svg/line_getAxisXIntersection.svg +0 -262
- package/svg/line_getAxisXIntersection_2.svg +0 -244
- package/svg/line_getAxisYIntersection.svg +0 -304
- package/svg/line_getAxisYIntersection_2.svg +0 -285
- package/svg/line_getAxisYIntersection_3.svg +0 -277
- package/svg/line_intersection.svg +0 -346
- package/svg/line_projectPoint.svg +0 -311
- package/svg/point_1.svg +0 -243
- package/svg/point_2.svg +0 -409
- package/svg/point_3.svg +0 -298
- package/svg/point_4.svg +0 -272
- package/svg/point_5.svg +0 -356
- package/svg/right_triangle.svg +0 -194
- package/svg/vector_definition.svg +0 -130
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -7
package/src/designParams.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
// designParams
|
|
2
|
-
|
|
3
|
-
enum PType {
|
|
4
|
-
eNumber,
|
|
5
|
-
eCheckbox,
|
|
6
|
-
eDropdown
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface tParam {
|
|
10
|
-
name: string;
|
|
11
|
-
unit: string;
|
|
12
|
-
init: number;
|
|
13
|
-
min: number;
|
|
14
|
-
max: number;
|
|
15
|
-
step: number;
|
|
16
|
-
dropdown: string[];
|
|
17
|
-
pType: PType;
|
|
18
|
-
}
|
|
19
|
-
interface tSimTime {
|
|
20
|
-
tMax: number;
|
|
21
|
-
tStep: number;
|
|
22
|
-
tUpdate: number; // in ms
|
|
23
|
-
}
|
|
24
|
-
interface tParamDef {
|
|
25
|
-
partName: string;
|
|
26
|
-
params: tParam[];
|
|
27
|
-
paramSvg: Record<string, string>;
|
|
28
|
-
sim: tSimTime;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type tParamVal = Record<string, number>;
|
|
32
|
-
type tParamChanged = Record<string, boolean>;
|
|
33
|
-
|
|
34
|
-
interface tDesignParamOne {
|
|
35
|
-
val: number;
|
|
36
|
-
init: number;
|
|
37
|
-
chg: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function oneDesignParam(iVal: number, iInit: number, iChg: boolean): tDesignParamOne {
|
|
41
|
-
const oneDP: tDesignParamOne = { val: iVal, init: iInit, chg: iChg };
|
|
42
|
-
return oneDP;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
type tDesignParamList = Record<string, tDesignParamOne>;
|
|
46
|
-
|
|
47
|
-
function paramListToVal(dpList: tDesignParamList): tParamVal {
|
|
48
|
-
const rParamVal: tParamVal = {};
|
|
49
|
-
for (const pa of Object.keys(dpList)) {
|
|
50
|
-
rParamVal[pa] = dpList[pa].val;
|
|
51
|
-
}
|
|
52
|
-
return rParamVal;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
class DesignParam {
|
|
56
|
-
paramVal: tParamVal = {};
|
|
57
|
-
paramInit: tParamVal = {};
|
|
58
|
-
paramChanged: tParamChanged = {};
|
|
59
|
-
partName: string;
|
|
60
|
-
paramNames: string[];
|
|
61
|
-
getParamName(): string[] {
|
|
62
|
-
const rNames: string[] = [];
|
|
63
|
-
for (const pName of Object.keys(this.paramVal)) {
|
|
64
|
-
rNames.push(pName);
|
|
65
|
-
}
|
|
66
|
-
return rNames;
|
|
67
|
-
}
|
|
68
|
-
constructor(iparamDef: tParamDef) {
|
|
69
|
-
for (const pi of iparamDef.params) {
|
|
70
|
-
this.paramVal[pi.name] = pi.init;
|
|
71
|
-
this.paramInit[pi.name] = pi.init;
|
|
72
|
-
this.paramChanged[pi.name] = false;
|
|
73
|
-
}
|
|
74
|
-
this.partName = iparamDef.partName;
|
|
75
|
-
this.paramNames = this.getParamName();
|
|
76
|
-
}
|
|
77
|
-
getPartName(): string {
|
|
78
|
-
return this.partName;
|
|
79
|
-
}
|
|
80
|
-
getParamVal(): tParamVal {
|
|
81
|
-
return this.paramVal;
|
|
82
|
-
}
|
|
83
|
-
getVal(iname: string): number {
|
|
84
|
-
if (this.paramNames.includes(iname)) {
|
|
85
|
-
return this.paramVal[iname];
|
|
86
|
-
} else {
|
|
87
|
-
throw `err140: parameter ${iname} does not exist in design ${this.partName}`;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
getInit(iname: string): number {
|
|
91
|
-
if (this.paramNames.includes(iname)) {
|
|
92
|
-
return this.paramInit[iname];
|
|
93
|
-
} else {
|
|
94
|
-
throw `err149: parameter ${iname} does not exist in design ${this.partName}`;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
getChanged(iname: string): boolean {
|
|
98
|
-
if (this.paramNames.includes(iname)) {
|
|
99
|
-
return this.paramChanged[iname];
|
|
100
|
-
} else {
|
|
101
|
-
throw `err156: parameter ${iname} does not exist in design ${this.partName}`;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
setVal(iname: string, ival: number) {
|
|
105
|
-
if (this.paramNames.includes(iname)) {
|
|
106
|
-
this.paramVal[iname] = ival;
|
|
107
|
-
this.paramChanged[iname] = true;
|
|
108
|
-
} else {
|
|
109
|
-
throw `err163: parameter ${iname} does not exist in design ${this.partName}`;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
applyParamVal(iValues: tParamVal): string {
|
|
113
|
-
let rlog = '';
|
|
114
|
-
for (const pa of Object.keys(iValues)) {
|
|
115
|
-
this.setVal(pa, iValues[pa]);
|
|
116
|
-
}
|
|
117
|
-
rlog += `info104: apply ${Object.keys(iValues).length} parameters on ${this.partName}\n`;
|
|
118
|
-
return rlog;
|
|
119
|
-
}
|
|
120
|
-
applyParamList(iValues: tDesignParamList): string {
|
|
121
|
-
const rlog = this.applyParamVal(paramListToVal(iValues));
|
|
122
|
-
return rlog;
|
|
123
|
-
}
|
|
124
|
-
getDesignParamList(): tDesignParamList {
|
|
125
|
-
const rDPList: tDesignParamList = {};
|
|
126
|
-
for (const pi of this.paramNames) {
|
|
127
|
-
rDPList[pi] = oneDesignParam(this.getVal(pi), this.getInit(pi), this.getChanged(pi));
|
|
128
|
-
}
|
|
129
|
-
return rDPList;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function designParam(iparamDef: tParamDef): DesignParam {
|
|
134
|
-
return new DesignParam(iparamDef);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function pNumber(name: string, unit: string, init: number, min = 0, max = 100, step = 1): tParam {
|
|
138
|
-
const rParam: tParam = {
|
|
139
|
-
name: name,
|
|
140
|
-
unit: unit,
|
|
141
|
-
init: init,
|
|
142
|
-
min: min,
|
|
143
|
-
max: max,
|
|
144
|
-
step: step,
|
|
145
|
-
dropdown: [],
|
|
146
|
-
pType: PType.eNumber
|
|
147
|
-
};
|
|
148
|
-
return rParam;
|
|
149
|
-
}
|
|
150
|
-
function pCheckbox(name: string, init: boolean): tParam {
|
|
151
|
-
const rParam: tParam = {
|
|
152
|
-
name: name,
|
|
153
|
-
unit: 'checkbox',
|
|
154
|
-
init: init ? 1 : 0,
|
|
155
|
-
min: 0,
|
|
156
|
-
max: 1,
|
|
157
|
-
step: 1,
|
|
158
|
-
dropdown: [],
|
|
159
|
-
pType: PType.eCheckbox
|
|
160
|
-
};
|
|
161
|
-
return rParam;
|
|
162
|
-
}
|
|
163
|
-
function pDropdown(name: string, values: string[]): tParam {
|
|
164
|
-
const rParam: tParam = {
|
|
165
|
-
name: name,
|
|
166
|
-
unit: 'dropdown',
|
|
167
|
-
init: 0,
|
|
168
|
-
min: 0,
|
|
169
|
-
max: values.length - 1,
|
|
170
|
-
step: 1,
|
|
171
|
-
dropdown: values,
|
|
172
|
-
pType: PType.eDropdown
|
|
173
|
-
};
|
|
174
|
-
return rParam;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export type { tParamDef, tParamVal, tDesignParamList, DesignParam };
|
|
178
|
-
export { PType, pNumber, pCheckbox, pDropdown, designParam, paramListToVal, oneDesignParam };
|
package/src/figure.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { degToRad, radToDeg, roundZero, point } from './figure';
|
|
3
|
-
|
|
4
|
-
describe('angle suit', () => {
|
|
5
|
-
it('radian to degree', () => {
|
|
6
|
-
expect(roundZero(radToDeg(Math.PI / 3) - 60)).toBe(0);
|
|
7
|
-
});
|
|
8
|
-
it('degree to radian', () => {
|
|
9
|
-
expect(roundZero(degToRad(45) - Math.PI / 4)).toBe(0);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('point suit', () => {
|
|
14
|
-
it('coordinate cartesian to polar', () => {
|
|
15
|
-
const cpolar = point(2, 2).getPolar();
|
|
16
|
-
expect([
|
|
17
|
-
roundZero(cpolar[0] - Math.PI / 4),
|
|
18
|
-
roundZero(cpolar[1] - Math.sqrt(8))
|
|
19
|
-
]).toStrictEqual([0, 0]);
|
|
20
|
-
});
|
|
21
|
-
});
|
package/src/figure.ts
DELETED
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
// figure.ts
|
|
2
|
-
// a minimalistic 2D euclid geometry calculation library
|
|
3
|
-
// figure.ts deals with points, lines, vectors, contours
|
|
4
|
-
// figure.ts gather all other modules of geom
|
|
5
|
-
|
|
6
|
-
import type { tCanvasAdjust } from './canvas_utils';
|
|
7
|
-
//import { colorCanvasPoint } from '$lib/style/colors.scss';
|
|
8
|
-
import { colors, adjustZero, adjustInit } from './canvas_utils';
|
|
9
|
-
import { withinZero2Pi, withinPiPi, degToRad, radToDeg, roundZero, ffix } from './angle_utils';
|
|
10
|
-
import { lcFromLaLbAc, aCFromLaLbLc, lbFromLaAaAb, aBFromLaLbAa } from './triangle_utils';
|
|
11
|
-
import { ShapePoint, Point, point, pointMinMax } from './point';
|
|
12
|
-
import { Line, line, linePP, bisector, circleCenter } from './line';
|
|
13
|
-
import { Vector, vector } from './vector';
|
|
14
|
-
import type { tContour } from './contour';
|
|
15
|
-
import { contour, contourCircle } from './contour';
|
|
16
|
-
|
|
17
|
-
interface tLayers {
|
|
18
|
-
points: boolean;
|
|
19
|
-
lines: boolean;
|
|
20
|
-
vectors: boolean;
|
|
21
|
-
main: boolean;
|
|
22
|
-
mainB: boolean;
|
|
23
|
-
second: boolean;
|
|
24
|
-
secondB: boolean;
|
|
25
|
-
dynamics: boolean;
|
|
26
|
-
ruler: boolean;
|
|
27
|
-
refframe: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
class Figure {
|
|
31
|
-
pointList: Point[];
|
|
32
|
-
lineList: Line[];
|
|
33
|
-
vectorList: Vector[];
|
|
34
|
-
mainList: tContour[];
|
|
35
|
-
mainBList: tContour[];
|
|
36
|
-
secondList: tContour[];
|
|
37
|
-
secondBList: tContour[];
|
|
38
|
-
dynamicsList: tContour[];
|
|
39
|
-
xMin: number;
|
|
40
|
-
xMax: number;
|
|
41
|
-
yMin: number;
|
|
42
|
-
yMax: number;
|
|
43
|
-
constructor() {
|
|
44
|
-
this.pointList = [];
|
|
45
|
-
this.lineList = [];
|
|
46
|
-
this.vectorList = [];
|
|
47
|
-
this.mainList = [];
|
|
48
|
-
this.mainBList = [];
|
|
49
|
-
this.secondList = [];
|
|
50
|
-
this.secondBList = [];
|
|
51
|
-
this.dynamicsList = [];
|
|
52
|
-
this.xMin = 0;
|
|
53
|
-
this.xMax = 0;
|
|
54
|
-
this.yMin = 0;
|
|
55
|
-
this.yMax = 0;
|
|
56
|
-
}
|
|
57
|
-
addPoint(ipoint: Point) {
|
|
58
|
-
this.pointList.push(ipoint);
|
|
59
|
-
}
|
|
60
|
-
addPoints(ipoints: Point[]) {
|
|
61
|
-
//for (const ipt of ipoints) {
|
|
62
|
-
// this.pointList.push(ipt);
|
|
63
|
-
//}
|
|
64
|
-
this.pointList.push(...ipoints);
|
|
65
|
-
}
|
|
66
|
-
addLine(iline: Line) {
|
|
67
|
-
this.lineList.push(iline);
|
|
68
|
-
}
|
|
69
|
-
addLines(ilines: Line[]) {
|
|
70
|
-
for (const iline of ilines) {
|
|
71
|
-
this.lineList.push(iline);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
addVector(ivector: Vector) {
|
|
75
|
-
this.vectorList.push(ivector);
|
|
76
|
-
}
|
|
77
|
-
addMain(icontour: tContour) {
|
|
78
|
-
const roundedContour = icontour.generateContour();
|
|
79
|
-
this.addPoints(roundedContour.generatePoints());
|
|
80
|
-
//this.addPoints(icontour.generatePoints()); // points of the skeleton
|
|
81
|
-
this.addLines(roundedContour.generateLines());
|
|
82
|
-
this.mainList.push(roundedContour);
|
|
83
|
-
this.mainBList.push(icontour.extractSkeleton());
|
|
84
|
-
}
|
|
85
|
-
addSecond(icontour: tContour) {
|
|
86
|
-
const roundedContour = icontour.generateContour();
|
|
87
|
-
this.addPoints(roundedContour.generatePoints());
|
|
88
|
-
//this.addPoints(icontour.generatePoints()); // points of the skeleton
|
|
89
|
-
this.addLines(roundedContour.generateLines());
|
|
90
|
-
this.secondList.push(roundedContour);
|
|
91
|
-
this.secondBList.push(icontour.extractSkeleton());
|
|
92
|
-
}
|
|
93
|
-
addDynamics(icontour: tContour) {
|
|
94
|
-
this.addPoints(icontour.generatePoints());
|
|
95
|
-
this.addLines(icontour.generateLines());
|
|
96
|
-
this.dynamicsList.push(icontour);
|
|
97
|
-
}
|
|
98
|
-
translate(ix: number, iy: number): Figure {
|
|
99
|
-
const rfig = new Figure();
|
|
100
|
-
for (const pt of this.pointList) {
|
|
101
|
-
rfig.addPoint(pt.translate(ix, iy));
|
|
102
|
-
}
|
|
103
|
-
for (const li of this.lineList) {
|
|
104
|
-
rfig.addLine(li.translate(ix, iy));
|
|
105
|
-
}
|
|
106
|
-
for (const vec of this.vectorList) {
|
|
107
|
-
rfig.addVector(vec.translate(ix, iy));
|
|
108
|
-
}
|
|
109
|
-
for (const ctr of this.mainList) {
|
|
110
|
-
rfig.addMain(ctr.translate(ix, iy));
|
|
111
|
-
}
|
|
112
|
-
for (const ctr of this.secondList) {
|
|
113
|
-
rfig.addSecond(ctr.translate(ix, iy));
|
|
114
|
-
}
|
|
115
|
-
for (const ctr of this.dynamicsList) {
|
|
116
|
-
rfig.addDynamics(ctr.translate(ix, iy));
|
|
117
|
-
}
|
|
118
|
-
return rfig;
|
|
119
|
-
}
|
|
120
|
-
translatePolar(ia: number, il: number): Figure {
|
|
121
|
-
return this.translate(il * Math.cos(ia), il * Math.sin(ia));
|
|
122
|
-
}
|
|
123
|
-
rotate(ix: number, iy: number, ia: number): Figure {
|
|
124
|
-
const rfig = new Figure();
|
|
125
|
-
const pt0 = point(ix, iy);
|
|
126
|
-
for (const pt of this.pointList) {
|
|
127
|
-
rfig.addPoint(pt.rotate(pt0, ia));
|
|
128
|
-
}
|
|
129
|
-
for (const li of this.lineList) {
|
|
130
|
-
rfig.addLine(li.rotate(pt0, ia));
|
|
131
|
-
}
|
|
132
|
-
for (const vec of this.vectorList) {
|
|
133
|
-
rfig.addVector(vec.rotate(pt0, ia));
|
|
134
|
-
}
|
|
135
|
-
for (const ctr of this.mainList) {
|
|
136
|
-
rfig.addMain(ctr.rotate(ix, iy, ia));
|
|
137
|
-
}
|
|
138
|
-
for (const ctr of this.secondList) {
|
|
139
|
-
rfig.addSecond(ctr.rotate(ix, iy, ia));
|
|
140
|
-
}
|
|
141
|
-
for (const ctr of this.dynamicsList) {
|
|
142
|
-
rfig.addDynamics(ctr.rotate(ix, iy, ia));
|
|
143
|
-
}
|
|
144
|
-
return rfig;
|
|
145
|
-
}
|
|
146
|
-
mergeFigure(ifig: Figure, mainToSecond = false) {
|
|
147
|
-
for (const pt of ifig.pointList) {
|
|
148
|
-
this.addPoint(pt.clone());
|
|
149
|
-
}
|
|
150
|
-
for (const li of ifig.lineList) {
|
|
151
|
-
this.addLine(li.clone());
|
|
152
|
-
}
|
|
153
|
-
for (const vec of ifig.vectorList) {
|
|
154
|
-
this.addVector(vec.clone());
|
|
155
|
-
}
|
|
156
|
-
for (const ctr of ifig.mainList) {
|
|
157
|
-
if (mainToSecond) {
|
|
158
|
-
this.addSecond(ctr.clone());
|
|
159
|
-
} else {
|
|
160
|
-
this.addMain(ctr.clone());
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
for (const ctr of ifig.secondList) {
|
|
164
|
-
this.addSecond(ctr.clone());
|
|
165
|
-
}
|
|
166
|
-
for (const ctr of ifig.dynamicsList) {
|
|
167
|
-
this.addDynamics(ctr.clone());
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
clear() {
|
|
171
|
-
this.pointList = [];
|
|
172
|
-
this.lineList = [];
|
|
173
|
-
this.vectorList = [];
|
|
174
|
-
this.mainList = [];
|
|
175
|
-
this.mainBList = [];
|
|
176
|
-
this.secondList = [];
|
|
177
|
-
this.secondBList = [];
|
|
178
|
-
this.dynamicsList = [];
|
|
179
|
-
}
|
|
180
|
-
getMinMax() {
|
|
181
|
-
[this.xMin, this.xMax, this.yMin, this.yMax] = pointMinMax(this.pointList);
|
|
182
|
-
//console.log(`dbg137: ${this.xMin}, ${this.xMax}, ${this.yMin}, ${this.yMax}`);
|
|
183
|
-
}
|
|
184
|
-
getAdjustFull(iCanvasWidth: number, iCanvasHeight: number): tCanvasAdjust {
|
|
185
|
-
//console.log(`dbg140: ${iCanvasWidth}, ${iCanvasHeight}`);
|
|
186
|
-
let rCanvasAdjust: tCanvasAdjust = adjustZero();
|
|
187
|
-
if (this.pointList.length > 0) {
|
|
188
|
-
this.getMinMax();
|
|
189
|
-
rCanvasAdjust = adjustInit(
|
|
190
|
-
this.xMin,
|
|
191
|
-
this.xMax,
|
|
192
|
-
this.yMin,
|
|
193
|
-
this.yMax,
|
|
194
|
-
iCanvasWidth,
|
|
195
|
-
iCanvasHeight
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
//console.log(`dbg150: ${rCanvasAdjust.shiftX}, ${rCanvasAdjust.scaleX}`);
|
|
199
|
-
return rCanvasAdjust;
|
|
200
|
-
}
|
|
201
|
-
getAdjustZoom(iCanvasWidth: number, iCanvasHeight: number): tCanvasAdjust {
|
|
202
|
-
//console.log(`dbg140: ${iCanvasWidth}, ${iCanvasHeight}`);
|
|
203
|
-
let rCanvasAdjust: tCanvasAdjust = adjustZero();
|
|
204
|
-
if (this.pointList.length > 0) {
|
|
205
|
-
this.getMinMax();
|
|
206
|
-
const xMin = (this.xMin + this.xMax) / 2;
|
|
207
|
-
const yMin = (this.yMin + this.yMax) / 2;
|
|
208
|
-
rCanvasAdjust = adjustInit(
|
|
209
|
-
xMin,
|
|
210
|
-
this.xMax,
|
|
211
|
-
yMin,
|
|
212
|
-
this.yMax,
|
|
213
|
-
iCanvasWidth,
|
|
214
|
-
iCanvasHeight
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
//console.log(`dbg150: ${rCanvasAdjust.shiftX}, ${rCanvasAdjust.scaleX}`);
|
|
218
|
-
return rCanvasAdjust;
|
|
219
|
-
}
|
|
220
|
-
quantifyRuler(canvasWidth: number, adjust: tCanvasAdjust) {
|
|
221
|
-
const minWidth = canvasWidth / 10;
|
|
222
|
-
const lsizep = minWidth / adjust.scaleX;
|
|
223
|
-
let lref = 0.0001;
|
|
224
|
-
while (lref < lsizep) {
|
|
225
|
-
lref *= 10;
|
|
226
|
-
}
|
|
227
|
-
if (lref / 5 > lsizep) {
|
|
228
|
-
lref /= 5;
|
|
229
|
-
} else if (lref / 2 > lsizep) {
|
|
230
|
-
lref /= 2;
|
|
231
|
-
}
|
|
232
|
-
const lsize = lref * adjust.scaleX; // radius2canvas
|
|
233
|
-
return [lref, lsize];
|
|
234
|
-
}
|
|
235
|
-
drawRuler(ctx: CanvasRenderingContext2D, adjust: tCanvasAdjust, color: string) {
|
|
236
|
-
const [lref, lsize] = this.quantifyRuler(ctx.canvas.width, adjust);
|
|
237
|
-
const xpos = ctx.canvas.width - 10 - lsize;
|
|
238
|
-
//ctx.clearRect(xpos, 5, 100, 25);
|
|
239
|
-
ctx.font = '15px Arial';
|
|
240
|
-
ctx.fillStyle = color;
|
|
241
|
-
ctx.fillText(`${lref.toFixed(4)}`, xpos, 20);
|
|
242
|
-
ctx.beginPath();
|
|
243
|
-
ctx.moveTo(xpos, 25);
|
|
244
|
-
ctx.lineTo(xpos + lsize, 25);
|
|
245
|
-
ctx.lineTo(xpos + lsize, 25 + lsize);
|
|
246
|
-
ctx.strokeStyle = color;
|
|
247
|
-
ctx.stroke();
|
|
248
|
-
}
|
|
249
|
-
draw(ctx: CanvasRenderingContext2D, adjust: tCanvasAdjust, layers: tLayers) {
|
|
250
|
-
if (layers.points) {
|
|
251
|
-
for (const p of this.pointList) {
|
|
252
|
-
p.draw(ctx, adjust);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (layers.lines) {
|
|
256
|
-
for (const li of this.lineList) {
|
|
257
|
-
li.draw(ctx, adjust);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
if (layers.vectors) {
|
|
261
|
-
for (const li of this.vectorList) {
|
|
262
|
-
li.draw(ctx, adjust);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (layers.main) {
|
|
266
|
-
for (const li of this.mainList) {
|
|
267
|
-
li.draw(ctx, adjust, colors.main);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
if (layers.mainB) {
|
|
271
|
-
for (const li of this.mainBList) {
|
|
272
|
-
li.draw(ctx, adjust, colors.mainB);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (layers.second) {
|
|
276
|
-
for (const li of this.secondList) {
|
|
277
|
-
li.draw(ctx, adjust, colors.second);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (layers.secondB) {
|
|
281
|
-
for (const li of this.secondBList) {
|
|
282
|
-
li.draw(ctx, adjust, colors.secondB);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (layers.dynamics) {
|
|
286
|
-
for (const li of this.dynamicsList) {
|
|
287
|
-
li.draw(ctx, adjust, colors.dynamics);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if (layers.ruler) {
|
|
291
|
-
this.drawRuler(ctx, adjust, colors.ruler);
|
|
292
|
-
}
|
|
293
|
-
if (layers.refframe) {
|
|
294
|
-
for (const i of [10, 100, 200]) {
|
|
295
|
-
point(i, 0).draw(ctx, adjust, colors.reference, ShapePoint.eCross);
|
|
296
|
-
point(-i, 0).draw(ctx, adjust, colors.reference, ShapePoint.eCross);
|
|
297
|
-
point(0, i).draw(ctx, adjust, colors.reference, ShapePoint.eCross);
|
|
298
|
-
point(0, -i).draw(ctx, adjust, colors.reference, ShapePoint.eCross);
|
|
299
|
-
}
|
|
300
|
-
point(0, 0).draw(ctx, adjust, colors.origin, ShapePoint.eCross);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function figure() {
|
|
306
|
-
return new Figure();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
type tFaces = Record<string, Figure>;
|
|
310
|
-
function mergeFaces(iFaces: tFaces): Figure {
|
|
311
|
-
const rfig = figure();
|
|
312
|
-
for (const face in iFaces) {
|
|
313
|
-
const fig = iFaces[face];
|
|
314
|
-
for (const ipoint of fig.pointList) {
|
|
315
|
-
rfig.pointList.push(ipoint);
|
|
316
|
-
}
|
|
317
|
-
for (const iline of fig.lineList) {
|
|
318
|
-
rfig.lineList.push(iline);
|
|
319
|
-
}
|
|
320
|
-
for (const ivector of fig.vectorList) {
|
|
321
|
-
rfig.vectorList.push(ivector);
|
|
322
|
-
}
|
|
323
|
-
for (const ctr of fig.mainList) {
|
|
324
|
-
rfig.mainList.push(ctr);
|
|
325
|
-
}
|
|
326
|
-
for (const ctr of fig.mainBList) {
|
|
327
|
-
rfig.mainBList.push(ctr);
|
|
328
|
-
}
|
|
329
|
-
for (const ctr of fig.secondList) {
|
|
330
|
-
rfig.secondList.push(ctr);
|
|
331
|
-
}
|
|
332
|
-
for (const ctr of fig.secondBList) {
|
|
333
|
-
rfig.secondBList.push(ctr);
|
|
334
|
-
}
|
|
335
|
-
for (const ctr of fig.dynamicsList) {
|
|
336
|
-
rfig.dynamicsList.push(ctr);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return rfig;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function initLayers(): tLayers {
|
|
343
|
-
const layers: tLayers = {
|
|
344
|
-
points: false,
|
|
345
|
-
lines: false,
|
|
346
|
-
vectors: false,
|
|
347
|
-
main: true,
|
|
348
|
-
mainB: false,
|
|
349
|
-
second: true,
|
|
350
|
-
secondB: false,
|
|
351
|
-
dynamics: false,
|
|
352
|
-
ruler: true,
|
|
353
|
-
refframe: false
|
|
354
|
-
};
|
|
355
|
-
return layers;
|
|
356
|
-
}
|
|
357
|
-
function copyLayers(iLayers: tLayers): tLayers {
|
|
358
|
-
const layers: tLayers = {
|
|
359
|
-
points: iLayers.points,
|
|
360
|
-
lines: iLayers.lines,
|
|
361
|
-
vectors: iLayers.vectors,
|
|
362
|
-
main: iLayers.main,
|
|
363
|
-
mainB: iLayers.mainB,
|
|
364
|
-
second: iLayers.second,
|
|
365
|
-
secondB: iLayers.secondB,
|
|
366
|
-
dynamics: iLayers.dynamics,
|
|
367
|
-
ruler: iLayers.ruler,
|
|
368
|
-
refframe: iLayers.refframe
|
|
369
|
-
};
|
|
370
|
-
return layers;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/* export */
|
|
374
|
-
|
|
375
|
-
export type { Point, tContour, tLayers, Figure, tFaces };
|
|
376
|
-
export {
|
|
377
|
-
ShapePoint,
|
|
378
|
-
withinZero2Pi,
|
|
379
|
-
withinPiPi,
|
|
380
|
-
degToRad,
|
|
381
|
-
radToDeg,
|
|
382
|
-
roundZero,
|
|
383
|
-
ffix,
|
|
384
|
-
lcFromLaLbAc,
|
|
385
|
-
aCFromLaLbLc,
|
|
386
|
-
lbFromLaAaAb,
|
|
387
|
-
aBFromLaLbAa,
|
|
388
|
-
point,
|
|
389
|
-
line,
|
|
390
|
-
linePP,
|
|
391
|
-
bisector,
|
|
392
|
-
circleCenter,
|
|
393
|
-
vector,
|
|
394
|
-
contour,
|
|
395
|
-
contourCircle,
|
|
396
|
-
figure,
|
|
397
|
-
mergeFaces,
|
|
398
|
-
initLayers,
|
|
399
|
-
copyLayers
|
|
400
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// index.ts (previously geom.ts)
|
|
2
|
-
|
|
3
|
-
export * from './canvas_utils';
|
|
4
|
-
|
|
5
|
-
//import type { Point, tContour, tLayers, Figure } from './figure';
|
|
6
|
-
//export type { Point, tContour, tLayers, Figure };
|
|
7
|
-
//export type * from './figure';
|
|
8
|
-
export * from './figure';
|
|
9
|
-
|
|
10
|
-
export * from './designParams';
|
|
11
|
-
export * from './volume';
|
|
12
|
-
export * from './sub_design';
|
|
13
|
-
export * from './aaParamGeom';
|
|
14
|
-
|
|
15
|
-
export * from './aaExportFile';
|
|
16
|
-
export * from './paramFile';
|
package/src/line.test.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { Line, line, bisector, circleCenter } from './line';
|
|
3
|
-
import { point } from './point';
|
|
4
|
-
import { degToRad } from './angle_utils';
|
|
5
|
-
|
|
6
|
-
describe('line module', () => {
|
|
7
|
-
const l1 = new Line(10, 10, Math.PI / 4);
|
|
8
|
-
const l2 = line(20, 20, (3 / 4) * Math.PI);
|
|
9
|
-
const p1 = point(30, 30);
|
|
10
|
-
const p2 = point(30, -30);
|
|
11
|
-
const lr1 = line(9, -3, degToRad(288));
|
|
12
|
-
const lr2 = line(-15, -33, degToRad(-37));
|
|
13
|
-
it('Line construction', () => {
|
|
14
|
-
expect(() => new Line(0, 0, 0).setFromPoints(p1, p1)).toThrowError(/err434/);
|
|
15
|
-
expect(new Line(0, 0, 0).setFromPoints(p2, p1).ca).toBeCloseTo(Math.PI / 2, 5);
|
|
16
|
-
});
|
|
17
|
-
it('Line Affine', () => {
|
|
18
|
-
const l1Affine = l1.getAffine();
|
|
19
|
-
const l1b = line(0, 0, 0).setAffine(l1Affine);
|
|
20
|
-
expect(l1.isEqual(l1b)).toBeTruthy();
|
|
21
|
-
const lr1Affine = lr1.getAffine();
|
|
22
|
-
const lr1b = line(0, 0, 0).setAffine(lr1Affine);
|
|
23
|
-
expect(lr1.isEqual(lr1b)).toBeTruthy();
|
|
24
|
-
});
|
|
25
|
-
it('Line Axis X and Y intersection', () => {
|
|
26
|
-
expect(l1.getAxisXIntersection()).toBeCloseTo(0, 5);
|
|
27
|
-
expect(l2.getAxisXIntersection()).toBeCloseTo(40, 5);
|
|
28
|
-
expect(l1.getAxisYIntersection()).toBeCloseTo(0, 5);
|
|
29
|
-
expect(l2.getAxisYIntersection()).toBeCloseTo(40, 5);
|
|
30
|
-
});
|
|
31
|
-
it('Line Axis X and Y intersection with triangulation', () => {
|
|
32
|
-
expect(lr1.getAxisXIntersecTri()).toBeCloseTo(lr1.getAxisXIntersection(), 5);
|
|
33
|
-
expect(lr2.getAxisXIntersecTri()).toBeCloseTo(lr2.getAxisXIntersection(), 5);
|
|
34
|
-
expect(lr1.getAxisYIntersecTri()).toBeCloseTo(lr1.getAxisYIntersection(), 5);
|
|
35
|
-
expect(lr2.getAxisYIntersecTri()).toBeCloseTo(lr2.getAxisYIntersection(), 5);
|
|
36
|
-
});
|
|
37
|
-
it('Line distance to Origine', () => {
|
|
38
|
-
expect(l1.distanceOrig()).toBeCloseTo(0, 5);
|
|
39
|
-
expect(l2.distanceOrig()).toBeCloseTo(20 * Math.sqrt(2), 5);
|
|
40
|
-
});
|
|
41
|
-
const l3 = line(50, 0, Math.PI / 2);
|
|
42
|
-
const l4 = line(0, 60, 0);
|
|
43
|
-
it('Line orthogonal projection', () => {
|
|
44
|
-
expect(l1.distanceToPoint(point(10, 10))).toBeCloseTo(0, 5);
|
|
45
|
-
expect(l1.distanceToPoint(point(0, 0))).toBeCloseTo(0, 5);
|
|
46
|
-
expect(l1.distanceToPoint(point(10, -10))).toBeCloseTo(10 * Math.sqrt(2), 5);
|
|
47
|
-
expect(l3.distanceToPoint(point(50, 10))).toBeCloseTo(0, 5);
|
|
48
|
-
expect(l3.distanceToPoint(point(30, 10))).toBeCloseTo(20, 5);
|
|
49
|
-
expect(l4.distanceToPoint(point(-10, 60))).toBeCloseTo(0, 5);
|
|
50
|
-
expect(l4.distanceToPoint(point(20, 90))).toBeCloseTo(30, 5);
|
|
51
|
-
});
|
|
52
|
-
const l5 = line(-30, -30, -Math.PI / 2);
|
|
53
|
-
const l6 = line(-30, 40, -Math.PI / 2);
|
|
54
|
-
it('Line comparison', () => {
|
|
55
|
-
expect(l1.isOrthogonal(l2)).toBeTruthy();
|
|
56
|
-
expect(l1.isOrthogonal(l1)).toBeFalsy();
|
|
57
|
-
expect(l1.isOrthogonal(l3)).toBeFalsy();
|
|
58
|
-
expect(l1.isParallel(l2)).toBeFalsy();
|
|
59
|
-
expect(l3.isParallel(l5)).toBeTruthy();
|
|
60
|
-
expect(l3.isParallel(l3)).toBeTruthy();
|
|
61
|
-
expect(l4.isParallel(l1)).toBeFalsy();
|
|
62
|
-
expect(l1.isEqual(l1)).toBeTruthy();
|
|
63
|
-
expect(l1.isEqual(l2)).toBeFalsy();
|
|
64
|
-
expect(l5.isEqual(l6)).toBeTruthy();
|
|
65
|
-
});
|
|
66
|
-
it('Bisector of 2 points', () => {
|
|
67
|
-
const lAxisX = line(0, 0, 0);
|
|
68
|
-
expect(bisector(p1, p2).isEqual(lAxisX)).toBeTruthy();
|
|
69
|
-
});
|
|
70
|
-
it('Circle-center of 3 points', () => {
|
|
71
|
-
const pA = point(38, 54);
|
|
72
|
-
const pB = point(-5, 28);
|
|
73
|
-
const pC = point(5, 79);
|
|
74
|
-
expect(circleCenter(pA, pB, pC).isEqual(circleCenter(pA, pC, pB))).toBeTruthy();
|
|
75
|
-
expect(circleCenter(pA, pB, pC).isEqual(circleCenter(pC, pA, pB))).toBeTruthy();
|
|
76
|
-
expect(circleCenter(pA, pB, pC).isEqual(circleCenter(pB, pA, pC))).toBeTruthy();
|
|
77
|
-
});
|
|
78
|
-
});
|