use of java.awt.Polygon in project TranskribusCore by Transkribus.
the class PointStrUtils method buildPolygon.
public static Polygon buildPolygon(String pointsStr) {
List<Point> coords = (List<Point>) PointStrUtils.buildPointContainer(pointsStr, Collectors.toList(), Point::new, false);
int n = coords.size();
int[] xValues = new int[n];
int[] yValues = new int[n];
for (int i = 0; i < n; i++) {
final Point p = coords.get(i);
xValues[i] = p.x;
yValues[i] = p.y;
}
return new Polygon(xValues, yValues, n);
}
use of java.awt.Polygon in project TranskribusCore by Transkribus.
the class PointStrUtils method getXBounds.
public static Pair<Integer, Integer> getXBounds(String baseline) {
Polygon baselinePoly = PointStrUtils.buildPolygon(baseline);
int baselineMinX = Integer.MAX_VALUE;
int baselineMaxX = Integer.MIN_VALUE;
for (int i = 0; i < baselinePoly.xpoints.length; i++) {
int x = baselinePoly.xpoints[i];
if (x < baselineMinX) {
baselineMinX = x;
}
if (x > baselineMaxX) {
baselineMaxX = x;
}
}
return Pair.of(baselineMinX, baselineMaxX);
}
use of java.awt.Polygon in project OpenNotebook by jaltekruse.
the class CylinderObjectGUI method drawMathObject.
public void drawMathObject(CylinderObject object, Graphics g, Point pageOrigin, float zoomLevel) {
g.setColor(Color.BLACK);
ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness());
Graphics2D g2d = (Graphics2D) g;
Color fillColor = object.getColor();
Polygon fillShape;
if (fillColor != null) {
fillShape = new Polygon();
fillShape.addPoint((int) (object.getSide1pts()[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (object.getSide1pts()[0].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (object.getSide1pts()[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (object.getSide1pts()[1].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (object.getSide2pts()[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (object.getSide2pts()[1].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (object.getSide2pts()[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (object.getSide2pts()[0].gety() * sap.getHeight()) + sap.getyOrigin());
g2d.setColor(fillColor);
g2d.fillPolygon(fillShape);
if (object.isFlippedVertically()) {
g2d.fillOval(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), (int) (object.getInsideEdgeOfDisk().gety() * sap.getHeight()));
g2d.setColor(MathObjectGUI.brightenColor(fillColor));
g2d.fillOval(sap.getxOrigin(), (int) (object.getPointBehindCylinder().gety() * sap.getHeight()) + sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
} else {
g2d.fillOval(sap.getxOrigin(), (int) (object.getPointBehindCylinder().gety() * sap.getHeight()) + sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
g2d.setColor(MathObjectGUI.brightenColor(fillColor));
g2d.fillOval(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), (int) (object.getInsideEdgeOfDisk().gety() * sap.getHeight()));
}
}
g2d.setStroke(new BasicStroke(sap.getLineThickness(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
g2d.setColor(Color.BLACK);
g.drawLine((int) (object.getSide1pts()[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (object.getSide1pts()[0].gety() * sap.getHeight()) + sap.getyOrigin(), (int) (object.getSide1pts()[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (object.getSide1pts()[1].gety() * sap.getHeight()) + sap.getyOrigin());
g.drawLine((int) (object.getSide2pts()[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (object.getSide2pts()[0].gety() * sap.getHeight()) + sap.getyOrigin(), (int) (object.getSide2pts()[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (object.getSide2pts()[1].gety() * sap.getHeight()) + sap.getyOrigin());
if (object.isFlippedVertically()) {
g.drawArc(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()), 0, 180);
g.drawOval(sap.getxOrigin(), (int) (object.getPointBehindCylinder().gety() * sap.getHeight()) + sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
} else {
g.drawOval(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
g.drawArc(sap.getxOrigin(), (int) (object.getPointBehindCylinder().gety() * sap.getHeight()) + sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()), 180, 180);
}
g2d.setStroke(new BasicStroke(1));
}
use of java.awt.Polygon in project OpenNotebook by jaltekruse.
the class CubeObjectGUI method drawMathObject.
public void drawMathObject(CubeObject object, Graphics g, Point pageOrigin, float zoomLevel) {
g.setColor(Color.BLACK);
ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness());
Graphics2D g2d = (Graphics2D) g;
Color fillColor = object.getColor();
Polygon fillShape;
GridPoint[] outsidePoints = new GridPoint[6];
int index = 0;
for (GridPoint p : CubeObject.getOutsidePoints()) {
outsidePoints[index] = new GridPoint(p.getx(), p.gety());
index++;
}
GridPoint innerPt = new GridPoint(CubeObject.getInnerPoint().getx(), CubeObject.getInnerPoint().gety());
GridPoint side1Pt = new GridPoint(CubeObject.getSide1Pt().getx(), CubeObject.getSide1Pt().gety());
GridPoint side2Pt = new GridPoint(CubeObject.getSide2Pt().getx(), CubeObject.getSide2Pt().gety());
GridPoint cornerPt = new GridPoint(CubeObject.getCornerPt().getx(), CubeObject.getCornerPt().gety());
if (object.isFlippedVertically()) {
for (GridPoint p : outsidePoints) {
flipPointVertically(p);
}
flipPointVertically(innerPt);
flipPointVertically(cornerPt);
flipPointVertically(side1Pt);
flipPointVertically(side2Pt);
}
if (object.isFlippedHorizontally()) {
for (GridPoint p : outsidePoints) {
flipPointHorizontally(p);
}
flipPointHorizontally(innerPt);
flipPointHorizontally(cornerPt);
flipPointHorizontally(side1Pt);
flipPointHorizontally(side2Pt);
}
if (fillColor != null) {
fillShape = new Polygon();
fillShape.addPoint((int) (outsidePoints[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[0].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (outsidePoints[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[1].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (outsidePoints[2].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[2].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
g2d.setColor(fillColor);
g2d.fillPolygon(fillShape);
fillShape = new Polygon();
fillShape.addPoint((int) (outsidePoints[2].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[2].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (outsidePoints[3].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[3].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (outsidePoints[4].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[4].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
g2d.setColor(MathObjectGUI.brightenColor(fillColor));
g2d.fillPolygon(fillShape);
fillShape = new Polygon();
fillShape.addPoint((int) (outsidePoints[4].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[4].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (outsidePoints[5].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[5].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (outsidePoints[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[0].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
g2d.setColor(MathObjectGUI.brightenColor(fillColor));
g2d.fillPolygon(fillShape);
}
g2d.setStroke(new BasicStroke(sap.getLineThickness(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
g2d.setColor(Color.BLACK);
Polygon p = new Polygon();
for (int i = 0; i < outsidePoints.length; i++) {
p.addPoint((int) (outsidePoints[i].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (outsidePoints[i].gety() * sap.getHeight()) + sap.getyOrigin());
}
g.drawLine((int) (cornerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (cornerPt.gety() * sap.getHeight()) + sap.getyOrigin(), (int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
g.drawLine((int) (side1Pt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (side1Pt.gety() * sap.getHeight()) + sap.getyOrigin(), (int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
g.drawLine((int) (side2Pt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (side2Pt.gety() * sap.getHeight()) + sap.getyOrigin(), (int) (innerPt.getx() * sap.getWidth()) + sap.getxOrigin(), (int) (innerPt.gety() * sap.getHeight()) + sap.getyOrigin());
g2d.drawPolygon(p);
g2d.setStroke(new BasicStroke(1));
}
use of java.awt.Polygon in project OpenNotebook by jaltekruse.
the class PolygonObjectGUI method drawMathObject.
public void drawMathObject(PolygonObject object, Graphics g, Point pageOrigin, float zoomLevel) {
g.setColor(Color.BLACK);
ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness());
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(sap.getLineThickness()));
Polygon p = new Polygon();
GridPoint[] points = object.getAdjustedVertices();
for (int i = 0; i < points.length; i++) {
p.addPoint((int) (points[i].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (points[i].gety() * sap.getHeight()) + sap.getyOrigin());
}
if (object.getColor() != null) {
g2d.setColor(object.getColor());
g2d.fillPolygon(p);
g2d.setColor(Color.BLACK);
}
g2d.drawPolygon(p);
g2d.setStroke(new BasicStroke(1));
}
Aggregations