/** * Creates an AffineTransformation defined by a set of control vectors. * Between one and three vectors must be supplied. * * @param src * the source points of the vectors * @param dest * the destination points of the vectors * @return the computed transformation * @throws IllegalArgumentException * if the control vector arrays are too short, long or of different * lengths */ public static AffineTransformation createFromControlVectors(Coordinate[] src, Coordinate[] dest) { if (src.length != dest.length) throw new IllegalArgumentException( "Src and Dest arrays are not the same length"); if (src.length <= 0) throw new IllegalArgumentException("Too few control points"); if (src.length > 3) throw new IllegalArgumentException("Too many control points"); if (src.length == 1) return createFromControlVectors(src[0], dest[0]); if (src.length == 2) return createFromControlVectors(src[0], src[1], dest[0], dest[1]); return createFromControlVectors(src[0], src[1], src[2], dest[0], dest[1], dest[2]); }
@Metadata(description="Transforms a geometry by mapping envelope baseline to target vector") public static Geometry transformByBaseline(Geometry g, Geometry destBaseline) { Envelope env = g.getEnvelopeInternal(); Coordinate src0 = new Coordinate(env.getMinX(), env.getMinY()); Coordinate src1 = new Coordinate(env.getMaxX(), env.getMinY()); Coordinate[] destPts = destBaseline.getCoordinates(); Coordinate dest0 = destPts[0]; Coordinate dest1 = destPts[1]; AffineTransformation trans = AffineTransformationFactory.createFromBaseLines(src0, src1, dest0, dest1); return trans.transform(g); }
private static Geometry fontGlyph(Geometry g, String text, Font font) { Envelope env = FunctionsUtil.getEnvelopeOrDefault(g); GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g); Geometry textGeom = FontGlyphReader.read(text, font, geomFact); Envelope envText = textGeom.getEnvelopeInternal(); if (g != null) { // transform to baseline Coordinate baseText0 = new Coordinate(envText.getMinX(), envText.getMinY()); Coordinate baseText1 = new Coordinate(envText.getMaxX(), envText.getMinY()); Coordinate baseGeom0 = new Coordinate(env.getMinX(), env.getMinY()); Coordinate baseGeom1 = new Coordinate(env.getMaxX(), env.getMinY()); AffineTransformation trans = AffineTransformationFactory.createFromBaseLines(baseText0, baseText1, baseGeom0, baseGeom1); return trans.transform(textGeom); } return textGeom; }
@Metadata(description="Transforms a geometry using one to three control vectors") public static Geometry transformByVectors(Geometry g, Geometry control) { int nControl = control.getNumGeometries(); Coordinate src[] = new Coordinate[nControl]; Coordinate dest[] = new Coordinate[nControl]; for (int i = 0; i < nControl; i++) { Geometry contComp = control.getGeometryN(i); Coordinate[] pts = contComp.getCoordinates(); src[i] = pts[0]; dest[i] = pts[1]; } AffineTransformation trans = AffineTransformationFactory.createFromControlVectors(src, dest); System.out.println(trans); return trans.transform(g); }
void run(double p0x, double p0y, double pp0x, double pp0y ) { Coordinate p0 = new Coordinate(p0x, p0y); Coordinate pp0 = new Coordinate(pp0x, pp0y); AffineTransformation trans = AffineTransformationFactory.createFromControlVectors( p0, pp0); Coordinate dest = new Coordinate(); assertEqualPoint(pp0, trans.transform(p0, dest)); }
void run(double p0x, double p0y, double p1x, double p1y, double pp0x, double pp0y, double pp1x, double pp1y ) { Coordinate p0 = new Coordinate(p0x, p0y); Coordinate p1 = new Coordinate(p1x, p1y); Coordinate pp0 = new Coordinate(pp0x, pp0y); Coordinate pp1 = new Coordinate(pp1x, pp1y); AffineTransformation trans = AffineTransformationFactory.createFromControlVectors( p0, p1, pp0, pp1); Coordinate dest = new Coordinate(); assertEqualPoint(pp0, trans.transform(p0, dest)); assertEqualPoint(pp1, trans.transform(p1, dest)); }