/** * @return the length of this line segment */ public float getLength(){ return endPoint.subtract(startPoint).length(); }
} else if (!firstRender){ if (result.charAt(result.length()-1) != ' ' && renderInfo.getText().length() > 0 && renderInfo.getText().charAt(0) != ' '){ // we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space float spacing = lastEnd.subtract(start).length(); if (spacing > renderInfo.getSingleSpaceWidth()/2f){ appendTextChunk(" ");
/** * 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); }
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); }