Skip to content

Commit 904323f

Browse files
authored
Merge pull request #112 from jgrewe/axis
fix dimension.axis methods LGTM
2 parents 58f60a1 + 6169ab0 commit 904323f

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

+nix/RangeDimension.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
end
2020

2121
function tickAt = tick_at(obj, index)
22+
if index > 0
23+
index = index - 1;
24+
end
2225
func_name = strcat(obj.alias, '::tick_at');
23-
tickAt = nix_mx(func_name, obj.nix_handle, index);
26+
tickAt = nix_mx(func_name, obj.nix_handle, uint64(index));
2427
end
2528

2629
function indexOf = index_of(obj, position)
@@ -32,9 +35,12 @@
3235
if nargin < 3
3336
startIndex = 0;
3437
end
38+
if(startIndex > 0)
39+
startIndex = startIndex - 1;
40+
end
3541

3642
func_name = strcat(obj.alias, '::axis');
37-
axis = nix_mx(func_name, obj.nix_handle, count, startIndex);
43+
axis = nix_mx(func_name, obj.nix_handle, uint64(count), uint64(startIndex));
3844
end
3945

4046
end

+nix/SampledDimension.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@
2424
end
2525

2626
function posAt = position_at(obj, index)
27+
if index > 0
28+
index = index - 1;
29+
end
2730
func_name = strcat(obj.alias, '::position_at');
28-
posAt = nix_mx(func_name, obj.nix_handle, index);
31+
posAt = nix_mx(func_name, obj.nix_handle, uint64(index));
2932
end
3033

3134
function axis = axis(obj, count, startIndex)
3235
if nargin < 3
3336
startIndex = 0;
3437
end
35-
38+
if startIndex > 0
39+
startIndex = startIndex - 1;
40+
end
3641
func_name = strcat(obj.alias, '::axis');
37-
axis = nix_mx(func_name, obj.nix_handle, count, startIndex);
42+
axis = nix_mx(func_name, obj.nix_handle, uint64(count), uint64(startIndex));
3843
end
3944
end
4045
end
41-
46+

tests/TestDimensions.m

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@
4141
assert(isempty(d1.unit));
4242
assert(d1.samplingInterval == 200);
4343
assert(isempty(d1.offset));
44-
44+
45+
axis = d1.axis(10, 0);
46+
assert(axis(1) == 0);
47+
assert(length(axis) == 10);
48+
assert(axis(end) == (length(axis) - 1) * d1.samplingInterval);
49+
4550
d1.label = 'foo';
4651
d1.unit = 'mV';
4752
d1.samplingInterval = 325;
@@ -52,6 +57,14 @@
5257
assert(d1.samplingInterval == 325);
5358
assert(d1.offset == 500);
5459

60+
axis = d1.axis(10, 0);
61+
assert(axis(1) == d1.offset);
62+
assert(length(axis) == 10);
63+
assert(axis(end) == (length(axis) - 1) * d1.samplingInterval + d1.offset);
64+
65+
assert(d1.position_at(0) == d1.offset);
66+
assert(d1.position_at(10) == d1.offset + 9 * d1.samplingInterval);
67+
5568
d1.label = '';
5669
d1.unit = '';
5770
d1.offset = 0;
@@ -60,6 +73,13 @@
6073
assert(isempty(d1.unit));
6174
assert(d1.samplingInterval == 325);
6275
assert(d1.offset == 0);
76+
77+
axis = d1.axis(10, 0);
78+
assert(axis(1) == 0);
79+
assert(axis(end) == (length(axis) - 1) * d1.samplingInterval + d1.offset);
80+
81+
assert(d1.position_at(0) == d1.offset);
82+
assert(d1.position_at(10) == d1.offset + 9 * d1.samplingInterval);
6383
end
6484

6585
function [] = test_range_dimension( varargin )
@@ -75,7 +95,15 @@
7595
assert(isempty(d1.label));
7696
assert(isempty(d1.unit));
7797
assert(isequal(d1.ticks, ticks));
78-
98+
99+
axis = d1.axis(3, 0);
100+
assert(axis(1) == ticks(1));
101+
assert(length(axis) == 3);
102+
assert(axis(end) == ticks(length(axis)));
103+
104+
assert(d1.tick_at(0) == ticks(1));
105+
assert(d1.tick_at(3) == ticks(3));
106+
79107
new_ticks = [5 6 7 8];
80108
d1.label = 'foo';
81109
d1.unit = 'mV';

0 commit comments

Comments
 (0)