[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level |
Date: |
Mon, 25 Jul 2022 21:28:03 -0400 (EDT) |
Follow-up Comment #10, bug #39370 (project octave):
Good debugging.
I asked a question in comment #4 back in 2014 about whether there was any
actual effect from having duplicate points in the contour lines. I don't
think there is which means this may not be that important to fix this.
Quoting the example in comment #8:
>> x = 0:2;
>> y = x;
>> z = x' * y;
>> c = contourc (x, y, z, 2:3)
c =
2.0000 1.0000 2.0000 3.0000 1.5000 2.0000
2.0000 2.0000 1.0000 2.0000 2.0000 1.5000
>> b = contour (x, y, z, 2:3)
b =
Columns 1 through 7
2.0000 1.0000 1.0000 2.0000 2.0000 3.0000 1.5000
4.0000 2.0000 2.0000 1.0000 1.0000 2.0000 2.0000
Column 8
2.0000
1.5000
You have to understand the contourc format, but the first contour is the
points
(1, 2) (1, 2) (2, 1) (2, 1)
These points, in Octave, are used to directly create a patch object so the
duplication is unnecessary, but immaterial.
I also think this means we don't need to follow Matlab exactly. If the
uniquified matrix from contourc will work to produce a plot then we might as
well just settle on both routines producing the same matrix which is the
smaller one.
At least for starters, I would probably do the culling in contourc.m. It is
an m-file, and potentially slow, but the number of contours is not that large
(default is 10).
This would be approximately right Octave code
diff -r 7d4cf04665e6 scripts/plot/draw/contourc.m
--- a/scripts/plot/draw/contourc.m Wed Jul 20 16:37:58 2022 +0200
+++ b/scripts/plot/draw/contourc.m Mon Jul 25 18:25:21 2022 -0700
@@ -163,6 +163,28 @@ function [c, lev] = contourc (varargin)
endwhile
endif
+ ## Post-process to remove duplicate contour points
+ ## FIXME: Possibly better to do this in C++ code __contour__
+ i = j = 0;
+ c2 = zeros (size (c));
+ while (i < columns (c))
+ i++; j++;
+
+ lvl = c(1,i);
+ n = c(2,i);
+
+ ctmp = c(:, i+(1:n));
+ ctmp = unique (ctmp.', "rows", "stable").';
+ n2 = columns (ctmp);
+
+ c2(1,j) = lvl;
+ c2(2,j) = n2;
+ c2(:,j+(1:n2)) = ctmp;
+
+ i += n; j += n2;
+ endwhile
+ c = c2(:,1:j);
+
endfunction
Note that this won't catch points that differ by a few eps. One would need to
use uniquetol for that, but it doesn't appear to have a "stable" option.
(file #53472)
_______________________________________________________
Additional Item Attachment:
File name: contourc.diff Size:0 KB
<https://file.savannah.gnu.org/file/contourc.diff?file_id=53472>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?39370>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level, Nicholas Jankowski, 2022/07/22
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level, Nicholas Jankowski, 2022/07/25
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level, Nicholas Jankowski, 2022/07/25
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level,
Rik <=
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level, Rik, 2022/07/25
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level, Nicholas Jankowski, 2022/07/26
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level, Nicholas Jankowski, 2022/07/26
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level, Rik, 2022/07/26
- [Octave-bug-tracker] [bug #39370] contourc adds duplicates to the start and end of the 1st level, Nicholas Jankowski, 2022/07/26