Modify

Opened 10 years ago

Closed 4 years ago

Last modified 4 years ago

#10205 closed defect (fixed)

[Patch]Strange align nodes in circle behavior

Reported by: naoliv Owned by: GerdP
Priority: normal Milestone: 20.12
Component: Core Version:
Keywords: Cc:

Description

With the attached example, select the way tagged with FIXME=curve and then press o (align nodes in circle)
See how it wrongly transforms its shape

JOSM:

Repository Root: http://josm.openstreetmap.de/svn
Build-Date: 2014-06-26 01:35:33
Last Changed Author: bastiK
Revision: 7271
Repository UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
URL: http://josm.openstreetmap.de/svn/trunk
Last Changed Date: 2014-06-25 21:02:07 +0200 (Wed, 25 Jun 2014)
Last Changed Rev: 7271

Identification: JOSM/1.5 (7271 pt_BR) Linux Debian GNU/Linux unstable (sid)
Memory Usage: 824 MB / 1756 MB (429 MB allocated, but free)
Java version: 1.7.0_55, Oracle Corporation, OpenJDK 64-Bit Server VM
Java package: openjdk-7-jre:amd64-7u55-2.4.7-2
VM arguments: [-Djava.net.useSystemProxies=true, -Dawt.useSystemAAFontSettings=on]
Dataset consistency test: No problems found

Plugin: AddrInterpolation (30416)
Plugin: Create_grid_of_ways (30416)
Plugin: FixAddresses (30416)
Plugin: ImageryCache (30416)
Plugin: OpeningHoursEditor (30416)
Plugin: PicLayer (30436)
Plugin: SimplifyArea (30416)
Plugin: buildings_tools (30485)
Plugin: editgpx (30416)
Plugin: geochat (30416)
Plugin: geotools (30416)
Plugin: jts (30416)
Plugin: merge-overlap (30416)
Plugin: notes (v0.9.2)
Plugin: opendata (30436)
Plugin: pdfimport (30416)
Plugin: poly (30495)
Plugin: reverter (30436)
Plugin: tagging-preset-tester (30416)
Plugin: todo (29154)
Plugin: turnrestrictions (30454)
Plugin: undelete (30416)
Plugin: utilsplugin2 (30460)

Attachments (7)

example.osm.bz2 (2.7 KB ) - added by naoliv 10 years ago.
bad-polygon.jpg (25.7 KB ) - added by Balaitous 9 years ago.
When the way is closed, it is not possible to determine anticlockwise order for nodes.
10205-beta.patch (12.9 KB ) - added by GerdP 4 years ago.
work in progress
josm_10205_align_nodes_in_polygon_playground.osm.xz (4.9 KB ) - added by skyper 4 years ago.
playground with some examples
10205-beta-2.patch (60.8 KB ) - added by GerdP 4 years ago.
10205.2.patch (64.6 KB ) - added by GerdP 4 years ago.
josm_10205_self_intersecting_example.osm (1.1 KB ) - added by skyper 4 years ago.
example for self-intersecting results

Download all attachments as: .zip

Change History (39)

by naoliv, 10 years ago

Attachment: example.osm.bz2 added

comment:1 by Balaitous, 9 years ago

Bug is due to collectNodesAnticlockwise algorithm.
It doesn't work because the polygon that close the way is self-crossing, and return nodes in clockwise order.
See bad-polygon.jpg

This function was introduce in r6919 for #8431 and #9839.

by Balaitous, 9 years ago

Attachment: bad-polygon.jpg added

When the way is closed, it is not possible to determine anticlockwise order for nodes.

comment:2 by GerdP, 4 years ago

Found this while working on #20041. Please check the result that you get when you select the nodes of the FIXME way instead of the way. Is that the result you expected?

comment:3 by GerdP, 4 years ago

The current code adds a temporate node to calculate the direction of an unclosed way. This calculation fails when the resulting way is self-crossing. It is easy to detect the self-crossing but I am not sure what to do when it was detected.

  • show a notification like "Selection could not be used to align in circle." or maybe
  • ignore the direction and use the result that is calculated when the way nodes are selected.

comment:4 by skyper, 4 years ago

Why are the end nodes moved in both cases?

Even with only nodes selected the result looks strange to me. The movement of the middle nodes is too much and the radius too small.

I would like to get a result similar to:

  1. Select way and middle node with connection and Disconnect node from way
  2. Select way and align in circle
  3. Select previous disconnected node and move onto way

Nodes close to one end are weighted too much in my opinion.

Would show a notification and leave these situations for other action like circle arc or spline.

comment:5 by GerdP, 4 years ago

Why are the end nodes moved in both cases?

What do you mean with both cases?
If only nodes are selected there is no "end node", the algo simply calculates the center of the four nodes, then the avg. distance of the nodes to that center as radius and then moves each node so that it lies on the virtual line with this center and radius.

Nodes close to one end are weighted too much in my opinion.

Hm, I don't think that we can simply ignore nodes which are close to the end, but you are right that the result is far from expected. I assume this is always the case when the nodes are almost on a straight line. A human probably recognizes the circular pattern because of the other ways but the algo just looks at the selected nodes.
I'll add the test to reject this selection as suggested in comment:3

comment:6 by GerdP, 4 years ago

Owner: changed from team to GerdP
Status: newassigned

comment:7 by GerdP, 4 years ago

I assume this is always the case when the nodes are almost on a straight line.

It's quite strange, (both with tested and with r17386):

  • When I select the 4 nodes of the original way and use "merge selection" so that I have only those nodes in a new layer the result looks very different and more like you expected.
  • When I use copy & "paste at source position" the result looks as in the complete data.

Will look again at this tomorrow...

comment:8 by GerdP, 4 years ago

Ah, quite simple. The order of the nodes changes and thus the calculation of the center. That's why the algo tries to sort the nodes in counter clockwise order.

in reply to:  5 comment:9 by skyper, 4 years ago

Replying to GerdP:

Why are the end nodes moved in both cases?

What do you mean with both cases?
If only nodes are selected there is no "end node", the algo simply calculates the center of the four nodes, then the avg. distance of the nodes to that center as radius and then moves each node so that it lies on the virtual line with this center and radius.

Sorry, you are right, with only nodes it is just the wrong action to use.

Nodes close to one end are weighted too much in my opinion.

Hm, I don't think that we can simply ignore nodes which are close to the end, but you are right that the result is far from expected. I assume this is always the case when the nodes are almost on a straight line. A human probably recognizes the circular pattern because of the other ways but the algo just looks at the selected nodes.
I'll add the test to reject this selection as suggested in comment:3

Hmh, maybe, nodes on the "wrong" side can be ignored in these cases and only the nodes on the side with more distance to a straight line be used.

comment:10 by GerdP, 4 years ago

It's quite tricky. The method Geometry.getCenter() is used to calculate the center of the circle. IIGTR the algo used in this method is meant to be used with the nodes of a polygon which is not self-intersecting, the order of the nodes would be that of a closed way (first node == last node)
If only nodes are selected the code in AlignInCircleAction doesn't sort the nodes and thus the result of the center calculation is more or less unpredictable. The code itself documents this a possible selection: "Align these nodes, all are fix" but obviously the code doesn't work well and this selection is also not documented in the wiki wiki:Help/Action/AlignInCircle
I see no real use case for this selection, so I think we should simply reject a selection that contains only nodes.

Last edited 4 years ago by GerdP (previous) (diff)

comment:11 by GerdP, 4 years ago

The tested version r17329 as well as latest r17386 also don't complain when a P-shaped way is selected, result of action is garbage.

comment:12 by GerdP, 4 years ago

reg. end nodes of an unclosed way:
The current code doesn't fix them completely, they may be moved to or away from the calculated center. This is now different to "More tools -> Circle arc" action from utilsplugin2.
This also happens for roundabout ways. Sonetimes "fixed" nodes have to be moved.
For unclosed ways sometimes the better solution seems to be creating a new circle as a temporary helper line and move the existing nodes closer to that.
It probably the same iteration process as rectifying angles in buildings where some angles are not 90°.

by GerdP, 4 years ago

Attachment: 10205-beta.patch added

work in progress

comment:13 by skyper, 4 years ago

Ok, reg end nodes, it is just the wrong action for this use case and Circle arc is the one to use.
No doubt about moving "fixed nodes" but only to the arc without distributing preserving angles if possible.

Regarding only nodes, I still like the option. If finding the proper center is a problem, how about sticking to the selection order or define the first two as "diameter" and the rest are only corner nodes?

comment:14 by GerdP, 4 years ago

Regarding only nodes, I still like the option. If finding the proper center is a problem, how about sticking to the selection order or define the first two as "diameter" and the rest are only corner nodes?

Do you have a use case? Something like natural=tree arranged in a circle maybe?

We can still allow it but it would require a different algo to calculate the center. I would simply calculate the avg. lat and avg. lon, similar to getNodesCenter()in source:/josm/trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java

Edit: Problem with this simple algo is that a repeated action moves all nodes again. So, if you don't find a good use for this I'll remove the support.

Last edited 4 years ago by GerdP (previous) (diff)

comment:15 by skyper, 4 years ago

A simple case is a pier as area with one end as circle arc or a big sundial with hour marks.

Many historical monuments with astronomical background are other examples and in architecture you will find polygons inside polygons. Vauban is famous for that, e.g. Neuf-Brisach

comment:16 by GerdP, 4 years ago

I don't get it. In what situation do you select 4 or more nodes and press O to arrange them? And what do you expect?

by skyper, 4 years ago

playground with some examples

comment:17 by skyper, 4 years ago

I would expect regular polygons just like if I select a way with these nodes.

I thought, it can help to preserve shapes of complex polygons and polygons only part of a way or even virtual polygons like the aligned walls and polygons in Neuf-Brisach. Playing around, I see that it does not work and I still have to use helper lines for the rectangles and the polygons.

Right now, I am not sure if this is the proper action to use. I do not like that all nodes are moved if only one or two of many have an offset but that is calling for a new action. On the other hand, we do not have any action for regular shapes besides Orthogonalize shape which fails completely with an uneven number of corner nodes.

See my playground with some simple examples of regular shapes.

Last edited 4 years ago by skyper (previous) (diff)

comment:18 by GerdP, 4 years ago

I do not like that all nodes are moved if only one or two of many have an offset

That's what I thought. Without any selected way it is not possible to define the wanted center.

by GerdP, 4 years ago

Attachment: 10205-beta-2.patch added

comment:19 by GerdP, 4 years ago

  • don't allow selection that contains no ways
  • improve test coverage (todo: outside download area)
  • simplify code
  • patch adds test data with various combinations (alignCircleCases.osm), valid or not.

I wasn't sure how to handle the case that both a center is given and two nodes of the way(s) are selected. (sel=7) I decided that this means the two way nodes define only the diameter. The unpatched code ignored this special case.
The wiki doesn't yet document the special meaning of two selected way nodes.

comment:20 by GerdP, 4 years ago

Reg. selection that contains only nodes: We could allow that if there is exactly one way which has all selected nodes as children.
No, I don't like that as well since the result is very different to the old current behaviour.
This action is really a brain teaser ;)
My understanding is this: the algo which caculates the move commands needs a center point and a radius and one or mode nodes which should be moved. My findings so far:

  • We must reject all selections which don't allow to find the center and radius.
  • the center can be specified by the user, either by selecting a single node that is not on the modified way(s) or by selecting one or more ways which form a closed ring and exactly two nodes of the way/these ways. This method gives the diameter and - if not yet known - the center for the circle.
  • If the center is not known a 2nd algo Geometry.getCenter() tries to calculate it. This algo needs at least 4 nodes and the nodes must match certain criteria, e.g. a (virtually closed) way that is drawn along the nodes in the given order must not be self intersecting, else this 2nd algo may calculate a wrong center. So, the order of the move-nodes is important. Different methods to select the nodes may produce different orders, and the user has no way to check this order without a debugging tool :( The only way to select the nodes in a specific order seems to be to select them one after the other in the wanter order.
  • if no center is given and the 2nd algo failed we must stop with a message like "Cannot determine center of circle for this geometry."
  • if a center is known the radius is calculated as average distance to each node from the center
  • selected move-nodes are fixed, means "angle relative to center should not be modified"
Last edited 4 years ago by GerdP (previous) (diff)

by GerdP, 4 years ago

Attachment: 10205.2.patch added

comment:21 by GerdP, 4 years ago

10205.2.patch adds robustness and unit test

  • if only nodes and no way are selected, order the nodes using the angle to the agv. east-north position. This should produce a predictable result
  • a center node can be selected also when one unclosed way is selected. This allows to get a better result for example.osm.bz2
  • if way(s) are selected the order the nodes is determined by the occurence in the way(s). Self-Intersecting polygons are rejected if no center node is given

I'll commit this tomorrow if nobody complains.

comment:22 by GerdP, 4 years ago

Milestone: 20.12
Summary: Strange align nodes in circle behavior[Patch]Strange align nodes in circle behavior

comment:23 by GerdP, 4 years ago

In 17393/josm:

see #10205: Strange align nodes in circle behavior

  • allow to define center node also when a single unclosed way is selected
  • add robustness and more unit tests for evaluation of valid selections
  • if only nodes and no way are selected, order the nodes using the angle to the agv. east-north position. This should produce a predictable result
  • if way(s) are selected the order the nodes is determined by the occurence in the way(s). Self-Intersecting polygons are rejected if no center node is given
  • don't throw InvalidSelection when selection is valid but no point was moved, let buildCommand() return null instead

With a selection that gives a center point and way(s) which are not even close to a circular shape the result might still be surprising. Sometimes the way nodes are arranged around the center node, sometimes they are moved so that a circle arc with nearly the same length is produced. The result changes significantly when the way nodes are also selected. Subject to further improvements.

comment:24 by skyper, 4 years ago

The difference is the result of using either a radius/diameter or a shorter chord.

I am wondering about the restriction to at least four nodes as three nodes already form a polygon.

Last edited 4 years ago by skyper (previous) (diff)

in reply to:  24 ; comment:25 by GerdP, 4 years ago

Replying to skyper:

The difference is the result of using either a radius/diameter or a shorter chord.

Not sure what you mean.

I am wondering about the restriction to at least four nodes as three nodes already form a polygon.

I agree that it looks strange, but when I allow just three nodes this will always return "nothing changed".

in reply to:  25 comment:26 by skyper, 4 years ago

Replying to GerdP:

Replying to skyper:

The difference is the result of using either a radius/diameter or a shorter chord.

Not sure what you mean.

Sorry, I was off. Thought, that there are two different ways to calculate the diameter of the underlying circle and that it changes when we only look at (circle) segments like open ways.

What surprised me, is the fact that it produces self-intersecting ways, now.

I am wondering about the restriction to at least four nodes as three nodes already form a polygon.

I agree that it looks strange, but when I allow just three nodes this will always return "nothing changed".

I see. It works with a way with only three child nodes if you select two way nodes in addition. So I can create triangles, nice. Probably, nothing we can do but proper document.

comment:27 by GerdP, 4 years ago

What surprised me, is the fact that it produces self-intersecting ways, now.

It should not unless the way(s) are already self-intersecting. Do you have an example?

by skyper, 4 years ago

example for self-intersecting results

in reply to:  27 comment:28 by skyper, 4 years ago

Replying to GerdP:

What surprised me, is the fact that it produces self-intersecting ways, now.

It should not unless the way(s) are already self-intersecting. Do you have an example?

See attachment:josm_10205_self_intersecting_example.osm​. Select the way and any one or two middle node(s) (B-E).

comment:29 by GerdP, 4 years ago

Are we talking about r17393?

comment:30 by GerdP, 4 years ago

Ah, yes, now I see. Result is the same for tested, right? I assume the method really only works well when the input is already close to the wanted geometry. I could add more tests to validate the result but we could also say garbage in -> garbage out ;)

Last edited 4 years ago by GerdP (previous) (diff)

comment:31 by skyper, 4 years ago

Yes, same result with tested and latest (r17391), has nothing to do with r17393.

Think the result should never be an self-intersecting way. The problem is that the order of way nodes is not in sync with the order on the virtual circle.

Anyway, sounds like a new enhancement (ticket) as you are right, we do not care about a correct selection for e.g. align in line either.
I am thinking about a new action to create regular polygons but with fixed end nodes and an ellipsoid instead of a circle.

Last edited 4 years ago by skyper (previous) (diff)

comment:32 by GerdP, 4 years ago

Resolution: fixed
Status: assignedclosed

I think the original ticket is fixed now. There is already a ticket for a new mapmode, see #2891. Maybe also #6385.

Last edited 4 years ago by GerdP (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain GerdP.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.