Skip to content

Commit

Permalink
[508439] Add tests for IMultiShape#toPath().
Browse files Browse the repository at this point in the history
  • Loading branch information
mwienand committed Dec 13, 2016
1 parent bcca6d6 commit 271a6d0
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*******************************************************************************
* Copyright (c) 2012, 2015 itemis AG and others.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*
* Contributors:
* Matthias Wienand (itemis AG) - initial API and implementation
*
*
*******************************************************************************/
package org.eclipse.gef.geometry.tests;

Expand All @@ -18,6 +18,7 @@

import org.eclipse.gef.geometry.internal.utils.PrecisionUtils;
import org.eclipse.gef.geometry.planar.Path;
import org.eclipse.gef.geometry.planar.Path.Segment;
import org.eclipse.gef.geometry.planar.Point;
import org.eclipse.gef.geometry.planar.Rectangle;
import org.eclipse.gef.geometry.planar.Region;
Expand Down Expand Up @@ -121,6 +122,41 @@ public void test_equals() {
assertFalse(r1.equals(r0));
}

@Test
public void test_toPath() {
// empty Region
Region region = new Region();
assertEquals(new Path(), region.toPath());

// one rectangle
region = new Region(new Rectangle(0, 0, 100, 50));
Path path = region.toPath();
Segment[] segs = path.getSegments();
assertEquals(6, segs.length);
assertEquals(Path.Segment.MOVE_TO, segs[0].getType());
assertEquals(Path.Segment.CLOSE, segs[5].getType());

// overlapping rectangles
region = new Region(new Rectangle(0, 0, 100, 100),
new Rectangle(50, 50, 100, 100));
path = region.toPath();
segs = path.getSegments();
assertEquals(12, segs.length);
assertEquals(Path.Segment.MOVE_TO, segs[0].getType());
assertEquals(Path.Segment.CLOSE, segs[11].getType());

// distinct rectangles
region = new Region(new Rectangle(0, 0, 50, 50),
new Rectangle(60, 60, 50, 50));
path = region.toPath();
segs = path.getSegments();
assertEquals(10, segs.length);
assertEquals(Path.Segment.MOVE_TO, segs[0].getType());
assertEquals(Path.Segment.CLOSE, segs[4].getType());
assertEquals(Path.Segment.MOVE_TO, segs[5].getType());
assertEquals(Path.Segment.CLOSE, segs[9].getType());
}

@Test
public void test_toPath_with_void() {
Region r = new Region(new Rectangle(0, 0, 200, 50),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*******************************************************************************
* Copyright (c) 2012, 2015 itemis AG and others.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*
* Contributors:
* Matthias Wienand (itemis AG) - initial API and implementation
*
*
*******************************************************************************/
package org.eclipse.gef.geometry.tests;

Expand All @@ -21,8 +21,10 @@

import org.eclipse.gef.geometry.planar.Line;
import org.eclipse.gef.geometry.planar.Path;
import org.eclipse.gef.geometry.planar.Path.Segment;
import org.eclipse.gef.geometry.planar.Point;
import org.eclipse.gef.geometry.planar.Polygon;
import org.eclipse.gef.geometry.planar.Rectangle;
import org.eclipse.gef.geometry.planar.Ring;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -105,6 +107,41 @@ public void equals() {

public static class ToPathTests {

@Test
public void toPath() {
// empty Region
Ring ring = new Ring();
assertEquals(new Path(), ring.toPath());

// one rectangle
ring = new Ring(new Rectangle(0, 0, 100, 50).toPolygon());
Path path = ring.toPath();
Segment[] segs = path.getSegments();
assertEquals(6, segs.length);
assertEquals(Path.Segment.MOVE_TO, segs[0].getType());
assertEquals(Path.Segment.CLOSE, segs[5].getType());

// overlapping rectangles
ring = new Ring(new Rectangle(0, 0, 100, 100).toPolygon(),
new Rectangle(50, 50, 100, 100).toPolygon());
path = ring.toPath();
segs = path.getSegments();
assertEquals(10, segs.length);
assertEquals(Path.Segment.MOVE_TO, segs[0].getType());
assertEquals(Path.Segment.CLOSE, segs[9].getType());

// distinct rectangles
ring = new Ring(new Rectangle(0, 0, 50, 50).toPolygon(),
new Rectangle(60, 60, 50, 50).toPolygon());
path = ring.toPath();
segs = path.getSegments();
assertEquals(10, segs.length);
assertEquals(Path.Segment.MOVE_TO, segs[0].getType());
assertEquals(Path.Segment.CLOSE, segs[4].getType());
assertEquals(Path.Segment.MOVE_TO, segs[5].getType());
assertEquals(Path.Segment.CLOSE, segs[9].getType());
}

@Test
public void toPath_with_void() {
Ring r = new Ring(
Expand Down Expand Up @@ -143,7 +180,7 @@ public void toPath_with_void() {
* <p>
* The {@link Ring#triangulate(Polygon, Line)} method is tested here.
* </p>
*
*
* <p>
* The test names indicate the various situations that are tested. Each
* situation comprises the location of the start and end point of the
Expand All @@ -153,14 +190,14 @@ public void toPath_with_void() {
* the {@link Polygon}. Imaginary {@link Point}s of intersection do not lie
* on the {@link Line} but on its expansion to infinity in both directions.
* </p>
*
*
* <p>
* The first two characters indicate the location of the start and the end
* {@link Point} of the {@link Line} relative to the {@link Polygon}. 'o'
* means 'outside the polygon'. 'i' means 'inside the polygon'. 'e' means
* 'on an edge of the polygon'. 'v' means 'on a vertex of the polygon'.
* </p>
*
*
* <p>
* After that, number and type of expected intersections are stated. Real
* intersection {@link Point}s ('r' for 'real') are named before the
Expand All @@ -169,7 +206,7 @@ public void toPath_with_void() {
* is a vertex of the polygon'. 'e' means 'the intersection point is on an
* edge of the polygon'.
* </p>
*
*
* <p>
* The postfix indicates the expected number of resulting {@link Polygon}s.
* 'ntd' means 'nothing to do' and therefore, it appears when a copy of the
Expand Down

0 comments on commit 271a6d0

Please sign in to comment.