Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird duplication #8

Open
ccarouge opened this issue Aug 10, 2021 · 1 comment
Open

Weird duplication #8

ccarouge opened this issue Aug 10, 2021 · 1 comment

Comments

@ccarouge
Copy link
Member

The following code repeats itself:

frontdetection/fronts.py

Lines 151 to 190 in 250f598

while insearchdist:
mindist=np.inf
for jj in range(ptcount):
if not_used[jj]:
dist=sp_dist.euclidean((inpts[t]),(inpts[jj]))
if dist>0 and dist<mindist:
mindist=dist
rec=jj
distr=dist
#have found nearest unused point
if mindist<searchdist:
not_used[rec]=False
templat.append(inpts[rec,0])
templon.append(inpts[rec,1])
t=rec
else:
insearchdist=False
# search other direction
t=ii
insearchdist=True
while insearchdist:
mindist=np.inf
for jj in range(ptcount):
if not_used[jj]:
dist=sp_dist.euclidean((inpts[t]),(inpts[jj]))
if dist>0 and dist<mindist:
mindist=dist
rec=jj
distr=dist
#have found nearest unused point
if mindist<searchdist:
not_used[rec]=False
templat2.append(inpts[rec,0])
templon2.append(inpts[rec,1])
t=rec
else:
insearchdist=False
if len(templat2)>0:
templat=templat2[::-1]+templat
templon=templon2[::-1]+templon

We go twice through the list of points. Each time the code identifies all the points that are close enough to the point of interest and sort them from closest to farthest. I am not sure the second repetition will find anything since the first search seems to remove all the points that are close enough. The comment says "in the other direction" but the code doesn't seem to give a specific direction to the search.

There are probably ways to rewrite this more efficiently to get the same result as current. But we may need some more information on what the code is supposed to be doing afterwards to ensure the code is correct.

@ScottWales
Copy link

From what I understand, the problem is that you're not necessarily starting at the start of a line, just some random point on it. So going only one direction will not find the full line, you have to go back to the start location and try searching the other direction as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants