/** * Checks if a segment contains a given point in itself * @param point a point to be checked * @return true if this segment contains given point, false otherwise */ public boolean containsPoint(Vector point) { if (point == null) { return false; } Vector diff1 = point.subtract(startPoint); if (diff1.get(0) < 0 || diff1.get(1) < 0 || diff1.get(2) < 0) { return false; } Vector diff2 = endPoint.subtract(point); if (diff2.get(0) < 0 || diff2.get(1) < 0 || diff2.get(2) < 0) { return false; } return true; } }
/** * Computes the bounding rectangle for this line segment. The rectangle has a rotation 0 degrees * with respect to the coordinate system that the line system is in. For example, if a line segment * is 5 unit long and sits at a 37 degree angle from horizontal, the bounding rectangle will have * origin of the lower left hand end point of the segment, with width = 4 and height = 3. * @return the bounding rectangle */ public Rectangle getBoundingRectangle(){ float x1 = getStartPoint().get(Vector.I1); float y1 = getStartPoint().get(Vector.I2); float x2 = getEndPoint().get(Vector.I1); float y2 = getEndPoint().get(Vector.I2); return new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2-x1), Math.abs(y2-y1)); }
static boolean containsMark(ITextChunkLocation baseLocation, ITextChunkLocation markLocation) { return baseLocation.getStartLocation().get(Vector.I1) <= markLocation.getStartLocation().get(Vector.I1) && baseLocation.getEndLocation().get(Vector.I1) >= markLocation.getEndLocation().get(Vector.I1) && Math.abs(baseLocation.distPerpendicular() - markLocation.distPerpendicular()) <= DIACRITICAL_MARKS_ALLOWED_VERTICAL_DEVIATION; }
@Override public boolean accept(IEventData data, EventType type) { if (type.equals(EventType.RENDER_TEXT)) { TextRenderInfo renderInfo = (TextRenderInfo) data; LineSegment segment = renderInfo.getBaseline(); Vector startPoint = segment.getStartPoint(); Vector endPoint = segment.getEndPoint(); float x1 = startPoint.get(Vector.I1); float y1 = startPoint.get(Vector.I2); float x2 = endPoint.get(Vector.I1); float y2 = endPoint.get(Vector.I2); return filterRect == null || filterRect.intersectsLine(x1, y1, x2, y2); } else { return false; } } }
public CharacterRenderInfo(TextRenderInfo tri) { super(tri == null ? "" : tri.getText(), tri == null ? null : getLocation(tri)); if (tri == null) throw new IllegalArgumentException("TextRenderInfo argument is not nullable."); // determine bounding box float x0 = tri.getDescentLine().getStartPoint().get(0); float y0 = tri.getDescentLine().getStartPoint().get(1); float h = tri.getAscentLine().getStartPoint().get(1) - tri.getDescentLine().getStartPoint().get(1); float w = Math.abs(tri.getBaseline().getStartPoint().get(0) - tri.getBaseline().getEndPoint().get(0)); this.boundingBox = new Rectangle(x0, y0, w, h); }
public TextChunkLocationDefaultImp(Vector startLocation, Vector endLocation, float charSpaceWidth) { this.startLocation = startLocation; this.endLocation = endLocation; this.charSpaceWidth = charSpaceWidth; Vector oVector = endLocation.subtract(startLocation); if (oVector.length() == 0) { oVector = new Vector(1, 0, 0); } orientationVector = oVector.normalize(); orientationMagnitude = (int) (Math.atan2(orientationVector.get(Vector.I2), orientationVector.get(Vector.I1)) * 1000); // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html // the two vectors we are crossing are in the same plane, so the result will be purely // in the z-axis (out of plane) direction, so we just take the I3 component of the result Vector origin = new Vector(0, 0, 1); distPerpendicular = (int) (startLocation.subtract(origin)).cross(orientationVector).get(Vector.I3); distParallelStart = orientationVector.dot(startLocation); distParallelEnd = orientationVector.dot(endLocation); }
Vector mergedStart = new Vector(Math.min(lastTextChunk.getLocation().getStartLocation().get(0), segment.getStartPoint().get(0)), Math.min(lastTextChunk.getLocation().getStartLocation().get(1), segment.getStartPoint().get(1)), Math.min(lastTextChunk.getLocation().getStartLocation().get(2), segment.getStartPoint().get(2))); Vector mergedEnd = new Vector(Math.max(lastTextChunk.getLocation().getEndLocation().get(0), segment.getEndPoint().get(0)), Math.max(lastTextChunk.getLocation().getEndLocation().get(1), segment.getEndPoint().get(1)), Math.max(lastTextChunk.getLocation().getEndLocation().get(2), segment.getEndPoint().get(2))); TextChunk merged = new TextChunk(lastTextChunk.getText(), tclStrat.createLocation(renderInfo, new LineSegment(mergedStart, mergedEnd)));