/** * Is the given sprite visible in the given area. * * @param sprite The sprite to check. * @param X1 The min abscissa of the area. * @param Y1 The min ordinate of the area. * @param X2 The max abscissa of the area. * @param Y2 The max ordinate of the area. * @return True if the node lies in the given area. */ protected boolean isSpriteIn(GraphicSprite sprite, double X1, double Y1, double X2, double Y2) { if (sprite.isAttachedToNode() && nodeInvisible.contains(sprite.getNodeAttachment().getId())) { return false; } else if (sprite.isAttachedToEdge() && !isEdgeVisible(sprite.getEdgeAttachment())) { return false; } else { Values size = sprite.getStyle().getSize(); double w2 = metrics.lengthToPx(size, 0) / 2; double h2 = size.size() > 1 ? metrics.lengthToPx(size, 1) / 2 : w2; Point2D.Double src = spritePositionPx(sprite); // new Point2D.Double( // sprite.getX(), // sprite.getY() ); // Tx.transform( src, src ); double x1 = src.x - w2; double x2 = src.x + w2; double y1 = src.y - h2; double y2 = src.y + h2; if (x2 < X1) return false; if (y2 < Y1) return false; if (x1 > X2) return false; if (y1 > Y2) return false; return true; } }
/** * Compute the real position of a sprite according to its eventual attachment in graph units. * * @param sprite The sprite. * @param pos Receiver for the sprite 2D position, can be null. * @param units The units in which the position must be computed (the sprite already contains * units). * @return The same instance as the one given by parameter pos or a new one if pos was null, * containing the computed position in the given units. */ public Point2D.Double getSpritePosition(GraphicSprite sprite, Point2D.Double pos, Units units) { if (sprite.isAttachedToNode()) return getSpritePositionNode(sprite, pos, units); else if (sprite.isAttachedToEdge()) return getSpritePositionEdge(sprite, pos, units); else return getSpritePositionFree(sprite, pos, units); }