/** * Multiplies the vector by a scalar * * @param by the scalar to multiply by * @return the result of the scalar multiplication */ public Vector multiply(float by) { float x = vals[I1] * by; float y = vals[I2] * by; float z = vals[I3] * by; return new Vector(x, y, z); }
/** * Computes the difference between this vector and the specified vector * * @param v the vector to subtract from this one * @return the results of the subtraction */ public Vector subtract(Vector v) { float x = vals[I1] - v.vals[I1]; float y = vals[I2] - v.vals[I2]; float z = vals[I3] - v.vals[I3]; return new Vector(x, y, z); }
/** * Computes the cross product of this vector and the specified vector * * @param with the vector to cross this vector with * @return the cross product */ public Vector cross(Vector with) { float x = vals[I2] * with.vals[I3] - vals[I3] * with.vals[I2]; float y = vals[I3] * with.vals[I1] - vals[I1] * with.vals[I3]; float z = vals[I1] * with.vals[I2] - vals[I2] * with.vals[I1]; return new Vector(x, y, z); }
/** * @param height the height, in text space * @return the height in user space */ private float convertHeightFromTextSpaceToUserSpace(float height) { LineSegment textSpace = new LineSegment(new Vector(0, 0, 1), new Vector(0, height, 1)); LineSegment userSpace = textSpace.transformBy(textToUserSpaceTransformMatrix); return userSpace.getLength(); }
/** * @param width the width, in text space * @return the width in user space */ private float convertWidthFromTextSpaceToUserSpace(float width) { LineSegment textSpace = new LineSegment(new Vector(0, 0, 1), new Vector(width, 0, 1)); LineSegment userSpace = textSpace.transformBy(textToUserSpaceTransformMatrix); return userSpace.getLength(); }
/** * @return a vector in User space representing the start point of the image */ public Vector getStartPoint() { return new Vector(0, 0, 1).cross(ctm); }
/** * Normalizes the vector (i.e. returns the unit vector in the same orientation as this vector) * * @return the unit vector */ public Vector normalize() { float l = this.length(); float x = vals[I1] / l; float y = vals[I2] / l; float z = vals[I3] / l; return new Vector(x, y, z); }
private LineSegment getUnscaledBaselineWithOffset(float yOffset) { checkGraphicsState(); // we need to correct the width so we don't have an extra character and word spaces at the end. The extra character and word spaces // are important for tracking relative text coordinate systems, but should not be part of the baseline String unicodeStr = string.toUnicodeString(); float correctedUnscaledWidth = getUnscaledWidth() - (gs.getCharSpacing() + (unicodeStr.length() > 0 && unicodeStr.charAt(unicodeStr.length() - 1) == ' ' ? gs.getWordSpacing() : 0)) * (gs.getHorizontalScaling() / 100f); return new LineSegment(new Vector(0, yOffset, 1), new Vector(correctedUnscaledWidth, yOffset, 1)); }
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); }
/** * Computes the cross product of this vector and the specified matrix * * @param by the matrix to cross this vector with * @return the result of the cross product */ public Vector cross(Matrix by) { float x = vals[I1] * by.get(Matrix.I11) + vals[I2] * by.get(Matrix.I21) + vals[I3] * by.get(Matrix.I31); float y = vals[I1] * by.get(Matrix.I12) + vals[I2] * by.get(Matrix.I22) + vals[I3] * by.get(Matrix.I32); float z = vals[I1] * by.get(Matrix.I13) + vals[I2] * by.get(Matrix.I23) + vals[I3] * by.get(Matrix.I33); return new Vector(x, y, z); }
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)));