use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.
the class NodeConnector method getNodeFromPoint.
Optional<Node> getNodeFromPoint(final Point2D point, final List<NodeEntry> entries) {
if (entries.size() == 1) {
return Optional.of(entries.get(0).getNode());
}
final Map<Point2D, NodeEntry> entriesByPoint2D = new HashMap<>();
for (final NodeEntry entry : entries) {
final JSIBounds bounds = entry.getDmnShape().getBounds();
final double centerX = bounds.getX() + (bounds.getWidth() / 2);
final double centerY = bounds.getY() + (bounds.getHeight() / 2);
entriesByPoint2D.put(new Point2D(centerX, centerY), entry);
}
final Point2D nearest = Collections.min(entriesByPoint2D.keySet(), (point1, point2) -> {
final Double distance1 = point.distance(point1);
final Double distance2 = point.distance(point2);
return distance1.compareTo(distance2);
});
if (!isPointInsideNode(entriesByPoint2D.get(nearest), point)) {
return Optional.empty();
}
return Optional.of(entriesByPoint2D.get(nearest).getNode());
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.
the class NodeConnector method getNode.
private Optional<Node> getNode(final NodeEntry decisionServiceEntry, final String internalDMNElementId, final Map<String, List<NodeEntry>> entriesById) {
final JSIBounds decisionServiceBounds = decisionServiceEntry.getDmnShape().getBounds();
for (final Map.Entry<String, List<NodeEntry>> entry : entriesById.entrySet()) {
final String id = entry.getKey();
final List<NodeEntry> entries = entry.getValue();
if (id.contains(internalDMNElementId)) {
for (final NodeEntry nodeEntry : entries) {
final JSIBounds nodeBounds = nodeEntry.getDmnShape().getBounds();
final boolean b = (nodeBounds.getX() + nodeBounds.getWidth()) < (decisionServiceBounds.getX() + decisionServiceBounds.getWidth());
final boolean b1 = nodeBounds.getX() > decisionServiceBounds.getX();
final boolean innerX = b1 && b;
final boolean b2 = (nodeBounds.getY() + nodeBounds.getHeight()) < (decisionServiceBounds.getY() + decisionServiceBounds.getHeight());
final boolean b3 = nodeBounds.getY() > decisionServiceBounds.getY();
final boolean innerY = b2 && b3;
if (innerX && innerY) {
return Optional.of(nodeEntry.getNode());
}
}
}
}
return Optional.empty();
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.
the class NodeConnector method isPointInsideNode.
boolean isPointInsideNode(final NodeEntry node, final Point2D point) {
final JSIBounds bounds = node.getDmnShape().getBounds();
final double width = bounds.getX() + bounds.getWidth();
final double height = bounds.getY() + bounds.getHeight();
return point.getX() <= width + CENTRE_TOLERANCE && point.getX() >= bounds.getX() - CENTRE_TOLERANCE && point.getY() <= height + CENTRE_TOLERANCE && point.getY() >= bounds.getY() - CENTRE_TOLERANCE;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.
the class NodeEntriesBuilder method makeStandardShape.
private JSIDMNShape makeStandardShape() {
final JSIDMNShape jsidmnShape = new JSIDMNShape();
final JSIBounds boundsParam = new JSIBounds();
boundsParam.setX(0);
boundsParam.setY(0);
boundsParam.setWidth(100);
boundsParam.setHeight(50);
jsidmnShape.setBounds(boundsParam);
return jsidmnShape;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds in project kie-wb-common by kiegroup.
the class NodeConnectorTest method createNodeEntryWithBounds.
NodeEntry createNodeEntryWithBounds(final double x, final double y, final double width, final double height) {
final NodeEntry nodeEntry = mock(NodeEntry.class);
final JSIDMNShape shape = mock(JSIDMNShape.class);
final JSIBounds bounds = mock(JSIBounds.class);
when(bounds.getHeight()).thenReturn(height);
when(bounds.getWidth()).thenReturn(width);
when(bounds.getX()).thenReturn(x);
when(bounds.getY()).thenReturn(y);
when(nodeEntry.getDmnShape()).thenReturn(shape);
when(shape.getBounds()).thenReturn(bounds);
return nodeEntry;
}
Aggregations