org.eclipse.draw2d.geometry.PrecisionPoint Java Examples

The following examples show how to use org.eclipse.draw2d.geometry.PrecisionPoint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EdgeLabelQuery.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Check if the <code>segment</code> is on the same line as the
 * <code>referenceSegment</code> and if it is in the same direction or not.
 *
 * @param referenceSegment The reference segment.
 * @param segment          The segment to test
 * @return one of these statuses {@link #NOT_ON_SAME_LINE},
 *         {@link #ON_SAME_LINE_SAME_DIRECTION} or
 *         {@link #ON_SAME_LINE_OPPOSITE_DIRECTION}.
 */
private int getSameLineStatus(LineSeg referenceSegment, LineSeg segment) {
	int result = NOT_ON_SAME_LINE;
	if (segment.length() != 0) {
		Vector referenceVector = new Vector(referenceSegment.getTerminus().x - referenceSegment.getOrigin().x,
				referenceSegment.getTerminus().y - referenceSegment.getOrigin().y);
		Vector vector = new Vector(segment.getTerminus().x - segment.getOrigin().x,
				segment.getTerminus().y - segment.getOrigin().y);
		double angle = referenceVector.getAngle(vector);
		if ((angle == 0) || (angle == 180)) {
			Straight straight = new Straight(new PrecisionPoint(segment.getOrigin()),
					new PrecisionPoint(segment.getTerminus()));
			double distToInfiniteLine = straight
					.getDistance(new Vector(referenceSegment.getOrigin().x, referenceSegment.getOrigin().y));
			if (distToInfiniteLine < DISTANCE_TOLERANCE) {
				if (angle == 180) {
					result = ON_SAME_LINE_OPPOSITE_DIRECTION;
				} else {
					result = ON_SAME_LINE_SAME_DIRECTION;
				}
			}
		}
	}
	return result;
}
 
Example #2
Source File: GeometryUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public PrecisionPoint findNearestIntersection(Line line, List<Line> segs, PrecisionPoint reference) {
	PrecisionPoint nearestPoi = null;
	double nearestDistance = Double.MAX_VALUE;
	for (final Line seg : segs) {
		final PrecisionPoint poi = getIntersection(seg, line);
		if (poi == null) {
			continue;
		}
		if (nearestPoi == null) {
			nearestPoi = poi;
			nearestDistance = getDistance(nearestPoi, reference);
		} else {
			final double distance = getDistance(poi, reference);
			if (distance < nearestDistance) {
				nearestPoi = poi;
				nearestDistance = distance;
			}
		}
	}
	return nearestPoi;
}
 
Example #3
Source File: BonitaUnspecifiedTypeCreationTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void snapPoint(CreateRequest request) {
	Dimension delta =getDragMoveDelta();
	Point moveDelta = new Point(delta.preciseWidth(),delta.preciseHeight());

	if (helper != null && sourceRectangle != null && compoundSrcRect != null) {
		PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
		PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy();
		baseRect.translate(moveDelta);
		jointRect.translate(moveDelta);
		PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta);
		helper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] {
				baseRect, jointRect }, preciseDelta);

		request.setLocation(preciseDelta);
	}

}
 
Example #4
Source File: PointsUtil.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Rotates the given {@link Point} with the given angle relative to the rotation point.
 * @param point The {@link Point} to rotate
 * @param angle The angle to rotate (in Degrees)
 * @param rotationPoint The rotation point
 * @return The rotated Point
 */
public static PrecisionPoint doRotate(final PrecisionPoint point, final double angle, final PrecisionPoint rotationPoint) {
	assert point!=null : "Precondition violated: point!=null";
	assert rotationPoint!=null : "Precondition violated: rotationPoint!=null";
	double trueAngle = Math.toRadians(angle);
	double sin = Math.sin(trueAngle);
	double cos = Math.cos(trueAngle);
	
	//Relative coordinates to the rotation point
	double relX = point.preciseX()-rotationPoint.preciseX();
	double relY = point.preciseY()-rotationPoint.preciseY();
	
	double temp = relX * cos - relY * sin;

	double y = relX * sin + relY * cos;
	double x = temp;
	
	return new PrecisionPoint(x+rotationPoint.x,y+rotationPoint.y);
}
 
Example #5
Source File: GeometryUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public double getParameterAt(Straight s, PrecisionPoint p) {
	if (!contains(s, p)) {
		throw new IllegalArgumentException(
				"The given position Vector has to be on this Straight: getParameterAt(" + s + ", " + p + ")");
	}

	if (Math.abs(s.direction.preciseX()) > Math.abs(s.direction.preciseY())) {
		return (p.preciseX() - s.position.preciseX()) / s.direction.preciseX();
	}
	if (s.direction.preciseY() != 0) {
		return (p.preciseY() - s.position.preciseY()) / s.direction.preciseY();
	}

	throw new IllegalStateException(
			"The direction Vector of this Straight may not be (0, 0) for this computation: getParameterAt(" + s
					+ ", " + p + ")");
}
 
Example #6
Source File: ConnData.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private int getSideIndex(Rectangle bounds, boolean isVerticalSegment, PrecisionPoint anchorPoint) {
	int index;
	if (isVerticalSegment) {
		if (bounds.getTop().getDistance(anchorPoint) < bounds.getBottom().getDistance(anchorPoint)) {
			// top
			index = 0;
		} else {
			// bottom
			index = 2;
		}
	} else {
		if (bounds.getLeft().getDistance(anchorPoint) < bounds.getRight().getDistance(anchorPoint)) {
			// left
			index = 3;
		} else {
			// right
			index = 1;
		}
	}
	return index;
}
 
Example #7
Source File: AdjustIdentityAnchorCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void handleEdge(Edge edge, EditPart editPart, boolean sourceAnchor) {
	Anchor anchorToModify;
	if (sourceAnchor) {
		anchorToModify = edge.getSourceAnchor();
	} else {
		anchorToModify = edge.getTargetAnchor();
	}
	String terminalString = composeTerminalString(DEFAULT_POINT);
	if (anchorToModify instanceof IdentityAnchor) {
		terminalString = ((IdentityAnchor) anchorToModify).getId();
	}
	PrecisionPoint anchorPoint = BaseSlidableAnchor.parseTerminalString(terminalString);
	PrecisionPoint newPoint = computeNewAnchor(anchorPoint, editPart);
	String newTerminalString = new SlidableAnchor(null, newPoint).getTerminal();
	if (anchorToModify instanceof IdentityAnchor) {
		((IdentityAnchor) anchorToModify).setId(newTerminalString);
	} else if (anchorToModify == null) {
		// Create a new one
		IdentityAnchor newAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
		newAnchor.setId(newTerminalString);
		if (sourceAnchor) {
			edge.setSourceAnchor(newAnchor);
		} else {
			edge.setTargetAnchor(newAnchor);
		}
	}
}
 
Example #8
Source File: ConnData.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public List<PrecisionPoint> getVisualPoints() {
	List<PrecisionPoint> list = new ArrayList<>();
	PointList pointList = conn.getPoints();
	for (int i = 0; i < pointList.size(); i++) {
		list.add(new PrecisionPoint(pointList.getPoint(i)));
	}
	return list;
}
 
Example #9
Source File: PolygonController.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public PolygonController ( final SymbolController controller, final Polygon element, final ResourceManager manager )
{
    super ( controller, manager );

    this.figure = new PolygonShape () {
        @Override
        public void addNotify ()
        {
            super.addNotify ();
            start ();
        }

        @Override
        public void removeNotify ()
        {
            stop ();
            super.removeNotify ();
        }
    };

    final PointList points = new PointList ();
    for ( final Position pos : element.getPoints () )
    {
        final Point p = new PrecisionPoint ( pos.getX (), pos.getY () );
        points.addPoint ( p );
    }
    setPoints ( points );

    controller.addElement ( element, this );

    applyCommon ( element );
}
 
Example #10
Source File: AdjustIdentityAnchorCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected String composeTerminalString(PrecisionPoint p) {
	StringBuffer s = new StringBuffer(24);
	s.append(TERMINAL_START_CHAR);
	s.append(p.preciseX());
	s.append(TERMINAL_DELIMITER_CHAR);
	s.append(p.preciseY());
	s.append(TERMINAL_END_CHAR);
	return s.toString();
}
 
Example #11
Source File: AdjustIdentityAnchorCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private PrecisionPoint computeNewAnchor(PrecisionPoint currentAnchorPoint, EditPart editPart) {

		double scale = getScale(editPart);
		IFigure figure = ((IGraphicalEditPart) editPart).getFigure();
		Rectangle bounds = figure.getBounds();
		if (figure instanceof HandleBounds) {
			bounds = ((HandleBounds) figure).getHandleBounds();
		}

		Point currentRelativePoint = getAnchorRelativePoint(currentAnchorPoint, bounds);

		if (futureSize != null && delta != null) {
			// In case of border node, the real location is computed earlier
			// (according to BorderItemLocator). The corresponding futureSize
			// and delta are used instead of the request data.
			return new PrecisionPoint(((double) (currentRelativePoint.x - delta.x)) / futureSize.width,
					((double) (currentRelativePoint.y - delta.y)) / futureSize.height);
		} else {

			double logicalWidthDelta = request.getSizeDelta().width / scale;
			double logicalHeightDelta = request.getSizeDelta().height / scale;

			int direction = request.getResizeDirection();

			double newRelativeX = computeNewXRelativeLocation(direction, currentRelativePoint, logicalWidthDelta);
			double newRelativeY = computeNewYRelativeLocation(direction, currentRelativePoint, logicalHeightDelta);

			return new PrecisionPoint(newRelativeX / (bounds.width() + logicalWidthDelta),
					newRelativeY / (bounds.height() + logicalHeightDelta));
		}
	}
 
Example #12
Source File: GeometryUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public List<Line> getOutlineSegments(Rectangle rect) {
	List<Line> segs = new ArrayList<>();
	segs.add(new Line(new PrecisionPoint(rect.x, rect.y), new PrecisionPoint(rect.x + rect.w, rect.y)));
	segs.add(new Line(new PrecisionPoint(rect.x + rect.w, rect.y),
			new PrecisionPoint(rect.x + rect.w, rect.y + rect.h)));
	segs.add(new Line(new PrecisionPoint(rect.x + rect.w, rect.y + rect.h),
			new PrecisionPoint(rect.x, rect.y + rect.h)));
	segs.add(new Line(new PrecisionPoint(rect.x, rect.y + rect.h), new PrecisionPoint(rect.x, rect.y)));
	return segs;
}
 
Example #13
Source File: PolygonController.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Set points as string
 * <p>
 * <code>
 * 1.5;2.5|1.5;2.5
 * </code>
 * </p>
 * 
 * @param points
 */
public void setPointsString ( final String pointsString )
{
    final PointList pointList = new PointList ();

    final String[] points = pointsString.split ( "\\|" );
    for ( final String point : points )
    {
        final String[] toks = point.split ( ";" );
        final PrecisionPoint p = new PrecisionPoint ( Double.parseDouble ( toks[0] ), Double.parseDouble ( toks[1] ) );
        pointList.addPoint ( p );
    }
    setPoints ( pointList );
}
 
Example #14
Source File: LineController.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public LineController ( final SymbolController controller, final Line element, final ResourceManager manager )
{
    super ( controller, manager );

    this.figure = new PolylineShape () {
        @Override
        public void addNotify ()
        {
            super.addNotify ();
            start ();
        }

        @Override
        public void removeNotify ()
        {
            stop ();
            super.removeNotify ();
        }
    };

    final PointList points = new PointList ();
    for ( final Position pos : element.getPoints () )
    {
        final Point p = new PrecisionPoint ( pos.getX (), pos.getY () );
        points.addPoint ( p );
    }
    setPoints ( points );

    controller.addElement ( element, this );

    applyCommon ( element );
}
 
Example #15
Source File: ROIFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private Rectangle getROIFromGeoBounds(PrecisionRectangle roiBounds){
	PrecisionPoint lt = ((GraphArea)getParent()).getDataLocation(roiBounds.preciseX(), roiBounds.preciseY());
	PrecisionPoint rb = ((GraphArea)getParent()).getDataLocation(roiBounds.preciseX() + roiBounds.preciseWidth(),
			roiBounds.preciseY() + roiBounds.preciseHeight());
	return new Rectangle((int)Math.round(lt.preciseX()) + intensityGraphFigure.getCropLeft(), 
			(int)Math.round(lt.preciseY()) +intensityGraphFigure.getCropTop(),
			(int)Math.ceil(rb.preciseX() - lt.preciseX()), (int)Math.ceil(rb.preciseY() - lt.preciseY()));
}
 
Example #16
Source File: IntensityGraphFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**Get data index location on cropped data array from geometry location.
 * @param x x much be inside graph area.
 * @param y y much be inside graph area
 * @return
 */
public PrecisionPoint getDataLocation(double x, double y){
	Rectangle clientArea = getClientArea();
	double hIndex = croppedDataWidth * (x - clientArea.x)/(double)clientArea.width;
	double vIndex = croppedDataHeight * (y - clientArea.y)/(double)clientArea.height;	
	return new PrecisionPoint(hIndex, vIndex);

}
 
Example #17
Source File: ConnData.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public List<PrecisionPoint> getInitialVisualPointsCopy() {
	List<PrecisionPoint> copy = new ArrayList<>();
	for (PrecisionPoint p : initialVisualPoints) {
		copy.add(new PrecisionPoint(p));
	}
	return copy;
}
 
Example #18
Source File: GeometryUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public PrecisionPoint getIntersection(Straight s1, Straight s2) {
	PrecisionPoint p1 = getAdded(s1.position, s1.direction);
	PrecisionPoint p2 = getAdded(s2.position, s2.direction);
	V3 l1 = getCrossProduct(new V3(s1.position.x, s1.position.y, 1), new V3(p1));
	V3 l2 = getCrossProduct(new V3(s2.position.x, s2.position.y, 1), new V3(p2));
	PrecisionPoint poi = getCrossProduct(l1, l2).toPoint();
	return poi;
}
 
Example #19
Source File: ROIFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private PrecisionRectangle getGeoBoundsFromROI(Rectangle roiDataBounds){
	PrecisionPoint lt = ((GraphArea)getParent()).getGeoLocation(roiDataBounds.preciseX()-intensityGraphFigure.getCropLeft(), 
			roiDataBounds.preciseY()-intensityGraphFigure.getCropTop());
	PrecisionPoint rb = ((GraphArea)getParent()).getGeoLocation(
			roiDataBounds.preciseX() + roiDataBounds.preciseWidth() -intensityGraphFigure.getCropLeft(), 
			roiDataBounds.preciseY() + roiDataBounds.preciseHeight() -intensityGraphFigure.getCropTop());
	return new PrecisionRectangle(lt.preciseX()-getBounds().x, lt.preciseY()-getBounds().y, rb.preciseX() - lt.preciseX(), rb.preciseY() - lt.preciseY());			
}
 
Example #20
Source File: GeometryUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public PrecisionPoint getProjection(Straight s, PrecisionPoint vector) {
	// calculate with a normalized direction vector to prevent rounding
	// effects
	PrecisionPoint normalized = getNormalized(s.direction);

	// to compensate rounding problems with large vectors, we shift
	// straight and given vector by the straight's position vector before
	// the computation and back before returning the computed projection.
	Straight s1 = new Straight(new PrecisionPoint(0d, 0d), normalized);
	Straight s2 = new Straight(getSubtracted(vector, s.position), getOrthogonalComplement(normalized));
	return getAdded(getIntersection(s1, s2), s.position);
}
 
Example #21
Source File: RelativeBendpointUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void forceLocation(Connection conn, RelativeBendpoint relbp, double locX, double locY) {
	float w = 0;
	Dimension d2 = new Dimension();
	PrecisionDimension d1 = new PrecisionDimension();

	// compute d1 based on source anchor
	PrecisionPoint a1 = new PrecisionPoint(conn.getSourceAnchor().getReferencePoint());
	Point a1Copy = a1.getCopy();
	conn.translateToRelative(a1Copy);

	// x = a1.preciseX() + d1.preciseWidth()
	// <=> x - a1.preciseX() = d1.preciseWidth()
	d1.setPreciseWidth(locX - a1Copy.preciseX());
	d1.setPreciseHeight(locY - a1Copy.preciseY());

	relbp.setRelativeDimensions(d1, d2);
	relbp.setWeight(w);

	// ensure location is correct
	Point location = relbp.getLocation();
	if (Math.abs(location.preciseX() - locX) > 0.1) {
		throw new IllegalStateException(
				"cannot force location-x: expected <" + locX + "> but got <" + location.preciseX() + ">");
	}
	if (Math.abs(location.preciseY() - locY) > 0.1) {
		throw new IllegalStateException(
				"cannot force location-y: expected <" + locY + "> but got <" + location.preciseY() + ">");
	}
}
 
Example #22
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected List<RelativeBendpoint> createConstraint(Connection conn, List<PrecisionPoint> list) {
	List<RelativeBendpoint> constraint = new ArrayList<>();
	for (Point p : list) {
		RelativeBendpoint relbp = new RelativeBendpoint();
		relbp.setConnection(conn);
		relbpUtil.forceLocation(conn, relbp, p.preciseX(), p.preciseY());
		constraint.add(relbp);
	}
	return constraint;
}
 
Example #23
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find first intersection with target box, walking from start to end.
 *
 * @param points
 * @param rect
 * @param isSelfAssoc
 */
protected void cutOffEnd(List<PrecisionPoint> points, Rectangle rect, boolean isSelfAssoc) {
	// determine top, right, bottom, and left sides
	final List<Line> segs = geom.getOutlineSegments(geom.toRectangle(rect));

	// need four points for self-associations
	int startIndex = isSelfAssoc ? 3 : 1;
	if (startIndex >= points.size()) {
		return;
	}

	// walk from start to end
	PrecisionPoint p1 = geom.toPP(points.get(startIndex - 1));
	for (int i = startIndex; i < points.size(); i++) {
		final PrecisionPoint p2 = geom.toPP(points.get(i));
		final Line line = new Line(p1, p2);
		final PrecisionPoint poi = geom.findNearestIntersection(line, segs, p1);
		if (poi != null) {
			for (int j = points.size() - 1; j >= i; j--) {
				points.remove(j);
			}
			if (p1.preciseX() == p2.preciseX()) {
				poi.setPreciseX(p1.preciseX());
			} else {
				poi.setPreciseY(p1.preciseY());
			}
			points.add(poi);
			return;
		}
		p1 = p2;
	}
}
 
Example #24
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find first intersection with source box, walking from end to start.
 *
 * @param points
 * @param rect
 * @param isSelfAssoc
 */
protected void cutOffStart(List<PrecisionPoint> points, Rectangle rect, boolean isSelfAssoc) {
	// determine top, right, bottom, and left sides
	final List<Line> segs = geom.getOutlineSegments(geom.toRectangle(rect));

	// need at least four points for self-assocs
	int startIndex = isSelfAssoc ? points.size() - 4 : points.size() - 2;
	if ((startIndex < 0) || ((startIndex + 1) >= points.size())) {
		return;
	}

	// walk from end to start
	PrecisionPoint p2 = geom.toPP(points.get(startIndex + 1));
	for (int i = startIndex; i >= 0; i--) {
		final PrecisionPoint p1 = geom.toPP(points.get(i));
		final Line line = new Line(p1, p2);
		final PrecisionPoint poi = geom.findNearestIntersection(line, segs, p2);
		if (poi != null) {
			for (int j = i; j >= 0; j--) {
				points.remove(j);
			}
			if (p1.preciseX() == p2.preciseX()) {
				poi.setPreciseX(p1.preciseX());
			} else {
				poi.setPreciseY(p1.preciseY());
			}
			points.add(0, poi);
			return;
		}
		p2 = p1;
	}
}
 
Example #25
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void cutOutLoops(List<PrecisionPoint> points) {
		// loops are only possible with at least five points
		final int minLoopSize = 5;
		if (points.size() < minLoopSize) {
			return;
		}

		// search from start so that removals can happen without having to adjust
		// indices
		for (int i = points.size() - 1; i >= (minLoopSize - 1); i--) {
			final Line rearLine = new Line(geom.toPP(points.get(i - 1)), geom.toPP(points.get(i)));
			for (int j = 0; j <= ((i - minLoopSize) + 1); j++) {
				final Line frontLine = new Line(geom.toPP(points.get(j)), geom.toPP(points.get(j + 1)));
				final PrecisionPoint poi = geom.getIntersection(rearLine, frontLine);
//				System.out.println("intersect " + rearLine + " with " + frontLine + " yields " + poi);
				if (poi != null) {
					// replace all points from j + 1 ... i - 1 with the point of intersection
					for (int k = i - 1; k >= (j + 1); k--) {
						points.remove(k);
					}
					points.add(j + 1, poi);
					// XXX: due to continuous loop-removal, there should always be at most one loop
					return;
				}
			}
		}
	}
 
Example #26
Source File: GeometryUtilTests.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test_line_intersection() {
	PrecisionPoint p1 = new PrecisionPoint(306.0, 258.0);
	PrecisionPoint p2 = new PrecisionPoint(540.0, 258.0);
	Line l1 = new GeometryUtil.Line(p1, p2);

	PrecisionPoint q1 = new PrecisionPoint(434.0, 63.0);
	PrecisionPoint q2 = new PrecisionPoint(434.0, 348.0);
	Line l2 = new GeometryUtil.Line(q1, q2);

	Point poi = geom.getIntersection(l1, l2);
	assertNotNull(poi);
	assertEquals(434.0, poi.preciseX(), 0.1);
	assertEquals(258.0, poi.preciseY(), 0.1);
}
 
Example #27
Source File: GeometryUtilTests.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test_line_intersection_2() {
	PrecisionPoint p1 = new PrecisionPoint(434.0, 63.0);
	PrecisionPoint p2 = new PrecisionPoint(434.0, 348.0);
	Line l1 = new GeometryUtil.Line(p1, p2);

	PrecisionPoint q1 = new PrecisionPoint(244.0, 194.0);
	PrecisionPoint q2 = new PrecisionPoint(520.0, 194.0);
	Line l2 = new GeometryUtil.Line(q1, q2);

	Point poi = geom.getIntersection(l1, l2);
	assertNotNull(poi);
	assertEquals(434.0, poi.preciseX(), 0.1);
	assertEquals(194.0, poi.preciseY(), 0.1);
}
 
Example #28
Source File: DiagramElementsModifierTest.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Test for setConnectionAnchors
 */
@Test
public void setConnectionAnchorsTest() {
	Pair<String, Class<?>> A = new Pair<String, Class<?>>("ClassA",
			org.eclipse.uml2.uml.Class.class);
	Pair<String, Class<?>> B = new Pair<String, Class<?>>("ClassB",
			org.eclipse.uml2.uml.Class.class);

	List<Pair<String, Class<?>>> objects = Arrays.asList(A, B);
	List<Pair<Pair<String, Class<?>>, Pair<String, Class<?>>>> associations = Arrays
			.asList(new Pair<Pair<String, Class<?>>, Pair<String, Class<?>>>(
					A, B));

	init(objects, associations);
	@SuppressWarnings("unchecked")
	List<EditPart> eps = getDiagramEditPart().getChildren();
	ClassEditPart classAEp = (ClassEditPart) eps.get(0);
	ClassEditPart classBEp = (ClassEditPart) eps.get(1);

	@SuppressWarnings("unchecked")
	List<ConnectionEditPart> conns = classBEp.getSourceConnections();
	ConnectionEditPart assoc = conns.get(0);
	DiagramElementsModifier.setConnectionAnchors(assoc, "(1, 0.5)",
			"(0, 0.5)");

	ConnectionAnchor source = classAEp.getSourceConnectionAnchor(assoc);
	ConnectionAnchor target = classBEp.getTargetConnectionAnchor(assoc);
	Point sourceReferencePoint = ((SlidableAnchor) source)
			.getReferencePoint();
	Point targetReferencePoint = ((SlidableAnchor) target)
			.getReferencePoint();
	PrecisionPoint sourceAnchor = SlidableAnchor.getAnchorRelativeLocation(
			sourceReferencePoint, source.getOwner().getBounds());
	PrecisionPoint targetAnchor = SlidableAnchor.getAnchorRelativeLocation(
			targetReferencePoint, target.getOwner().getBounds());

	Assert.assertEquals(new PrecisionPoint(1, 0.5), sourceAnchor);
	Assert.assertEquals(new PrecisionPoint(0, 0.5), targetAnchor);
}
 
Example #29
Source File: DraggableElementCreationTool.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void snapPoint(CreateRequest request) {
    if (helper != null && figure != null) {
        final PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
        final PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy();
        Point location = getLocation().getTranslated(-figure.getSize().width / 2, -figure.getSize().height / 2);
        final PrecisionPoint preciseDelta = new PrecisionPoint(location.preciseX(), location.preciseY());
        baseRect.translate(preciseDelta);
        jointRect.translate(preciseDelta);
        helper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] {
                baseRect, jointRect }, preciseDelta);
        request.setLocation(preciseDelta);
    }

}
 
Example #30
Source File: BPMNShapeFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void attachEdgeLabel(final DecorationNode decorationNode, final BPMNEdge edge, String labelText,
        Edge bonitaEdge) {
    Font font = createFont(bonitaEdge);
    if (font != null) {
        final BPMNLabel label = DiFactory.eINSTANCE.createBPMNLabel();
        Location relativeLocation = (Location) decorationNode.getLayoutConstraint();

        Point offSet = new Point(relativeLocation.getX(), relativeLocation.getY());
        org.eclipse.gmf.runtime.notation.Bounds absoluteBounds = NotationFactory.eINSTANCE.createBounds();
        PointList pList = new PointList();
        edge.getWaypoint().stream().map(wayPoint -> new PrecisionPoint(wayPoint.getX(), wayPoint.getY()))
                .forEach(pList::addPoint);

        Point referencePoint = PointListUtilities.calculatePointRelativeToLine(pList, 0,
                LabelViewConstants.MIDDLE_LOCATION, true);
        Point location = LabelHelper.calculatePointRelativeToPointOnLine(pList, referencePoint, offSet);
        //Here we use some default constant values to avoid a dependency on a set Display
        //The output diemension values are sligthly the same between windows and linux
        Dimension dimension = new Dimension((int) (labelText.length() * 7.42), (int) (11 * 1.6));
        absoluteBounds.setWidth(dimension.width);
        absoluteBounds.setHeight(dimension.height);
        location.translate(-1 * dimension.width / 2, -1 * dimension.height / 2);

        absoluteBounds.setWidth(dimension.width);
        absoluteBounds.setHeight(dimension.height);
        absoluteBounds.setX(location.x);
        absoluteBounds.setY(location.y);
        final Bounds elementBounds = DcFactory.eINSTANCE.createBounds();
        elementBounds.setX(absoluteBounds.getX());
        elementBounds.setY(absoluteBounds.getY());
        elementBounds.setHeight(absoluteBounds.getHeight());
        elementBounds.setWidth(absoluteBounds.getWidth());
        edge.setBPMNLabel(label);
    }
}