Skip to content

Commit d6b59dc

Browse files
committed
Fix several methods setting the arc length property.
1 parent 27e1183 commit d6b59dc

File tree

6 files changed

+58
-10
lines changed

6 files changed

+58
-10
lines changed

Path2D.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
% See also PolygonPath, SplinePath.
5555

5656
properties (SetAccess = protected)
57-
% ISCIRCUIT - Logical indicating if path is a circuit
57+
% IsCircuit - Logical indicating if path is a circuit
5858
IsCircuit = false
5959
end
6060

@@ -70,6 +70,11 @@
7070
%PATH2D Construct a PATH2D class instance.
7171
end%Constructor
7272

73+
function obj = set.ArcLengths(obj, val)
74+
assert(numel(val) == obj.numel())
75+
obj.ArcLengths = val(:);
76+
end%fcn
77+
7378
function s = cumlengths(obj)
7479
% CUMLENGTHS Cumulative path segment lengths.
7580
% S = CUMLENGTHS(OBJ) returns the vector S of cumulative path

PolygonPath.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,11 @@
437437
% strictly increasing
438438
assert(all(diff(tau) > 0))
439439

440-
xyhcs = interp1(0:N-1, ...
440+
xyhcs = interp1(...
441441
[obj.x, obj.y, obj.head, obj.curv, obj.arcLengths0()], ...
442-
tau(:), varargin{:});
442+
tau(:) + 1, varargin{:});
443443
obj = PolygonPath(xyhcs(:,1), xyhcs(:,2), xyhcs(:,3), xyhcs(:,4));
444-
obj.ArcLengths = xyhcs(:,5);
444+
obj.ArcLengths = xyhcs(2:end,5);
445445

446446
end%fcn
447447

@@ -804,11 +804,14 @@
804804

805805
for i = 1:builtin('numel', obj)
806806
obji = obj(i);
807+
if obji.numel() < 1
808+
continue
809+
end
807810
obji.x = flip(obji.x);
808811
obji.y = flip(obji.y);
809812
obji.head = flip(obji.head) + pi;
810813
obji.curv = -flip(obji.curv);
811-
obji.ArcLengths = [-flip(obji.ArcLengths(1:end-1)); 0] + obji.length();
814+
obji.ArcLengths = cumsum(flip(diff(obji.arcLengths0())));
812815
obj(i) = obji;
813816
end%for
814817

SplinePath.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
breaks = obj.Breaks;
7878
coefs = obj.Coefs;
7979
arcLen = obj.ArcLengths;
80+
[~,P1] = obj.termPoints();
8081
breaks2 = obj2.Breaks;
8182
coefs2 = obj2.Coefs;
8283

@@ -88,10 +89,9 @@
8889
cat(3, zeros(2,n1,k2-k1), coefs), ...
8990
cat(3, zeros(2,n2,k1-k2), coefs2));
9091

91-
[~,P1] = obj.termPoints();
92-
P0 = obj2.termPoints();
93-
ds = sqrt( sum((P0 - P1).^2) );
94-
obj.ArcLengths = [arcLen; obj2.ArcLengths(2:end) + arcLen(end) + ds];
92+
dP = obj2.termPoints() - P1;
93+
ds = hypot(dP(1), dP(2));
94+
obj.ArcLengths = [arcLen; obj2.ArcLengths + arcLen(end) + ds];
9595

9696
end%fcn
9797

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="test" />
5+
</Category>
6+
</Info>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
classdef InterpTest < matlab.unittest.TestCase
2+
3+
methods (Test)
4+
function testInterpStraight(testCase)
5+
% Test interpolation of a straight path.
6+
7+
obj0 = PolygonPath.straight([0 0], [20 2]);
8+
[tau0,tau1] = obj0.domain();
9+
obj1 = obj0.interp(linspace(tau0, tau1, 100));
10+
11+
% The terminal points must match
12+
[exp0,exp1] = obj0.termPoints();
13+
[act0,act1] = obj1.termPoints();
14+
verifyEqual(testCase, act0, exp0);
15+
verifyEqual(testCase, act1, exp1);
16+
17+
% The length must match
18+
verifyEqual(testCase, obj1.length(), obj0.length())
19+
20+
end%fcn
21+
end
22+
23+
end%class

xUnitTests/SplinePath/AppendTestSpline.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@
33
methods (Test)
44
function testAppend(testCase)
55

6-
% Join two "arbitrary" single segment paths with different
6+
% Create two "arbitrary" single segment paths with different
77
% polynomial degrees
88
obj0 = SplinePath([0 1], reshape([1 2 1 0; 0 1 2 1], [2 1 4]));
99
[~,P1]= obj0.termPoints();
1010
obj1 = SplinePath.straight(P1, P1 + [10; 5]);
11+
12+
% This test assumes that the paths have no gap
13+
assert(isequal(P1, obj1.termPoints()))
14+
15+
% Join the two paths
1116
obj = obj0.append(obj1);
1217

1318
% Evaluation of appended path must return the same values as
1419
% evaluation of the original paths
1520
tau = linspace(0, 1, 101);
21+
22+
% - First segment
1623
[xAct,yAct] = obj.eval(tau);
1724
[xExp,yExp] = obj0.eval(tau);
1825
verifyEqual(testCase, xAct, xExp);
1926
verifyEqual(testCase, yAct, yExp);
2027

28+
% - Second segment
2129
[xAct,yAct] = obj.eval(tau + obj.Breaks(2));
2230
[xExp,yExp] = obj1.eval(tau);
2331
verifyEqual(testCase, xAct, xExp, 'AbsTol',2e-15);
2432
verifyEqual(testCase, yAct, yExp, 'AbsTol',2e-15);
33+
34+
% The path lengths must match
35+
verifyEqual(testCase, obj.length(), obj0.length() + obj1.length())
2536
end%fcn
2637
end
2738

0 commit comments

Comments
 (0)