Skip to content

Commit c6d6b05

Browse files
grid updated
1 parent d81367d commit c6d6b05

3 files changed

Lines changed: 11 additions & 27 deletions

File tree

public/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,6 +4255,7 @@ ${entry.message}` : entry.message
42554255
const radialBasePositions = orderedObjectIds.map(
42564256
(object_id) => translationFromTransforms(state.transformByObjectId[object_id] ?? [])
42574257
);
4258+
const gridAnchorPosition = radialBasePositions[0] ?? { x: 0, y: 0, z: 0 };
42584259
const radialCenter = state.explodeMode === "radial" ? radialBasePositions.reduce(
42594260
(center, position) => ({
42604261
x: center.x + position.x / orderedObjectIds.length,
@@ -4300,8 +4301,8 @@ ${entry.message}` : entry.message
43004301
if (index < rowStartIndex + rowCount) {
43014302
const column = index - rowStartIndex;
43024303
return {
4303-
x: (column - (rowCount - 1) / 2) * spacing,
4304-
y: (row - (rows - 1) / 2) * spacing,
4304+
x: gridAnchorPosition.x + column * spacing,
4305+
y: gridAnchorPosition.y + row * spacing,
43054306
z: 0
43064307
};
43074308
}

src/main.test.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,7 +3073,7 @@ describe('createApp', () => {
30733073
})
30743074
})
30753075

3076-
it('lays out grid explode in a centered near-square grid', async () => {
3076+
it('lays out grid explode from the first item in a near-square grid', async () => {
30773077
const { storage } = createStorage()
30783078
const execution = deferred()
30793079
const fileHandle: FakeFileHandle = {
@@ -3230,32 +3230,14 @@ describe('createApp', () => {
32303230
}>
32313231
}
32323232
expect(gridBatch.requests.map(request => ({ cmd: request.cmd }))).toEqual([
3233-
{
3234-
cmd: {
3235-
type: 'set_object_transform',
3236-
object_id: 'solid-object-1',
3237-
transforms: [
3238-
{
3239-
translate: {
3240-
property: { x: -76, y: -39.5, z: 0 },
3241-
set: false,
3242-
origin: { type: 'local' },
3243-
},
3244-
rotate_rpy: null,
3245-
rotate_angle_axis: null,
3246-
scale: null,
3247-
},
3248-
],
3249-
},
3250-
},
32513233
{
32523234
cmd: {
32533235
type: 'set_object_transform',
32543236
object_id: 'solid-object-2',
32553237
transforms: [
32563238
{
32573239
translate: {
3258-
property: { x: -4, y: -42.5, z: -1 },
3240+
property: { x: 72, y: -3, z: -1 },
32593241
set: false,
32603242
origin: { type: 'local' },
32613243
},
@@ -3273,7 +3255,7 @@ describe('createApp', () => {
32733255
transforms: [
32743256
{
32753257
translate: {
3276-
property: { x: 78, y: -38.5, z: -2 },
3258+
property: { x: 154, y: 1, z: -2 },
32773259
set: false,
32783260
origin: { type: 'local' },
32793261
},
@@ -3291,7 +3273,7 @@ describe('createApp', () => {
32913273
transforms: [
32923274
{
32933275
translate: {
3294-
property: { x: -37.5, y: 43.5, z: 0 },
3276+
property: { x: 1, y: 83, z: 0 },
32953277
set: false,
32963278
origin: { type: 'local' },
32973279
},
@@ -3309,7 +3291,7 @@ describe('createApp', () => {
33093291
transforms: [
33103292
{
33113293
translate: {
3312-
property: { x: 35.5, y: 38.5, z: 3 },
3294+
property: { x: 74, y: 78, z: 3 },
33133295
set: false,
33143296
origin: { type: 'local' },
33153297
},

src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,7 @@ export function createApp(root: HTMLElement, partialDeps: Partial<AppDeps> = {})
20952095
const radialBasePositions = orderedObjectIds.map(object_id =>
20962096
translationFromTransforms(state.transformByObjectId[object_id] ?? []),
20972097
)
2098+
const gridAnchorPosition = radialBasePositions[0] ?? { x: 0, y: 0, z: 0 }
20982099
const radialCenter =
20992100
state.explodeMode === 'radial'
21002101
? radialBasePositions.reduce(
@@ -2145,8 +2146,8 @@ export function createApp(root: HTMLElement, partialDeps: Partial<AppDeps> = {})
21452146
if (index < rowStartIndex + rowCount) {
21462147
const column = index - rowStartIndex
21472148
return {
2148-
x: (column - (rowCount - 1) / 2) * spacing,
2149-
y: (row - (rows - 1) / 2) * spacing,
2149+
x: gridAnchorPosition.x + column * spacing,
2150+
y: gridAnchorPosition.y + row * spacing,
21502151
z: 0,
21512152
}
21522153
}

0 commit comments

Comments
 (0)