Hi Martin,
OK, I think I understand what the comparator is made for now.
It seems to me that a relation like s1 < s2 <==> s1 lies on the left of s2
can't define a total order on its own (without any other constraint),
but that it makes sense in the context of segments crossed by a
stabbing line.
I would suggest that the compareTo method is not directly associated
to the DepthSegment class, but that sort method always relies on a
comparator which would use the stabbing line as an argument.
What would you think of such a Comparator :
class StabbingLineComparator implements Comparator {
double y;
StabbingLineComparator(Coordinate c) {
y = c.y;
}
int compare(Object o1, Object o2) {
// assertions about o1 and o2
LineSegment line1 = ((DepthSegment)o1).getUpwardSegment();
LineSegment line2 = ((DepthSegment)o2).getUpwardSegment();
// handle properly the case where line1 is horizontal (p0.y = p1.y)
double x1 = line1.p0.x + (line1.p1.x-line1.p0.x) * (y-line1.p0.y) /
(line1.p1.y - line1.p0.y);
// handle properly the case where line2 is horizontal (p0.y = p1.y)
double x2 = line2.p0.x + (line2.p1.x-line2.p0.x) * (y-line2.p0.y) /
(line2.p1.y - line2.p0.y);
return Double.compare(x1, x2);
}
}
Collections.sort(stabbedSegments, new StabbingLineComparator(c));
Michaƫl
The ordering was made to allow determining the "depth" of subgraphs
which are nested within other graphs. This corresponds to a situation
where the buffer creates holes within polygons and polygons nested
within holes. When a disjoint graph is encountered, a stabbing line
is constructed from the righmost segment, and all segments in other
subgraphs which intersect this are found. The minimum one is then
computed - this is what the ordering is used for.
By linear ordering I really mean a total ordering of segments which:
(a) determines the leftmost segment in a set
(b) obeys the general contract for Comparator.
LineSegment#compareTo satifies (b), but not (a) (it's just a
lexocographic ordering by endpoint, which doesn't handle the case
where the segments lie "close together" (i.e. their envelopes
overlap). For instance, the following ASCII diagram shows a situation
where A is left of B but would be greater than B under the LineSegment
order:
| /
A | /
/
/ B
/
On Thu, Feb 5, 2015 at 1:47 PM, Michael Michaud
<[email protected] <mailto:[email protected]>> wrote:
Hi Martin,
The DepthSegment compareTo still does not obey the contract,
unfortunately. It's difficult to come up with a consistent
linear ordering for 2D segments.
It would be great if someone can build this and give it a test
with real data.
What is this ordering made for, and what do you mean by linear
ordering ? Isn't LineSegment#compareTo method enough to get a
strict ordering over segments for example ?
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Jts-topo-suite-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user