Java Code Examples for java.awt.geom.Area#contains()

The following examples show how to use java.awt.geom.Area#contains() . 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: Polyline.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
   synchronized public boolean apply(final Layer la, final Area roi, final mpicbg.models.CoordinateTransform ict) throws Exception {
	double[] fp = null;
	mpicbg.models.CoordinateTransform chain = null;
	Area localroi = null;
	AffineTransform inverse = null;
	for (int i=0; i<n_points; i++) {
		if (p_layer[i] == la.getId()) {
			if (null == localroi) {
				inverse = this.at.createInverse();
				localroi = roi.createTransformedArea(inverse);
			}
			if (localroi.contains(p[0][i], p[1][i])) {
				if (null == chain) {
					chain = M.wrap(this.at, ict, inverse);
					fp = new double[2];
				}
				M.apply(chain, p, i, fp);
			}
		}
	}
	if (null != chain) calculateBoundingBox(true, la); // may be called way too many times, but avoids lots of headaches.
	return true;
}
 
Example 2
Source File: Mask.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
private Table.UnsignedByte computeRelevantPoints (Area area)
{
    Table.UnsignedByte table = new Table.UnsignedByte(rect.width, rect.height);
    Point loc = rect.getLocation();
    table.fill(PixelFilter.BACKGROUND);

    for (int y = 0; y < rect.height; y++) {
        int ay = y + loc.y; // Absolute ordinate

        for (int x = 0; x < rect.width; x++) {
            int ax = x + loc.x; // Absolute abscissa

            if (area.contains(ax, ay)) {
                table.setValue(x, y, 0);
                pointCount++;
            }
        }
    }

    return table;
}
 
Example 3
Source File: BarsRetriever.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<Section> getAreaSections (Area area,
                                       List<Section> allSections)
{
    final Rectangle areaBox = area.getBounds();
    final int xBreak = areaBox.x + areaBox.width;
    final List<Section> sections = new ArrayList<>();

    for (Section section : allSections) {
        final Rectangle sectionBox = section.getBounds();

        if (area.contains(sectionBox)) {
            sections.add(section);
        } else if (sectionBox.x >= xBreak) {
            break; // Since allSections are sorted by abscissa
        }
    }

    return sections;
}
 
Example 4
Source File: SystemManager.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Report the systems that contain the provided point
 *
 * @param point the provided pixel point
 * @param found (output) list to be populated (allocated if null)
 * @return the containing systems info, perhaps empty but not null
 */
public List<SystemInfo> getSystemsOf (Point2D point,
                                      List<SystemInfo> found)
{
    if (found != null) {
        found.clear();
    } else {
        found = new ArrayList<>();
    }

    for (SystemInfo system : systems) {
        Area area = system.getArea();

        if ((area != null) && area.contains(point)) {
            found.add(system);
        }
    }

    return found;
}
 
Example 5
Source File: SystemManager.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Report the systems that contain the provided rectangle
 *
 * @param rect  the provided rectangle
 * @param found (output) list to be populated (allocated if null)
 * @return the containing systems info, perhaps empty but not null
 */
public List<SystemInfo> containingSystems (Rectangle2D rect,
                                           List<SystemInfo> found)
{
    if (found != null) {
        found.clear();
    } else {
        found = new ArrayList<>();
    }

    for (SystemInfo system : systems) {
        Area area = system.getArea();

        if ((area != null) && area.contains(rect)) {
            found.add(system);
        }
    }

    return found;
}
 
Example 6
Source File: Treeline.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Expects @param a in local coords. */
@Override
public boolean intersects(final Area a) {
	if (0 == r) return a.contains(x, y);
	return M.intersects(a, new Area(new Ellipse2D.Float(x-r, y-r, r+r, r+r)));
	// TODO: not the getSegment() ?
}
 
Example 7
Source File: DarkToolTipUI.java    From darklaf with MIT License 5 votes vote down vote up
@Override
public boolean contains(final JComponent c, final int x, final int y) {
    Border b = c.getBorder();
    if (b instanceof DarkTooltipBorder) {
        Area insideArea = ((DarkTooltipBorder) b).getBackgroundArea(toolTip, toolTip.getWidth(),
                                                                    toolTip.getHeight());
        return insideArea.contains(x, y);
    } else {
        return super.contains(c, x, y);
    }
}
 
Example 8
Source File: Ball.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
   synchronized public boolean apply(final Layer la, final Area roi, final mpicbg.models.CoordinateTransform ict) throws Exception {
	double[] fp = null;
	mpicbg.models.CoordinateTransform chain = null;
	Area localroi = null;
	AffineTransform inverse = null;
	for (int i=0; i<n_points; i++) {
		if (p_layer[i] == la.getId()) {
			if (null == localroi) {
				inverse = this.at.createInverse();
				localroi = roi.createTransformedArea(inverse);
			}
			if (localroi.contains(p[0][i], p[1][i])) {
				if (null == chain) {
					chain = M.wrap(this.at, ict, inverse);
					fp = new double[2];
				}
				// Keep point copy
				final double ox = p[0][i],
				       oy = p[1][i];
				// Transform the point
				M.apply(chain, p, i, fp);
				// For radius, assume it's a point to the right of the center point
				fp[0] = (float)(ox + p_width[i]);
				fp[1] = (float)oy;
				chain.applyInPlace(fp);
				p_width[i] = Math.abs(fp[0] - p[0][i]);
			}
		}
	}
	if (null != chain) calculateBoundingBox(true, la); // may be called way too many times, but avoids lots of headaches.
	return true;
}
 
Example 9
Source File: Dissector.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
boolean intersects(final Area area, final double z_first, final double z_last) {
	for (int i=0; i<n_points; i++) {
		final Layer la = layer_set.getLayer(p_layer[i]);
		if (la.getZ() >= z_first && la.getZ() <= z_last) {
			for (int k=0; k<n_points; k++) {
				if (area.contains(p[0][k], p[1][k])) return true;
			}
		}
	}
	return false;
}
 
Example 10
Source File: DLabel.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
   synchronized public boolean apply(final Layer la, final Area roi, final mpicbg.models.CoordinateTransform ict) throws Exception {
	// Considers only the point where this floating text label is.
	final double[] fp = new double[2]; // point is 0,0
	this.at.transform(fp, 0, fp, 0, 1); // to world
	if (roi.contains(fp[0], fp[1])) {
		ict.applyInPlace(fp);
		this.at.createInverse().transform(fp, 0, fp, 0, 1); // back to local
		// as a result, there has been a translation:
		this.at.preConcatenate(new AffineTransform(1, 0, 0, 1, fp[0], fp[1]));
		return true;
	}
	return false;
}
 
Example 11
Source File: PdfToTextInfoConverter.java    From testarea-pdfbox2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void processTextPosition(TextPosition text) {
    PDGraphicsState gs = getGraphicsState();
    // check opacity for stroke and fill text 
    if (gs.getAlphaConstant() < Constants.EPSILON && gs.getNonStrokeAlphaConstant() < Constants.EPSILON) {
        return;
    }                       

    Vector center = getTextPositionCenterPoint(text);
    Area area = gs.getCurrentClippingPath();
    if (area == null || area.contains(lowerLeftX + center.getX(), lowerLeftY + center.getY())) {            
        nonStrokingColors.put(text, gs.getNonStrokingColor());
        super.processTextPosition(text);
    }
}
 
Example 12
Source File: StaffManager.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Report the staves whose area contains the provided point.
 *
 * @param point     the provided pixel point
 * @param theStaves the list of staves to check
 * @return the containing staves
 */
public static List<Staff> getStavesOf (Point2D point,
                                       List<Staff> theStaves)
{
    List<Staff> found = new ArrayList<>();
    for (Staff staff : theStaves) {
        Area area = staff.getArea();

        if ((area != null) && area.contains(point)) {
            found.add(staff);
        }
    }
    return found;
}
 
Example 13
Source File: CurvesBuilder.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Retrieve all arcs within reach from curve end (over some white gap)
 *
 * @param ext extension (on 'reverse' side)
 * @return the set of (new) reachable arcs
 */
private Set<ArcView> findReachableArcs (Extension ext)
{
    final Set<ArcView> reachableArcs = new LinkedHashSet<>();
    final Area area = defineExtArea(ext.curve);

    if (area != null) {
        // Check for reachable arcs in the extension area
        final Rectangle box = area.getBounds();
        final int xMax = (box.x + box.width) - 1;

        // Look for free-standing end points (with no junction point)
        for (Point end : skeleton.arcsEnds) {
            if (area.contains(end)) {
                final Arc arc = skeleton.arcsMap.get(end);

                if (!arc.isAssigned() && !ext.browsed.contains(arc)) {
                    // Check for lack of junction point
                    ArcView arcView = ext.curve.getArcView(arc, reverse);
                    Point pivot = arcView.getJunction(!reverse);

                    if (pivot == null) {
                        reachableArcs.add(arcView);
                        ext.browsed.add(arc);
                    }
                }
            } else if (end.x > xMax) {
                break; // Since list arcsEnds is sorted
            }
        }
    }

    return reachableArcs;
}
 
Example 14
Source File: Pipe.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
   synchronized public boolean apply(final Layer la, final Area roi, final mpicbg.models.CoordinateTransform ict) throws Exception {
	double[] fp = new double[2];
	mpicbg.models.CoordinateTransform chain = null;
	Area localroi = null;
	AffineTransform inverse = null;
	for (int i=0; i<n_points; i++) {
		if (p_layer[i] == la.getId()) {
			if (null == localroi) {
				inverse = this.at.createInverse();
				localroi = roi.createTransformedArea(inverse);
			}
			if (localroi.contains(p[0][i], p[1][i])) {
				if (null == chain) {
					chain = M.wrap(this.at, ict, inverse);
					fp = new double[2];
				}
				// Keep point copy
				final double ox = p[0][i],
				       oy = p[1][i];
				// Transform the point
				M.apply(chain, p, i, fp);
				// For radius, assume it's a point to the right of the center point
				fp[0] = ox + p_width[i];
				fp[1] = oy;
				chain.applyInPlace(fp);
				p_width[i] = Math.abs(fp[0] - p[0][i]);
				// The two associated control points:
				M.apply(chain, p_l, i, fp);
				M.apply(chain, p_r, i, fp);
			}
		}
	}
	if (null != chain) {
		generateInterpolatedPoints(0.05);
		calculateBoundingBox(true, la);
	}
	return true;
}
 
Example 15
Source File: Connector.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Whether the area of the root node intersects the world coordinates {@code wx}, {@code wy} at {@link Layer} {@code la}. */
public boolean intersectsOrigin(final double wx, final double wy, final Layer la) {
	if (null == root || root.la != la) return false;
	final Area a = root.getArea();
	a.transform(this.at);
	return a.contains(wx, wy);
}
 
Example 16
Source File: Polyline.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
   public boolean intersects(final Area area, final double z_first, final double z_last) {
	if (-1 == n_points) setupForDisplay();
	for (int i=0; i<n_points; i++) {
		final double z = layer_set.getLayer(p_layer[i]).getZ();
		if (z < z_first || z > z_last) continue;
		if (area.contains(p[0][i], p[1][i])) return true;
	}
	return false;
}
 
Example 17
Source File: AccurateMouse.java    From Runescape-Web-Walker-Engine with Apache License 2.0 5 votes vote down vote up
/**
 * This is a cpu intensive method.
 *
 * @param destination
 * @return
 */
public static Point getWalkingPoint(RSTile destination) {
    Area area = getTileModel(destination);
    ArrayList<Polygon> polygons = new ArrayList<>();
    for (RSTile tile : new RSArea(destination, 1).getAllTiles()) {
        if (tile.equals(destination)) {
            continue;
        }
        polygons.add(Projection.getTileBoundsPoly(tile, 0));
        polygons.addAll(
          Arrays.stream(Objects.getAt(tile)).filter(object -> RSObjectHelper.getActions(object).length > 0).map(RSObject::getModel).filter(java.util.Objects::nonNull).map(RSModel::getEnclosedArea).filter(java.util.Objects::nonNull).collect(
            Collectors.toList()));
        polygons.addAll(
          Arrays.stream(GroundItems.getAt(tile)).filter(object -> RSItemHelper.getItemActions(object).length > 0).map(RSGroundItem::getModel).filter(java.util.Objects::nonNull).map(RSModel::getEnclosedArea).filter(java.util.Objects::nonNull).collect(
            Collectors.toList()));
        polygons.addAll(
          Arrays.stream(NPCs.find(Filters.NPCs.tileEquals(tile))).filter(object -> RSNPCHelper.getActions(object).length > 0).map(RSNPC::getModel).filter(java.util.Objects::nonNull).map(RSModel::getEnclosedArea).filter(java.util.Objects::nonNull).collect(
            Collectors.toList()));
    }

    outterLoop:
    for (int i = 0; i < 1000; i++) {
        Point point = getRandomPoint(area.getBounds());
        if (Projection.isInViewport(point) && area.contains(point)) {
            for (Polygon polygon : polygons) {
                if (polygon.contains(point)) {
                    continue outterLoop;
                }
            }
            return point;
        }
    }
    return null;
}
 
Example 18
Source File: Connector.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean intersects(final Area a) {
	if (0 == r) return a.contains(x, y);
	return M.intersects(a, getArea());
}
 
Example 19
Source File: SlurLinker.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Select the best note head in the selected head-based chord.
 * We select the compatible note head which is closest to slur target end.
 *
 * @param chord   the selected chord
 * @param end     the slur end point
 * @param target  the slur target point
 * @param bisUnit the direction from slur middle to slur center (unit length)
 * @param area    target area
 * @return the best note head or null
 */
private HeadInter selectBestHead (SlurInter slur,
                                  AbstractChordInter chord,
                                  Point end,
                                  Point target,
                                  Point2D bisUnit,
                                  Area area)
{
    final boolean horizontal = slur.getInfo().isHorizontal();
    final boolean above = slur.isAbove();

    double bestDist = Double.MAX_VALUE;
    HeadInter bestHead = null;

    for (Inter head : chord.getNotes()) {
        Point center = head.getCenter();

        if (!horizontal) {
            // We require head center to be contained by lookup area
            if (!area.contains(center)) {
                continue;
            }
        }

        // Check head reference point WRT slur concavity
        Rectangle bounds = head.getBounds();
        Point refPt = new Point(center.x, bounds.y + (above ? (bounds.height - 1) : 0));

        if (dotProduct(subtraction(refPt, end), bisUnit) <= 0) {
            continue;
        }

        // Keep the closest head
        final double dist = center.distanceSq(target);

        if (dist < bestDist) {
            bestDist = dist;
            bestHead = (HeadInter) head;
        }
    }

    return bestHead;
}
 
Example 20
Source File: PDFVisibleTextStripper.java    From testarea-pdfbox2 with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Due to different rounding of numbers in the clip path and text transformations,
 * it can happen that the glyph origin is exactly on the border of the clip path
 * but the {@link Area#contains(double, double)} method of the determined clip
 * path returns false for the determined origin coordinates.
 * </p>
 * <p>
 * To fix this, this method generates a small rectangle around the (glyph origin)
 * coordinates and checks whether this rectangle intersects the (clip path) area.
 * </p>
 */
protected boolean contains(Area area, float x, float y) {
    if (useFatGlyphOrigin) {
        double length = .0002;
        double up = 1.0001;
        double down = .9999;
        return area.intersects(x < 0 ? x*up : x*down, y < 0 ? y*up : y*down, Math.abs(x*length), Math.abs(y*length));
    } else
        return area.contains(x, y);
}