[Geom4j-developer] SF.net SVN: geom4j:[28] trunk/src/net/sourceforge/geom4j/ SegmentIntersectionAlg
Status: Pre-Alpha
Brought to you by:
skhenkin
From: <skh...@us...> - 2010-01-15 15:23:27
|
Revision: 28 http://geom4j.svn.sourceforge.net/geom4j/?rev=28&view=rev Author: skhenkin Date: 2010-01-15 15:23:21 +0000 (Fri, 15 Jan 2010) Log Message: ----------- "Stars" test added Modified Paths: -------------- trunk/src/net/sourceforge/geom4j/SegmentIntersectionAlgorithmTest.java Modified: trunk/src/net/sourceforge/geom4j/SegmentIntersectionAlgorithmTest.java =================================================================== --- trunk/src/net/sourceforge/geom4j/SegmentIntersectionAlgorithmTest.java 2010-01-15 07:45:33 UTC (rev 27) +++ trunk/src/net/sourceforge/geom4j/SegmentIntersectionAlgorithmTest.java 2010-01-15 15:23:21 UTC (rev 28) @@ -212,6 +212,15 @@ @Test public void testRandomFullGraph() { + /* + * Test for segment sets of a full graph like this (N=4): + * +----+ + * |\ /| + * | \/ | + * | /\ | + * |/ \| + * +----+ + */ final int N = 3; // number of vertices in the graph final double X1 = 0, X2 = 1000, Y1 = 0, Y2 = 1000; // generate random point set @@ -255,7 +264,45 @@ SegmentIntersectionAlgorithm.NAIVE, SegmentIntersectionAlgorithm.BENTLEY_OTTMANN); } + + @Test + public void testRandomStars() { + /* + * Test for a set of "stars" (groups of segments that + * intersect in one points), e.g.: + * + * \ | / \ | / \ | / + * \|/ \|/ \|/ + * ---*--- ---*--- ---*--- + * /|\ /|\ /|\ + * / | \ / | \ / | \ + * + */ + final int N = 30; // number of stars + final int K = 30; // number of segments in each star + final double Y = 100; + final double R = 100; + PointSet intersections = new PointSet(); + SegmentSet ss = new SegmentSet(); + Random r = new Random(); + for (int i = 0; i < N; i++) { + double x = i*R*3; + intersections.add(new Point(x, Y)); + for (int j = 0; j < K; j++) { + double x1 = x + r.nextDouble()*2*R - R; + double y1 = Y + r.nextDouble()*2*R - R; + double x2 = 2*x - x1; + double y2 = 2*Y - y1; + ss.add(new Segment(new Point(x1, y1), new Point(x2, y2))); + } + } + PointSet naiveSet = ss.getAllIntersectionPoints(SegmentIntersectionAlgorithm.NAIVE); + assertEquals(intersections, naiveSet); + PointSet boSet = ss.getAllIntersectionPoints(SegmentIntersectionAlgorithm.BENTLEY_OTTMANN); + assertEquals(naiveSet, boSet); + } + private void assertEqualResults(double[][] segmentCoordinates, SegmentIntersectionAlgorithm alg1, SegmentIntersectionAlgorithm alg2) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |