Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/modeling/src/geometries/geom2/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const reverse = (geometry) => {

const newsides = oldsides.map((side) => [side[1], side[0]])
newsides.reverse() // is this required?
return create(newsides)
return Object.assign({}, geometry, create(newsides))

@z3dev z3dev Sep 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could save a function call and multiple object creation by using...

return Object.assign({}, geometry, { sides: newsides })

}

module.exports = reverse
24 changes: 23 additions & 1 deletion packages/modeling/src/geometries/geom2/reverse.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
const test = require('ava')

const { reverse, fromPoints } = require('./index')
const { reverse, fromPoints, transform } = require('./index')

const mat4 = require('../../maths/mat4')

const { comparePoints, compareVectors } = require('../../../test/helpers/')

test('reverse: keeps color and other fields of the geometry', (t) => {
const geometry = fromPoints([[0, 0], [1, 0], [0, 1]])
geometry.color = [1, 0, 0, 1]
geometry.userData = { name: 'part' }
const another = reverse(geometry)
t.deepEqual(another.color, [1, 0, 0, 1])
t.is(another.userData, geometry.userData)
t.not(another.sides, geometry.sides)
t.true(compareVectors(another.transforms, mat4.create()))
})

test('reverse: mirroring a geom2 keeps its fields', (t) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to transform.test.js? It's probably better in that suite.

const geometry = fromPoints([[0, 0], [1, 0], [0, 1]])
geometry.color = [0, 0, 1, 1]
geometry.userData = { name: 'part' }
const mirrored = transform(mat4.fromScaling(mat4.create(), [-1, 1, 1]), geometry)
t.deepEqual(mirrored.color, [0, 0, 1, 1])
t.is(mirrored.userData, geometry.userData)
})

test('reverse: Reverses a populated geom2', (t) => {
const points = [[0, 0], [1, 0], [0, 1]]
const expected = {
Expand Down
Loading