Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript): add PointSet interface type support #1226

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export type { default as JsonCompatible } from './json-compatible.js'
export { default as Image } from './image.js'
export { default as ImageType } from './image-type.js'

export { default as PointSet } from './point-set.js'
export { default as PointSetType } from './point-set-type.js'

export { default as Mesh } from './mesh.js'
export { default as MeshType } from './mesh-type.js'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const InterfaceTypes = {
TextStream: 'TextStream',
BinaryStream: 'BinaryStream',
Image: 'Image',
PointSet: 'PointSet',
Mesh: 'Mesh',
PolyData: 'PolyData',
Transform: 'Transform',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Mesh {
cellData: null | TypedArray

constructor (public readonly meshType = new MeshType()) {
this.name = 'mesh'
this.name = 'Mesh'

this.numberOfPoints = 0
this.points = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import IntTypes from './int-types.js'
import FloatTypes from './float-types.js'
import PixelTypes from './pixel-types.js'

class PointSetType {
constructor (
public readonly dimension: number = 3,
public readonly pointComponentType: (typeof FloatTypes)[keyof typeof FloatTypes] = FloatTypes.Float32,
public readonly pointPixelComponentType:
| (typeof IntTypes)[keyof typeof IntTypes]
| (typeof FloatTypes)[keyof typeof FloatTypes] = FloatTypes.Float32,
public readonly pointPixelType: (typeof PixelTypes)[keyof typeof PixelTypes] = PixelTypes.Scalar,
public readonly pointPixelComponents: number = 1
) {}
}

export default PointSetType
24 changes: 24 additions & 0 deletions packages/core/typescript/itk-wasm/src/interface-types/point-set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import PointSetType from './point-set-type.js'
import type TypedArray from '../typed-array.js'

class PointSet {
name: string = 'PointSet'

numberOfPoints: number
points: null | TypedArray

numberOfPointPixels: number
pointData: null | TypedArray

constructor (public readonly pointSetType = new PointSetType()) {
this.name = 'PointSet'

this.numberOfPoints = 0
this.points = null

this.numberOfPointPixels = 0
this.pointData = null
}
}

export default PointSet
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('meshType should have the same meshType passed to the constructor', t => {

test('name should have the default value of "Mesh"', t => {
const mesh = new Mesh()
t.deepEqual(mesh.name, 'mesh')
t.deepEqual(mesh.name, 'Mesh')
})

test('numberOfPoints should have a default value of 0', t => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import test from 'ava'

import { PointSet, PointSetType } from '../../../dist/index-node.js'

test('pointSetType should have the same pointSetType passed to the constructor', t => {
const pointSet = new PointSet()
const defaultPointSetType = new PointSetType()
t.deepEqual(pointSet.pointSetType, defaultPointSetType)
})

test('name should have the default value of "PointSet"', t => {
const pointSet = new PointSet()
t.deepEqual(pointSet.name, 'PointSet')
})

test('numberOfPoints should have a default value of 0', t => {
const pointSet = new PointSet()
t.is(pointSet.numberOfPoints, 0)
})

test('points should have a default value of null', t => {
const pointSet = new PointSet()
t.is(pointSet.points, null)
})

test('numberOfPointPixels should have a default value of 0', t => {
const pointSet = new PointSet()
t.is(pointSet.numberOfPointPixels, 0)
})

test('pointData should have a default value of null', t => {
const pointSet = new PointSet()
t.is(pointSet.pointData, null)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import test from 'ava'

import { PointSetType, FloatTypes } from '../../../dist/index-node.js'

test('dimension should have a default value of 3', t => {
const pointSetType = new PointSetType()
t.is(pointSetType.dimension, 3)
})
test('dimension should have the same value passed to the constructor', t => {
const pointSetType = new PointSetType(2)
t.is(pointSetType.dimension, 2)
})

test('pointComponentType should have a default value of Float32', t => {
const pointSetType = new PointSetType()
t.is(pointSetType.pointComponentType, FloatTypes.Float32)
})
test('pointComponentType should have the same value passed to the constructor', t => {
const pointSetType = new PointSetType(3, FloatTypes.Float64)
t.is(pointSetType.pointComponentType, FloatTypes.Float64)
})

test('pointPixelComponentType should have a default value of Float32', t => {
const pointSetType = new PointSetType()
t.is(pointSetType.pointPixelComponentType, FloatTypes.Float32)
})
test('pointPixelComponentType should have the same value passed to the constructor', t => {
const pointSetType = new PointSetType(3, FloatTypes.Float64, FloatTypes.Float64)
t.is(pointSetType.pointPixelComponentType, FloatTypes.Float64)
})
Loading