Skip to content

Commit 2c00366

Browse files
committed
feat(typescript): add PointSet interface type support
1 parent 3d75909 commit 2c00366

File tree

8 files changed

+111
-2
lines changed

8 files changed

+111
-2
lines changed

packages/core/typescript/itk-wasm/src/interface-types/index-common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export type { default as JsonCompatible } from './json-compatible.js'
1414
export { default as Image } from './image.js'
1515
export { default as ImageType } from './image-type.js'
1616

17+
export { default as PointSet } from './point-set.js'
18+
export { default as PointSetType } from './point-set-type.js'
19+
1720
export { default as Mesh } from './mesh.js'
1821
export { default as MeshType } from './mesh-type.js'
1922

packages/core/typescript/itk-wasm/src/interface-types/interface-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const InterfaceTypes = {
44
TextStream: 'TextStream',
55
BinaryStream: 'BinaryStream',
66
Image: 'Image',
7+
PointSet: 'PointSet',
78
Mesh: 'Mesh',
89
PolyData: 'PolyData',
910
Transform: 'Transform',

packages/core/typescript/itk-wasm/src/interface-types/mesh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Mesh {
1818
cellData: null | TypedArray
1919

2020
constructor (public readonly meshType = new MeshType()) {
21-
this.name = 'mesh'
21+
this.name = 'Mesh'
2222

2323
this.numberOfPoints = 0
2424
this.points = null
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import IntTypes from './int-types.js'
2+
import FloatTypes from './float-types.js'
3+
import PixelTypes from './pixel-types.js'
4+
5+
class PointSetType {
6+
constructor (
7+
public readonly dimension: number = 3,
8+
public readonly pointComponentType: (typeof FloatTypes)[keyof typeof FloatTypes] = FloatTypes.Float32,
9+
public readonly pointPixelComponentType:
10+
| (typeof IntTypes)[keyof typeof IntTypes]
11+
| (typeof FloatTypes)[keyof typeof FloatTypes] = FloatTypes.Float32,
12+
public readonly pointPixelType: (typeof PixelTypes)[keyof typeof PixelTypes] = PixelTypes.Scalar,
13+
public readonly pointPixelComponents: number = 1
14+
) {}
15+
}
16+
17+
export default PointSetType
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import PointSetType from './point-set-type.js'
2+
import type TypedArray from '../typed-array.js'
3+
4+
class PointSet {
5+
name: string = 'PointSet'
6+
7+
numberOfPoints: number
8+
points: null | TypedArray
9+
10+
numberOfPointPixels: number
11+
pointData: null | TypedArray
12+
13+
constructor (public readonly pointSetType = new PointSetType()) {
14+
this.name = 'PointSet'
15+
16+
this.numberOfPoints = 0
17+
this.points = null
18+
19+
this.numberOfPointPixels = 0
20+
this.pointData = null
21+
}
22+
}
23+
24+
export default PointSet

packages/core/typescript/itk-wasm/test/node/interface-types/mesh-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('meshType should have the same meshType passed to the constructor', t => {
1010

1111
test('name should have the default value of "Mesh"', t => {
1212
const mesh = new Mesh()
13-
t.deepEqual(mesh.name, 'mesh')
13+
t.deepEqual(mesh.name, 'Mesh')
1414
})
1515

1616
test('numberOfPoints should have a default value of 0', t => {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import test from 'ava'
2+
3+
import { PointSet, PointSetType } from '../../../dist/index-node.js'
4+
5+
test('pointSetType should have the same pointSetType passed to the constructor', t => {
6+
const pointSet = new PointSet()
7+
const defaultPointSetType = new PointSetType()
8+
t.deepEqual(pointSet.pointSetType, defaultPointSetType)
9+
})
10+
11+
test('name should have the default value of "PointSet"', t => {
12+
const pointSet = new PointSet()
13+
t.deepEqual(pointSet.name, 'PointSet')
14+
})
15+
16+
test('numberOfPoints should have a default value of 0', t => {
17+
const pointSet = new PointSet()
18+
t.is(pointSet.numberOfPoints, 0)
19+
})
20+
21+
test('points should have a default value of null', t => {
22+
const pointSet = new PointSet()
23+
t.is(pointSet.points, null)
24+
})
25+
26+
test('numberOfPointPixels should have a default value of 0', t => {
27+
const pointSet = new PointSet()
28+
t.is(pointSet.numberOfPointPixels, 0)
29+
})
30+
31+
test('pointData should have a default value of null', t => {
32+
const pointSet = new PointSet()
33+
t.is(pointSet.pointData, null)
34+
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import test from 'ava'
2+
3+
import { PointSetType, FloatTypes } from '../../../dist/index-node.js'
4+
5+
test('dimension should have a default value of 3', t => {
6+
const pointSetType = new PointSetType()
7+
t.is(pointSetType.dimension, 3)
8+
})
9+
test('dimension should have the same value passed to the constructor', t => {
10+
const pointSetType = new PointSetType(2)
11+
t.is(pointSetType.dimension, 2)
12+
})
13+
14+
test('pointComponentType should have a default value of Float32', t => {
15+
const pointSetType = new PointSetType()
16+
t.is(pointSetType.pointComponentType, FloatTypes.Float32)
17+
})
18+
test('pointComponentType should have the same value passed to the constructor', t => {
19+
const pointSetType = new PointSetType(3, FloatTypes.Float64)
20+
t.is(pointSetType.pointComponentType, FloatTypes.Float64)
21+
})
22+
23+
test('pointPixelComponentType should have a default value of Float32', t => {
24+
const pointSetType = new PointSetType()
25+
t.is(pointSetType.pointPixelComponentType, FloatTypes.Float32)
26+
})
27+
test('pointPixelComponentType should have the same value passed to the constructor', t => {
28+
const pointSetType = new PointSetType(3, FloatTypes.Float64, FloatTypes.Float64)
29+
t.is(pointSetType.pointPixelComponentType, FloatTypes.Float64)
30+
})

0 commit comments

Comments
 (0)