forked from cornerstonejs/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpageToPixel_test.js
More file actions
97 lines (77 loc) · 2.3 KB
/
Copy pathpageToPixel_test.js
File metadata and controls
97 lines (77 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { assert } from 'chai'; // eslint-disable-line import/extensions
import enable from '../src/enable.js';
import displayImage from '../src/displayImage.js';
import { getEnabledElement } from '../src/enabledElements.js';
import setViewport from '../src/setViewport.js';
import pageToPixel from '../src/pageToPixel.js';
import disable from '../src/disable.js';
describe('pageToPixel', function () {
beforeEach(function () {
// Arrange
this.element = document.createElement('div');
const height = 256;
const width = 256;
const getPixelData = () => new Uint8Array([0, 255, 255, 0]);
this.image = {
imageId: 'exampleImageId',
minPixelValue: 0,
maxPixelValue: 255,
slope: 1.0,
intercept: 0,
windowCenter: 127,
windowWidth: 256,
getPixelData,
rows: height,
columns: width,
height,
width,
color: false,
sizeInBytes: width * height * 2
};
this.viewport = {
scale: 1.0,
translation: {
x: 0,
y: 0
},
voi: {
windowWidth: 256,
windowCenter: 127
},
invert: false,
pixelReplication: false,
rotation: 0,
hflip: false,
vflip: false
};
});
it('should convert points in the page coordinate system to equivalent points in the pixel coordinate system', function () {
// Arrange
enable(this.element);
displayImage(this.element, this.image);
const element = this.element;
const enabledElement = getEnabledElement(this.element);
enabledElement.canvas.width = 256;
enabledElement.canvas.height = 256;
setViewport(element, this.viewport);
// Act
const convertedPoint = pageToPixel(element, 10, 10);
assert.deepEqual(convertedPoint, {
x: 10,
y: 10 });
});
it('should throw an error if the image is undefined', function () {
enable(this.element);
displayImage(this.element, this.image);
const element = this.element;
const enabledElement = getEnabledElement(this.element);
enabledElement.canvas.width = 256;
enabledElement.canvas.height = 256;
setViewport(element, this.viewport);
enabledElement.image = undefined;
assert.throws(() => pageToPixel(this.element, 10, 10));
});
afterEach(function () {
disable(this.element);
});
});