Skip to content

Commit 79666f3

Browse files
committed
Return vector of kept waypoints from method simplify().
1 parent 08bd643 commit 79666f3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

PolygonPath.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,22 +879,25 @@
879879

880880
end%fcn
881881

882-
function obj = simplify(obj)
882+
function [obj,keep] = simplify(obj)
883883
%SIMPLIFY Simplify path.
884884
% OBJ = SIMPLIFY(OBJ) removes intermediate points from line
885885
% segments of the path OBJ.
886-
886+
%
887+
% [OBJ,KEEP] = SIMPLIFY(OBJ) returns a logical vector KEEP
888+
% indicating which waypoints are kept.
889+
887890
h = atan2(diff(obj.y), diff(obj.x));
888891
dh = [true; diff(h); true];
889892
keep = (dh ~= 0);
890-
893+
891894
obj.x = obj.x(keep);
892895
obj.y = obj.y(keep);
893896
obj.head = obj.head(keep);
894897
obj.curv = obj.curv(keep);
895898
obj.ArcLengths = obj.ArcLengths(keep(2:end));
896899
end%fcn
897-
900+
898901
function [tau,idx] = s2tau(obj, s)
899902

900903
sObj = obj.arcLengths0();

xUnitTests/PolygonPath/SimplifyTest.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function testLine(testCase)
77
% Create a line with intermediate points
88
obj0 = PolygonPath.xy2Path(0:10, 0:10);
99

10-
obj1 = obj0.simplify();
10+
[obj1,keep] = obj0.simplify();
1111

1212
% The terminal points must match
1313
[exp0,exp1] = obj0.termPoints();
@@ -20,6 +20,8 @@ function testLine(testCase)
2020

2121
% Exactly two points, i.e. one segment, must survive
2222
verifyEqual(testCase, obj1.numel(), 1)
23+
24+
verifySize(testCase, keep, [obj0.numel()+1 1])
2325
end%fcn
2426

2527
function testNothingToRemove(testCase)
@@ -31,7 +33,10 @@ function testNothingToRemove(testCase)
3133
[0 1 1 2 2 3 3 4 4], ...
3234
[0 0 1 1 2 2 3 3 4]);
3335

34-
verifyEqual(testCase, obj0, obj0.simplify())
36+
[obj1,keep] = obj0.simplify();
37+
38+
verifyEqual(testCase, obj0, obj1)
39+
verifySize(testCase, keep, [obj0.numel()+1 1])
3540
end%fcn
3641
end
3742

0 commit comments

Comments
 (0)