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

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

源代码1 项目: audiveris   文件: SheetScanner.java
/**
 * Erase from text image the glyphs that intersect or touch a staff core area.
 * <p>
 * (We also tried to remove too small glyphs, but this led to poor recognition by OCR)
 *
 * @param glyphs all the glyph instances in image
 * @param cores  all staves cores
 */
private void eraseBorderGlyphs (List<Glyph> glyphs,
                                List<Area> cores)
{
    for (Glyph glyph : glyphs) {
        // Check position WRT staves cores
        Rectangle glyphBox = glyph.getBounds();
        glyphBox.grow(1, 1); // To catch touching glyphs (on top of intersecting ones)

        for (Area core : cores) {
            if (core.intersects(glyphBox)) {
                glyph.getRunTable().render(g, glyph.getTopLeft());

                break;
            }
        }
    }
}
 
源代码2 项目: audiveris   文件: CurvesBuilder.java
/**
 * Report all erased inters in provided system that intersect the provided box.
 *
 * @param system    the system being processed
 * @param box       the box to be intersected
 * @param crossable true for crossable, false for non-crossable
 * @return the collection of erased inter instances with proper crossable characteristic
 */
private Set<Inter> erasedInters (SystemInfo system,
                                 Rectangle box,
                                 boolean crossable)
{
    Set<Inter> found = new LinkedHashSet<>();
    List<Inter> inters = skeleton.getErasedInters(crossable).get(system);

    for (Inter inter : inters) {
        if (inter.getBounds().intersects(box)) {
            Area area = inter.getArea();

            if ((area == null) || area.intersects(box)) {
                found.add(inter);
            }
        }
    }

    return found;
}
 
源代码3 项目: audiveris   文件: SystemManager.java
/**
 * Report the systems that intersect 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> getSystemsOf (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.intersects(rect)) {
            found.add(system);
        }
    }

    return found;
}
 
源代码4 项目: TrakEM2   文件: Bucket.java
/** Remove from wherever it is, then test if it's in that bucket, otherwise re-add. */
synchronized final void updatePosition(final Displayable d, final Layer layer, final HashMap<Displayable,HashSet<Bucket>> db_map) {
	final HashSet<Bucket> hs = db_map.get(d);
	final Area a = d.getAreaForBucket(layer);
	final int stack_index = d.getBucketable().getDisplayableList().indexOf(d);
	if (null != hs) {
		for (final Iterator<Bucket> it = hs.iterator(); it.hasNext(); ) {
			final Bucket bu = it.next();
			if (null != a && a.intersects(bu.x, bu.y, bu.w, bu.h)) continue; // bu.intersects(box)) continue; // no change of bucket: lower-right corner still within the bucket
			// else, remove
			bu.map.remove(stack_index);
			it.remove();
		}
	}
	// insert wherever appropriate, if not there
	if (null != a) this.put(stack_index, d, layer, a, db_map);
}
 
源代码5 项目: gcs   文件: PdfGraphics2D.java
/**
 * @see Graphics2D#hit(Rectangle, Shape, boolean)
 */
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
	if (onStroke) {
		s = stroke.createStrokedShape(s);
	}
	s = transform.createTransformedShape(s);
	Area area = new Area(s);
	if (clip != null) {
		area.intersect(clip);
	}
	return area.intersects(rect.x, rect.y, rect.width, rect.height);
}
 
源代码6 项目: itext2   文件: PdfGraphics2D.java
/**
 * @see Graphics2D#hit(Rectangle, Shape, boolean)
 */
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
    if (onStroke) {
        s = stroke.createStrokedShape(s);
    }
    s = transform.createTransformedShape(s);
    Area area = new Area(s);
    if (clip != null)
        area.intersect(clip);
    return area.intersects(rect.x, rect.y, rect.width, rect.height);
}
 
源代码7 项目: audiveris   文件: SlurLinker.java
/**
 * Retrieve the best head embraced by the slur side.
 *
 * @param slur   the provided slur
 * @param side   desired side
 * @param area   lookup area on slur side
 * @param chords candidate chords on desired side
 * @return the map of heads found, perhaps empty, with their data
 */
private Map<Inter, SlurHeadLink> lookup (SlurInter slur,
                                         HorizontalSide side,
                                         Area area,
                                         List<Inter> chords)
{
    final Map<Inter, SlurHeadLink> found = new HashMap<>();
    final SlurInfo info = slur.getInfo();
    final Point end = info.getEnd(side == LEFT);
    final Point target = getTargetPoint(slur, side);
    final Point2D bisUnit = info.getBisUnit();

    // Look for intersected chords
    for (Inter chordInter : chords) {
        AbstractChordInter chord = (AbstractChordInter) chordInter;
        Rectangle chordBox = chord.getBounds();

        if (area.intersects(chordBox)) {
            // Check the chord contains at least one suitable head on desired slur side
            HeadInter head = selectBestHead(slur, chord, end, target, bisUnit, area);

            if (head != null) {
                found.put(chord, SlurHeadLink.create(target, side, chord, head));
            }
        }
    }

    return found;
}
 
源代码8 项目: audiveris   文件: NoteHeadsBuilder.java
/**
 * Check whether the provided rectangle would intersect area of frozen
 * barline/connector.
 *
 * @param rect provided rectangle
 * @return true if area hit
 */
private boolean barInvolved (Rectangle rect)
{
    for (Area a : barAreas) {
        if (a.intersects(rect)) {
            return true;
        }
    }

    return false;
}
 
源代码9 项目: audiveris   文件: NoteHeadsBuilder.java
/**
 * Build the list of areas around connectors and frozen barlines.
 *
 * @return the bar-centered areas
 */
private List<Area> getBarAreas (Area area)
{
    List<Area> kept = new ArrayList<>();
    for (Area r : systemBarAreas) {
        if (area.intersects(r.getBounds())) {
            kept.add(r);
        }
    }
    return kept;
}
 
源代码10 项目: audiveris   文件: Glyphs.java
/**
 * Look up in a collection of glyph instances for <b>all</b> glyph
 * instances intersected by a provided area.
 *
 * @param collection the collection of glyph instances to be browsed
 * @param area       the intersecting area
 * @return the glyph instances found, which may be an empty list
 */
public static Set<Glyph> intersectedGlyphs (Collection<? extends Glyph> collection,
                                            Area area)
{
    Set<Glyph> set = new LinkedHashSet<>();

    for (Glyph glyph : collection) {
        if (area.intersects(glyph.getBounds())) {
            set.add(glyph);
        }
    }

    return set;
}
 
源代码11 项目: pumpernickel   文件: VectorGraphics2D.java
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
	if (onStroke) {
		return hit(rect, getStroke().createStrokedShape(s), false);
	}

	Area area = new Area(s);
	return area.intersects(rect);
}
 
源代码12 项目: pumpernickel   文件: AbstractGraphics2D.java
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
	if (onStroke) {
		return hit(rect, getStroke().createStrokedShape(s), false);
	}

	Area area = new Area(s);
	return area.intersects(rect);
}
 
源代码13 项目: pentaho-reporting   文件: PdfGraphics2D.java
/**
 * @see Graphics2D#hit(Rectangle, Shape, boolean)
 */
@Override
public boolean hit( final Rectangle rect, Shape s, final boolean onStroke ) {
  if ( onStroke ) {
    s = stroke.createStrokedShape( s );
  }
  s = transform.createTransformedShape( s );
  final Area area = new Area( s );
  if ( clip != null ) {
    area.intersect( clip );
  }
  return area.intersects( rect.x, rect.y, rect.width, rect.height );
}
 
源代码14 项目: TrakEM2   文件: AreaList.java
@Override
public boolean linkPatches() {
	unlinkAll(Patch.class);
	// cheap way: intersection of the patches' bounding box with the area
	Rectangle r = new Rectangle();
	boolean must_lock = false;
	for (final Map.Entry<Long,Area> e : ht_areas.entrySet()) {
		final Layer la = this.layer_set.getLayer(e.getKey());
		if (null == la) {
			Utils.log2("AreaList.linkPatches: ignoring null layer for id " + e.getKey());
			continue;
		}
		final Area area = e.getValue().createTransformedArea(this.at);
		for (final Patch d : la.getAll(Patch.class)) {
			r = d.getBoundingBox(r);
			if (area.intersects(r)) {
				link(d, true);
				if (d.locked) must_lock = true;
			}
		}
	}

	// set the locked flag to this and all linked ones
	if (must_lock && !locked) {
		setLocked(true);
		return true;
	}

	return false;
}
 
源代码15 项目: TrakEM2   文件: AreaList.java
@Override
public boolean intersects(final Layer layer, final Rectangle r) {
	Object ob = ht_areas.get(layer.getId());
	if (null == ob) return false;
	if (AreaList.UNLOADED == ob) {
		ob = loadLayer(layer.getId());
		if (null == ob) return false;
	}
	final Area a = ((Area)ob).createTransformedArea(this.at);
	return a.intersects(r.x, r.y, r.width, r.height);
}
 
源代码16 项目: TrakEM2   文件: Bucket.java
private final void putIn(final int stack_index, final Displayable d, final Area a, final HashMap<Displayable,HashSet<Bucket>> db_map) {
	if (!a.intersects(x, y, w, h)) return;
	// there will be at least one now
	this.empty = false;
	if (null != children) {
		for (final Bucket bu : children) bu.putIn(stack_index, d, a, db_map);
	} else if (null != map) {
		map.put(stack_index, d);
		putToBucketMap(d, db_map); // the db_map
	}
}
 
源代码17 项目: audiveris   文件: Inters.java
/**
 * Lookup the provided list of interpretations for those whose bounds
 * intersect the given area.
 *
 * @param inters the list of interpretations to search for
 * @param order  if the list is already sorted by some order, this may speedup the search
 * @param area   the intersecting area
 * @return the intersected interpretations found, perhaps empty but not null
 */
public static List<Inter> intersectedInters (List<Inter> inters,
                                             GeoOrder order,
                                             Area area)
{
    List<Inter> found = new ArrayList<>();
    Rectangle bounds = area.getBounds();
    double xMax = bounds.getMaxX();
    double yMax = bounds.getMaxY();

    for (Inter inter : inters) {
        if (inter.isRemoved()) {
            continue;
        }

        Rectangle iBox = inter.getBounds();

        if (area.intersects(iBox)) {
            found.add(inter);
        } else {
            switch (order) {
            case BY_ABSCISSA:

                if (iBox.x > xMax) {
                    return found;
                }

                break;

            case BY_ORDINATE:

                if (iBox.y > yMax) {
                    return found;
                }

                break;

            case NONE:
            }
        }
    }

    return found;
}
 
源代码18 项目: 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);
}
 
源代码19 项目: pentaho-reporting   文件: AbstractGraphics2D.java
/**
 * Checks whether or not the specified <code>Shape</code> intersects the specified {@link java.awt.Rectangle}, which
 * is in device space. If <code>onStroke</code> is false, this method checks whether or not the interior of the
 * specified <code>Shape</code> intersects the specified <code>Rectangle</code>. If <code>onStroke</code> is
 * <code>true</code>, this method checks whether or not the <code>Stroke</code> of the specified <code>Shape</code>
 * outline intersects the specified <code>Rectangle</code>. The rendering attributes taken into account include the
 * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code> attributes.
 *
 * @param rect
 *          the area in device space to check for a hit
 * @param s
 *          the <code>Shape</code> to check for a hit
 * @param onStroke
 *          flag used to choose between testing the stroked or the filled shape. If the flag is <code>true</code>, the
 *          <code>Stroke</code> oultine is tested. If the flag is <code>false</code>, the filled <code>Shape</code> is
 *          tested.
 * @return <code>true</code> if there is a hit; <code>false</code> otherwise.
 * @see #setStroke
 * @see #fill
 * @see #draw
 * @see #transform
 * @see #setTransform
 * @see #clip
 * @see #setClip
 */
public boolean hit( final Rectangle rect, Shape s, final boolean onStroke ) {
  if ( onStroke ) {
    s = getStroke().createStrokedShape( s );
  }
  s = getTransform().createTransformedShape( s );
  final Area area = new Area( s );
  final Shape clip = getClip();
  if ( clip != null ) {
    area.intersect( new Area( clip ) );
  }
  return area.intersects( rect.x, rect.y, rect.width, rect.height );
}
 
源代码20 项目: jpexs-decompiler   文件: PDFGraphics.java
/**
   * @see Graphics2D#hit(Rectangle, Shape, boolean)
   */
  public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
      if (onStroke) {
          s = stroke.createStrokedShape(s);
      }
      s = transform.createTransformedShape(s);
      Area area = new Area(s);
      if (clip != null)
          area.intersect(clip);
      return area.intersects(rect.x, rect.y, rect.width, rect.height);
  }