java.awt.geom.Area#contains ( )源码实例Demo

下面列出了java.awt.geom.Area#contains ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TrakEM2   文件: Polyline.java
@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;
}
 
源代码2 项目: audiveris   文件: BarsRetriever.java
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;
}
 
源代码3 项目: audiveris   文件: SystemManager.java
/**
 * 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;
}
 
源代码4 项目: audiveris   文件: SystemManager.java
/**
 * 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;
}
 
源代码5 项目: audiveris   文件: Mask.java
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;
}
 
源代码6 项目: darklaf   文件: DarkToolTipUI.java
@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);
    }
}
 
/**
 * 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;
}
 
源代码8 项目: TrakEM2   文件: Polyline.java
@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;
}
 
源代码9 项目: TrakEM2   文件: Connector.java
/** 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);
}
 
源代码10 项目: TrakEM2   文件: Pipe.java
@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;
}
 
源代码11 项目: audiveris   文件: CurvesBuilder.java
/**
 * 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;
}
 
源代码12 项目: audiveris   文件: StaffManager.java
/**
 * 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;
}
 
源代码13 项目: testarea-pdfbox2   文件: PdfToTextInfoConverter.java
@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);
    }
}
 
源代码14 项目: TrakEM2   文件: DLabel.java
@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;
}
 
源代码15 项目: TrakEM2   文件: Dissector.java
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;
}
 
源代码16 项目: TrakEM2   文件: Ball.java
@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;
}
 
源代码17 项目: TrakEM2   文件: Treeline.java
/** 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() ?
}
 
源代码18 项目: audiveris   文件: SlurLinker.java
/**
 * 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;
}
 
源代码19 项目: TrakEM2   文件: Connector.java
@Override
public boolean intersects(final Area a) {
	if (0 == r) return a.contains(x, y);
	return M.intersects(a, getArea());
}
 
源代码20 项目: testarea-pdfbox2   文件: PDFVisibleTextStripper.java
/**
 * <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);
}