[OpenMap Users] GeoRegion containment?

From: Carsten Ø. Madsen <com_at_navicon.dk>
Date: Fri, 16 Nov 2007 15:32:54 +0100

Hello

I'm trying to use the GeoRegion.Impl class to determine if one region is
contained within the other but I can not make it work.

Here is my code. Notice that awt.geom version seems to work.

Any hints?

import java.awt.geom.GeneralPath;
import java.util.List;

import junit.framework.TestCase;

import com.bbn.openmap.geo.GeoRegion;
import com.bbn.openmap.geo.GeoSegment;
import com.bbn.openmap.geo.Intersection;

public class GeoRegionTest extends TestCase {

    static final float[] outer = new float[] { 10f, 0f, 10f, 10f, 0f,
10f, 0f,
            0f, 10f, 0f };

    static final float[] inner = new float[] { 5f, 1f, 5f, 5f, 1f, 5f,
1f, 1f,
            5f, 1f };

    public void testRegionContains() throws Exception {
        GeoRegion.Impl r1 = new GeoRegion.Impl(outer);
        GeoRegion.Impl r2 = new GeoRegion.Impl(inner);
        List l = Intersection.segmentNearPolyRegion(new GeoSegment.Impl(r2
                .toPointArray()), r1.toPointArray(), 1d);
        assertEquals(l != null, true);
        assertEquals(l.size(), 0);
    }

    public void testPathContains() {
        GeneralPath outerP = makePoly(outer);
        GeneralPath innerP = makePoly(inner);
        assertEquals(outerP.contains(innerP.getBounds2D()), true);
    }

    GeneralPath makePoly(float[] pts) {
        GeneralPath result = new GeneralPath();
        result.moveTo(pts[0], pts[1]);
        for (int i = 2; i < pts.length; i += 2) {
            result.lineTo(pts[i], pts[i + 1]);
        }
        return result;
    }
}

regards
CArsten

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Fri Nov 16 2007 - 09:36:26 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:08 EDT