1
0

Place rectangles by their centers

This commit is contained in:
Bán Dénes 2021-12-18 19:51:26 +01:00
parent 73045e4754
commit 0ed29e7e1d
5 changed files with 105 additions and 106 deletions

View File

@ -265,14 +265,13 @@ exports.parse = (config = {}, points = {}, units = {}) => {
const corner = a.sane(part.corner || 0, `${name}.corner`, 'number')(rec_units)
const bevel = a.sane(part.bevel || 0, `${name}.bevel`, 'number')(rec_units)
const rect_mirror = a.sane(part.mirror || false, `${name}.mirror`, 'boolean')()
const rect = rectangle(size[0], size[1], corner, bevel, name)
const rect = m.model.moveRelative(rectangle(size[0], size[1], corner, bevel, name), [-size[0]/2, -size[1]/2])
arg = anchor.position(u.deepcopy(rect))
if (rect_mirror) {
const mirror_anchor = u.deepcopy(anchor_def)
a.assert(mirror_anchor.ref, `Field "${name}.anchor.ref" must be speficied if mirroring is required!`)
anchor = anchor_lib.parse(mirror_anchor, `${name}.anchor --> mirror`, points, undefined, undefined, true)(rec_units)
const mirror_rect = m.model.moveRelative(u.deepcopy(rect), [-size[0], 0])
arg = u.union(arg, anchor.position(mirror_rect))
arg = u.union(arg, anchor.position(u.deepcopy(rect)))
}
break
case 'circle':

View File

@ -59,7 +59,7 @@ module.exports = class Point {
}
rect(size=14) {
let rect = u.rect(size, size, [-size/2, -size/2], this.meta.mirrored)
let rect = u.rect(size, size, [-size/2, -size/2])
return this.position(rect)
}
}

View File

@ -1,86 +1,86 @@
solid csg.js
facet normal 0 0 -1
outer loop
vertex 0 5 0
vertex 5 5 0
vertex 5 0 0
vertex -2.5 2.5 0
vertex 2.5 2.5 0
vertex 2.5 -2.5 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 0 5 0
vertex 5 0 0
vertex 0 0 0
vertex -2.5 2.5 0
vertex 2.5 -2.5 0
vertex -2.5 -2.5 0
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 0 5 5
vertex 0 0 5
vertex 5 0 5
vertex -2.5 2.5 5
vertex -2.5 -2.5 5
vertex 2.5 -2.5 5
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 0 5 5
vertex 5 0 5
vertex 5 5 5
vertex -2.5 2.5 5
vertex 2.5 -2.5 5
vertex 2.5 2.5 5
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 5 0 0
vertex 5 0 5
vertex 0 0 5
vertex 2.5 -2.5 0
vertex 2.5 -2.5 5
vertex -2.5 -2.5 5
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 5 0 0
vertex 0 0 5
vertex 0 0 0
vertex 2.5 -2.5 0
vertex -2.5 -2.5 5
vertex -2.5 -2.5 0
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 5 5 0
vertex 5 5 5
vertex 5 0 5
vertex 2.5 2.5 0
vertex 2.5 2.5 5
vertex 2.5 -2.5 5
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 5 5 0
vertex 5 0 5
vertex 5 0 0
vertex 2.5 2.5 0
vertex 2.5 -2.5 5
vertex 2.5 -2.5 0
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 5 5 5
vertex 5 5 0
vertex 0 5 0
vertex 2.5 2.5 5
vertex 2.5 2.5 0
vertex -2.5 2.5 0
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 5 5 5
vertex 0 5 0
vertex 0 5 5
vertex 2.5 2.5 5
vertex -2.5 2.5 0
vertex -2.5 2.5 5
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 0 5 5
vertex 0 5 0
vertex 0 0 0
vertex -2.5 2.5 5
vertex -2.5 2.5 0
vertex -2.5 -2.5 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 0 5 5
vertex 0 0 0
vertex 0 0 5
vertex -2.5 2.5 5
vertex -2.5 -2.5 0
vertex -2.5 -2.5 5
endloop
endfacet
endsolid csg.js

View File

@ -241,193 +241,193 @@ LINE
8
0
10
31.0980762
27
20
-4.0980762
-5.1961524
11
36.2942286
32.1961524
21
-7.0980762
-8.1961524
0
LINE
8
0
10
36.2942286
32.1961524
20
-7.0980762
-8.1961524
11
39.2942286
35.1961524
21
-1.9019238
-3
0
LINE
8
0
10
39.2942286
35.1961524
20
-1.9019238
-3
11
34.0980762
30
21
1.0980762
0
0
LINE
8
0
10
34.0980762
30
20
1.0980762
0
11
31.0980762
27
21
-4.0980762
-5.1961524
0
LINE
8
0
10
31.0980762
27
20
14.9019238
13.8038476
11
36.2942286
32.1961524
21
11.9019238
10.8038476
0
LINE
8
0
10
36.2942286
32.1961524
20
11.9019238
10.8038476
11
39.2942286
35.1961524
21
17.0980762
16
0
LINE
8
0
10
39.2942286
35.1961524
20
17.0980762
16
11
34.0980762
30
21
20.0980762
19
0
LINE
8
0
10
34.0980762
30
20
20.0980762
19
11
31.0980762
27
21
14.9019238
13.8038476
0
LINE
8
0
10
-1.0980762
-2.1961524
20
-4.0980762
-8.1961524
11
4.0980762
3
21
-1.0980762
-5.1961524
0
LINE
8
0
10
4.0980762
3
20
-1.0980762
-5.1961524
11
1.0980762
0
21
4.0980762
0
0
LINE
8
0
10
1.0980762
0
20
4.0980762
0
11
-4.0980762
-5.1961524
21
1.0980762
-3
0
LINE
8
0
10
-4.0980762
-5.1961524
20
1.0980762
-3
11
-1.0980762
-2.1961524
21
-4.0980762
-8.1961524
0
LINE
8
0
10
-1.0980762
-2.1961524
20
14.9019238
10.8038476
11
4.0980762
3
21
17.9019238
13.8038476
0
LINE
8
0
10
4.0980762
3
20
17.9019238
13.8038476
11
1.0980762
0
21
23.0980762
19
0
LINE
8
0
10
1.0980762
0
20
23.0980762
19
11
-4.0980762
-5.1961524
21
20.0980762
16
0
LINE
8
0
10
-4.0980762
-5.1961524
20
20.0980762
16
11
-1.0980762
-2.1961524
21
14.9019238
10.8038476
0
ENDSEC
0

View File

@ -16,12 +16,12 @@ outlines:
ref:
- matrix_default_default
- mirror_matrix_default_default
shift: [-sx/2, 0]
shift: [0, sy/2]
size: [20, 40]
outside_rects:
type: rectangle
anchor:
ref: matrix_default_default
shift: [-15, 5]
shift: [-10, 10]
size: 10
mirror: true