Skip to content

Commit 2acdd0e

Browse files
committed
Use typeof for undefined check
1 parent 024d4c4 commit 2acdd0e

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

src/tools/brush.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function getIndexCompareFunction(direction) {
129129
let result = 0;
130130
const va = a.get(direction);
131131
const vb = b.get(direction);
132-
if (va !== undefined && vb !== undefined) {
132+
if (typeof va !== 'undefined' && typeof vb !== 'undefined') {
133133
result = va - vb;
134134
}
135135
return result;
@@ -205,15 +205,15 @@ function getOriginIndexRangeFromMaskIndices(geometry, indices) {
205205

206206
// lowest origin
207207
const z0 = sorted[0].get(2);
208-
if (z0 === undefined) {
208+
if (typeof z0 === 'undefined') {
209209
return [];
210210
}
211211
const index0 = new Index([0, 0, z0]);
212212
const origin0 = geometry.indexToWorld(index0);
213213

214214
// highest origin
215215
const z1 = sorted.at(-1).get(2);
216-
if (z1 === undefined) {
216+
if (typeof z1 === 'undefined') {
217217
return [];
218218
}
219219
const index1 = new Index([0, 0, z1]);
@@ -300,7 +300,7 @@ class DrawBrushCommand {
300300
this.#segmentNumber = properties.segmentNumber;
301301
this.#srclayerid = properties.srclayerid;
302302

303-
if (properties.originalValuesLists !== undefined) {
303+
if (typeof properties.originalValuesLists !== 'undefined') {
304304
this.#originalValuesLists = properties.originalValuesLists;
305305
}
306306
this.#isSilent = properties.isSilent ?? false;
@@ -352,7 +352,7 @@ class DrawBrushCommand {
352352
* @fires DrawBrushCommand#brushdraw
353353
*/
354354
execute() {
355-
if (this.#segmentNumber === undefined) {
355+
if (typeof this.#segmentNumber === 'undefined') {
356356
return;
357357
}
358358

@@ -362,7 +362,7 @@ class DrawBrushCommand {
362362
}
363363

364364
// draw
365-
if (this.#originalValuesLists === undefined) {
365+
if (typeof this.#originalValuesLists === 'undefined') {
366366
this.#originalValuesLists = this.#mask.setAtOffsetsAndGetOriginals(
367367
this.#offsetsLists,
368368
segNumber
@@ -390,7 +390,7 @@ class DrawBrushCommand {
390390
* @fires DrawBrushCommand#brushremove
391391
*/
392392
undo() {
393-
if (this.#originalValuesLists === undefined) {
393+
if (typeof this.#originalValuesLists === 'undefined') {
394394
this.#originalValuesLists = this.#mask.setAtOffsetsAndGetOriginals(
395395
this.#offsetsLists,
396396
0
@@ -598,7 +598,8 @@ export class Brush extends EventTarget {
598598
sourceGeometry,
599599
circleIndices
600600
);
601-
if (newOrigIndexRange === undefined || newOrigIndexRange.length === 0) {
601+
if (typeof newOrigIndexRange === 'undefined' ||
602+
newOrigIndexRange.length === 0) {
602603
throw new Error(ERROR_MESSAGES.brush.noBrushOrigins);
603604
}
604605

@@ -642,7 +643,7 @@ export class Brush extends EventTarget {
642643
}
643644

644645
// append slices
645-
if (this.#mask === undefined) {
646+
if (typeof this.#mask === 'undefined') {
646647
throw new Error(ERROR_MESSAGES.brush.noMaskDefined);
647648
}
648649
const tags = this.#mask.getMeta();
@@ -663,7 +664,7 @@ export class Brush extends EventTarget {
663664
const srclayerid = maskVl.getId();
664665

665666
// get mask image
666-
if (this.#maskDataId === undefined) {
667+
if (typeof this.#maskDataId === 'undefined') {
667668
throw new Error(ERROR_MESSAGES.brush.noMaskId);
668669
}
669670
const maskData = this.#app.getData(this.#maskDataId);
@@ -684,11 +685,11 @@ export class Brush extends EventTarget {
684685
command.execute();
685686

686687
// store offsets and colours for final command
687-
this.#tmpOffsetsLists?.push(offsets);
688+
this.#tmpOffsetsLists.push(offsets);
688689
// only one element in original colours
689690
const originalValues = command.getOriginalValuesLists();
690-
if (originalValues !== undefined) {
691-
this.#tmpOriginalValuesLists?.push(originalValues[0]);
691+
if (typeof originalValues !== 'undefined') {
692+
this.#tmpOriginalValuesLists.push(originalValues[0]);
692693
}
693694
}
694695

@@ -708,7 +709,7 @@ export class Brush extends EventTarget {
708709
const sourceGeometry = sourceImage.getGeometry();
709710

710711
const imgK = sourceGeometry.worldToIndex(position).get(2);
711-
if (imgK === undefined) {
712+
if (typeof imgK === 'undefined') {
712713
throw new Error('Z position is undefined');
713714
}
714715
const index = new Index([0, 0, imgK]);
@@ -786,8 +787,8 @@ export class Brush extends EventTarget {
786787
const config = dataConfigs[key].find(function (item) {
787788
return item.divId === divId;
788789
});
789-
if (config !== undefined) {
790-
orient = config?.orientation;
790+
if (typeof config !== 'undefined') {
791+
orient = config.orientation;
791792
break;
792793
}
793794
}
@@ -801,7 +802,7 @@ export class Brush extends EventTarget {
801802
*/
802803
#displayMask(divId) {
803804
// check mask data id
804-
if (this.#maskDataId === undefined) {
805+
if (typeof this.#maskDataId === 'undefined') {
805806
throw new Error(ERROR_MESSAGES.brush.cannotDisplayMask);
806807
}
807808
const viewConfig = new ViewConfig(divId);
@@ -825,15 +826,15 @@ export class Brush extends EventTarget {
825826
}
826827
// DerivationImageSequence (0008,9124)
827828
const derivationImages = frameInfos[0].derivationImages;
828-
if (derivationImages === undefined) {
829+
if (typeof derivationImages === 'undefined') {
829830
return dataUid;
830831
}
831832
if (derivationImages.length === 0) {
832833
return dataUid;
833834
}
834835
// SourceImageSequence (0008,2112)
835836
const sourceImages = derivationImages[0].sourceImages;
836-
if (sourceImages === undefined) {
837+
if (typeof sourceImages === 'undefined') {
837838
return dataUid;
838839
}
839840
if (sourceImages.length === 0) {
@@ -877,7 +878,7 @@ export class Brush extends EventTarget {
877878
*/
878879
#getLayerGroupMaskViewLayer(layerGroup) {
879880
// check mask data id
880-
if (this.#maskDataId === undefined) {
881+
if (typeof this.#maskDataId === 'undefined') {
881882
throw new Error(ERROR_MESSAGES.brush.cannotGetMaskLayers);
882883
}
883884

@@ -903,11 +904,11 @@ export class Brush extends EventTarget {
903904
* @returns {Image} The image.
904905
*/
905906
#getMaskImage(maskDataId) {
906-
if (maskDataId === undefined) {
907+
if (typeof maskDataId === 'undefined') {
907908
throw new Error(ERROR_MESSAGES.brush.noMaskId);
908909
}
909910
const maskData = this.#app.getData(maskDataId);
910-
if (maskData === undefined) {
911+
if (typeof maskData === 'undefined') {
911912
throw new Error(ERROR_MESSAGES.brush.noMaskImageGetOffset);
912913
}
913914
return maskData.image;
@@ -925,7 +926,7 @@ export class Brush extends EventTarget {
925926
const layerGroup = this.#app.getLayerGroupByDivId(
926927
layerDetails.groupDivId
927928
);
928-
if (layerGroup === undefined) {
929+
if (typeof layerGroup === 'undefined') {
929930
throw new Error('No layergroup to get mask offsets');
930931
}
931932
this.#currentLayerGroup = layerGroup;
@@ -936,7 +937,7 @@ export class Brush extends EventTarget {
936937
} else {
937938
viewLayer = layerGroup.getViewLayersByDataId(this.#maskDataId)[0];
938939
}
939-
if (viewLayer === undefined) {
940+
if (typeof viewLayer === 'undefined') {
940941
return [];
941942
}
942943
const viewController = viewLayer.getViewController();
@@ -985,12 +986,12 @@ export class Brush extends EventTarget {
985986
// create mask (sets this.#mask)
986987
this.#maskDataId = this.#createMask(sourcePosition, sourceImage);
987988
// check
988-
if (this.#mask === undefined) {
989+
if (typeof this.#mask === 'undefined') {
989990
throw new Error(ERROR_MESSAGES.brush.noCreatedMaskImage);
990991
}
991992
// display mask
992993
const divId = layerGroup.getDivId();
993-
if (divId !== undefined) {
994+
if (typeof divId !== 'undefined') {
994995
this.#displayMask(divId);
995996
}
996997
// newly create mask case: find the SEG view layer
@@ -1062,12 +1063,12 @@ export class Brush extends EventTarget {
10621063
const layerGroup = this.#app.getLayerGroupByDivId(
10631064
layerDetails.groupDivId
10641065
);
1065-
if (layerGroup === undefined) {
1066+
if (typeof layerGroup === 'undefined') {
10661067
throw new Error('No layergroup to check black list');
10671068
}
10681069
const drawLayer = layerGroup.getActiveDrawLayer();
10691070

1070-
if (drawLayer === undefined) {
1071+
if (typeof drawLayer === 'undefined') {
10711072
const viewLayer = layerGroup.getActiveViewLayer();
10721073
const referenceDataId = viewLayer.getDataId();
10731074
const referenceData = this.#app.getData(referenceDataId);
@@ -1154,7 +1155,7 @@ export class Brush extends EventTarget {
11541155
if (!this.#started) {
11551156
return;
11561157
}
1157-
if (this.#startPoint === undefined) {
1158+
if (typeof this.#startPoint === 'undefined') {
11581159
return;
11591160
}
11601161
const mousePoint = new Point2D(event.offsetX, event.offsetY);
@@ -1179,13 +1180,13 @@ export class Brush extends EventTarget {
11791180
this.#started = false;
11801181
this.#removeEraserOnRightMousedown(_event);
11811182

1182-
if (this.#maskDataId === undefined) {
1183+
if (typeof this.#maskDataId === 'undefined') {
11831184
throw new Error(ERROR_MESSAGES.brush.cannotDrawNoMaskId);
11841185
}
1185-
if (this.#tmpOffsetsLists === undefined) {
1186+
if (typeof this.#tmpOffsetsLists === 'undefined') {
11861187
throw new Error(ERROR_MESSAGES.brush.cannotDrawNoOffset);
11871188
}
1188-
if (this.#tmpOriginalValuesLists === undefined) {
1189+
if (typeof this.#tmpOriginalValuesLists === 'undefined') {
11891190
throw new Error(ERROR_MESSAGES.brush.cannotDrawNoColourList);
11901191
}
11911192

@@ -1278,10 +1279,10 @@ export class Brush extends EventTarget {
12781279
* @returns {ViewLayer} The mask view layer.
12791280
*/
12801281
#getMaskViewLayer() {
1281-
if (this.#maskDataId === undefined) {
1282+
if (typeof this.#maskDataId === 'undefined') {
12821283
throw new Error(ERROR_MESSAGES.brush.cannotGetMaskVCNoMaskId);
12831284
}
1284-
if (this.#currentLayerGroup === undefined) {
1285+
if (typeof this.#currentLayerGroup === 'undefined') {
12851286
throw new Error('No current layer group');
12861287
}
12871288

@@ -1395,18 +1396,18 @@ export class Brush extends EventTarget {
13951396
* @param {object} features The list of features.
13961397
*/
13971398
setFeatures(features) {
1398-
if (features.brushSizeRange !== undefined) {
1399+
if (typeof features.brushSizeRange !== 'undefined') {
13991400
this.#brushSizeRange = features.brushSizeRange;
14001401
}
14011402
if (
1402-
features.brushSize !== undefined &&
1403+
typeof features.brushSize !== 'undefined' &&
14031404
features.brushSize >= this.#brushSizeRange.min &&
14041405
features.brushSize < this.#brushSizeRange.max
14051406
) {
14061407
this.#brushSize = features.brushSize;
14071408
}
14081409

1409-
if (features.brushMode !== undefined) {
1410+
if (typeof features.brushMode !== 'undefined') {
14101411
this.#brushMode = features.brushMode;
14111412
}
14121413

@@ -1415,16 +1416,16 @@ export class Brush extends EventTarget {
14151416
// just changing the brushSize
14161417
if (features.createMask) {
14171418
this.#maskDataId = undefined;
1418-
} else if (features.maskDataId !== undefined) {
1419+
} else if (typeof features.maskDataId !== 'undefined') {
14191420
this.#maskDataId = features.maskDataId;
14201421
}
14211422

14221423
// used in draw events
1423-
if (features.selectedSegmentNumber !== undefined) {
1424+
if (typeof features.selectedSegmentNumber !== 'undefined') {
14241425
this.#selectedSegmentNumber = features.selectedSegmentNumber;
14251426
}
14261427

1427-
if (features.blacklist !== undefined) {
1428+
if (typeof features.blacklist !== 'undefined') {
14281429
this.#blacklist = features.blacklist;
14291430
}
14301431
}

0 commit comments

Comments
 (0)