Search in sources :

Example 76 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class SVGGrid method createSVGGrid.

/**
 * Creates the SVG element corresponding to the grid.
 */
void createSVGGrid(final SVGElement elt, final SVGDocument document) {
    if (elt == null || document == null) {
        return;
    }
    // Initialisation of the parameters.
    final String prefix = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final double unit = shape.getUnit();
    final int subGridDiv = shape.getSubGridDiv();
    double xStep = Shape.PPC * unit;
    final double xSubStep;
    double yStep = Shape.PPC * unit;
    final double ySubStep;
    xStep *= shape.getGridEndX() < shape.getGridStartX() ? -1 : 1;
    yStep *= shape.getGridEndY() < shape.getGridStartY() ? -1 : 1;
    xSubStep = xStep / subGridDiv;
    ySubStep = yStep / subGridDiv;
    final int subGridDots = shape.getSubGridDots();
    final Point tl = shape.getTopLeftPoint();
    final Point br = shape.getBottomRightPoint();
    double tlx = tl.getX();
    double tly = tl.getY();
    double brx = br.getX();
    double bry = br.getY();
    final double minX = shape.getGridMinX();
    final double maxX = shape.getGridMaxX();
    final double minY = shape.getGridMinY();
    final double maxY = shape.getGridMaxY();
    final double absStep = Math.abs(xStep);
    final Color subGridColor = shape.getSubGridColour();
    final Color linesColor = shape.getLineColour();
    final double gridWidth = shape.getGridWidth();
    final double posX = Math.min(shape.getGridStartX(), shape.getGridEndX()) * Shape.PPC * unit;
    final double posY = -Math.min(shape.getGridStartY(), shape.getGridEndY()) * Shape.PPC * unit;
    final Point position = shape.getPosition();
    tlx -= position.getX();
    brx -= position.getX();
    tly -= position.getY();
    bry -= position.getY();
    elt.setAttribute(SVGAttributes.SVG_TRANSFORM, new SVGTransform.SVGTranslateTransformation(position.getX(), position.getY()).toString());
    // Creation of the sub-grid
    if (subGridDots > 0) {
        createSVGSubGridDots(document, elt, prefix, subGridDiv, unit, xSubStep, ySubStep, minX, maxX, minY, maxY, subGridDots, shape.getSubGridWidth(), tlx, tly, brx, bry, subGridColor);
    } else {
        if (subGridDiv > 1) {
            createSVGSubGridDiv(document, elt, prefix, subGridDiv, xSubStep, ySubStep, minX, maxX, minY, maxY, subGridDots, shape.getSubGridWidth(), tlx, tly, brx, bry, subGridColor, posX, posY, xStep, yStep);
        }
    }
    if (shape.getGridDots() > 0) {
        createSVGGridDots(document, elt, prefix, absStep, minX, maxX, minY, maxY, tlx, tly, brx, bry, unit, posX, posY, xStep, yStep, gridWidth, linesColor);
    } else {
        createSVGGridDiv(document, elt, prefix, minX, maxX, minY, maxY, tlx, tly, brx, bry, posX, posY, xStep, yStep, gridWidth, linesColor);
    }
    if (shape.getLabelsSize() > 0) {
        createSVGGridLabels(document, elt, prefix, minX, maxX, minY, maxY, tlx, tly, xStep, yStep, gridWidth, absStep);
    }
    if (MathUtils.INST.equalsDouble(shape.getRotationAngle() % (Math.PI * 2), 0.)) {
        setSVGRotationAttribute(elt);
    }
}
Also used : Color(net.sf.latexdraw.model.api.shape.Color) Point(net.sf.latexdraw.model.api.shape.Point) Point(net.sf.latexdraw.model.api.shape.Point)

Example 77 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class PSTBezierCurveView method getCode.

@Override
@NotNull
public String getCode(@NotNull final Point origin, final float ppc) {
    if (shape.getNbPoints() < 2) {
        return "";
    }
    final int size = shape.getNbPoints();
    final StringBuilder coord = new StringBuilder();
    final List<Point> pts = shape.getPoints();
    final List<Point> fCtrlPts = shape.getFirstCtrlPts();
    final List<Point> sCtrlPts = shape.getSecondCtrlPts();
    final double originx = origin.getX();
    final double originy = origin.getY();
    coord.append('(').append(MathUtils.INST.getCutNumberFloat((pts.get(0).getX() - originx) / ppc));
    coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - pts.get(0).getY()) / ppc));
    coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((fCtrlPts.get(0).getX() - originx) / ppc));
    coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - fCtrlPts.get(0).getY()) / ppc));
    coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((fCtrlPts.get(1).getX() - originx) / ppc));
    coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - fCtrlPts.get(1).getY()) / ppc));
    coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((pts.get(1).getX() - originx) / ppc));
    coord.append(',').append(MathUtils.INST.getCutNumber((originy - pts.get(1).getY()) / ppc)).append(')');
    for (int i = 2; i < size; i++) {
        final Point ctrlPt1 = fCtrlPts.get(i);
        final Point ctrlPt2 = sCtrlPts.get(i - 1);
        coord.append('(').append(MathUtils.INST.getCutNumberFloat((ctrlPt2.getX() - originx) / ppc));
        coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - ctrlPt2.getY()) / ppc));
        coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((ctrlPt1.getX() - originx) / ppc));
        coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - ctrlPt1.getY()) / ppc));
        coord.append(')').append('(');
        final Point pt = pts.get(i);
        coord.append(MathUtils.INST.getCutNumberFloat((pt.getX() - originx) / ppc)).append(',');
        coord.append(MathUtils.INST.getCutNumberFloat((originy - pt.getY()) / ppc)).append(')');
    }
    if (!shape.isOpened()) {
        final Point ctrlPt1 = sCtrlPts.get(0);
        final Point ctrlPt2 = sCtrlPts.get(sCtrlPts.size() - 1);
        coord.append('(').append(MathUtils.INST.getCutNumberFloat((ctrlPt2.getX() - originx) / ppc));
        coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - ctrlPt2.getY()) / ppc));
        coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((ctrlPt1.getX() - originx) / ppc));
        coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - ctrlPt1.getY()) / ppc));
        coord.append(')').append('(');
        final Point pt = pts.get(0);
        coord.append(MathUtils.INST.getCutNumberFloat((pt.getX() - originx) / ppc)).append(',');
        coord.append(MathUtils.INST.getCutNumberFloat((originy - pt.getY()) / ppc)).append(')');
    }
    final StringBuilder code = new StringBuilder();
    // NON-NLS
    code.append("\\psbezier[").append(getPropertiesCode(ppc)).append(']');
    final StringBuilder arrowsStyle = getArrowsStyleCode();
    if (arrowsStyle != null) {
        code.append(arrowsStyle);
    }
    code.append(coord);
    return code.toString();
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class PSTFrameView method getCode.

@Override
@NotNull
public String getCode(@NotNull final Point position, final float ppc) {
    final StringBuilder params = getPropertiesCode(ppc);
    final Point tl = shape.getTopLeftPoint();
    final Point br = shape.getBottomRightPoint();
    final double x1 = tl.getX() - position.getX();
    final double x2 = br.getX() - position.getX();
    final double y1 = position.getY() - tl.getY();
    final double y2 = position.getY() - br.getY();
    final StringBuilder code = new StringBuilder();
    if (shape.isRoundCorner()) {
        // NON-NLS
        params.append(", framearc=").append(MathUtils.INST.getCutNumberFloat(shape.getLineArc()));
    }
    final StringBuilder rotation = getRotationHeaderCode(ppc, position);
    if (rotation != null) {
        code.append(rotation);
    }
    // NON-NLS
    code.append("\\psframe[");
    code.append(params);
    code.append(']').append('(');
    code.append(MathUtils.INST.getCutNumberFloat(x2 / ppc)).append(',');
    code.append(MathUtils.INST.getCutNumberFloat(y1 / ppc)).append(')').append('(');
    code.append(MathUtils.INST.getCutNumberFloat(x1 / ppc)).append(',');
    code.append(MathUtils.INST.getCutNumberFloat(y2 / ppc)).append(')');
    if (rotation != null) {
        code.append('}');
    }
    return code.toString();
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class PSTGridView method getCode.

@Override
@NotNull
public String getCode(@NotNull final Point pt, final float ppc) {
    final int startX;
    final int startY;
    final int endX;
    final int endY;
    final boolean isXLabelSouth = shape.isXLabelSouth();
    final boolean isYLabelWest = shape.isYLabelWest();
    final Point position = shape.getPosition();
    final StringBuilder start = new StringBuilder();
    final StringBuilder end = new StringBuilder();
    final StringBuilder rot = getRotationHeaderCode(ppc, position);
    final StringBuilder coord = new StringBuilder();
    final double unit = shape.getUnit();
    final double gridStartx = shape.getGridStartX();
    final double gridStarty = shape.getGridStartY();
    final double gridEndx = shape.getGridEndX();
    final double gridEndy = shape.getGridEndY();
    final StringBuilder code = new StringBuilder();
    if (isXLabelSouth) {
        startY = (int) gridStarty;
        endY = (int) gridEndy;
    } else {
        startY = (int) gridEndy;
        endY = (int) gridStarty;
    }
    if (isYLabelWest) {
        startX = (int) gridStartx;
        endX = (int) gridEndx;
    } else {
        startX = (int) gridEndx;
        endX = (int) gridStartx;
    }
    coord.append('(').append((int) shape.getOriginX()).append(',').append((int) shape.getOriginY()).append(')');
    coord.append('(').append(startX).append(',').append(startY).append(')');
    coord.append('(').append(endX).append(',').append(endY).append(')');
    if (!MathUtils.INST.equalsDouble(unit, PSTricksConstants.DEFAULT_UNIT)) {
        // NON-NLS
        end.append("\n\\psset{unit=").append(PSTricksConstants.DEFAULT_UNIT).append(PSTricksConstants.TOKEN_CM).append('}');
    }
    if (!MathUtils.INST.equalsDouble(position.getX(), 0.0) || !MathUtils.INST.equalsDouble(position.getY(), 0.0)) {
        final float posX = MathUtils.INST.getCutNumberFloat((position.getX() - pt.getX()) / ppc);
        final float posY = MathUtils.INST.getCutNumberFloat((pt.getY() - position.getY()) / ppc);
        end.append('}');
        // NON-NLS
        start.append("\\rput(").append(posX).append(',').append(posY).append(')').append('{');
    }
    if (rot != null) {
        start.append(rot);
        end.insert(0, '}');
    }
    code.append(start);
    // NON-NLS
    code.append("\\psgrid[");
    code.append(getParamsCode(ppc, unit));
    code.append(']');
    code.append(coord);
    code.append(end);
    return code.toString();
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with Point

use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.

the class PSTRhombusView method getCode.

@Override
@NotNull
public String getCode(@NotNull final Point origin, final float ppc) {
    final Point tl = shape.getTopLeftPoint();
    final Point br = shape.getBottomRightPoint();
    final double tlx = tl.getX();
    final double tly = tl.getY();
    final double brx = br.getX();
    final double bry = br.getY();
    final double xCenter = (tlx + brx) / 2f - origin.getX();
    final double yCenter = origin.getY() - (tly + bry) / 2f;
    final StringBuilder params = getPropertiesCode(ppc);
    final double rotationAngle = Math.toDegrees(shape.getRotationAngle()) % 360;
    final StringBuilder code = new StringBuilder();
    if (!MathUtils.INST.equalsDouble(rotationAngle, 0.0)) {
        // NON-NLS
        params.append(", gangle=").append(MathUtils.INST.getCutNumberFloat(-rotationAngle));
    }
    // NON-NLS
    code.append("\\psdiamond[");
    code.append(params);
    code.append(']').append('(');
    code.append(MathUtils.INST.getCutNumberFloat(xCenter / ppc)).append(',');
    code.append(MathUtils.INST.getCutNumberFloat(yCenter / ppc)).append(')').append('(');
    code.append(MathUtils.INST.getCutNumberFloat((brx - tlx) / 2f) / ppc).append(',');
    code.append(MathUtils.INST.getCutNumberFloat((bry - tly) / 2f) / ppc).append(')');
    return code.toString();
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Point (net.sf.latexdraw.model.api.shape.Point)139 Test (org.junit.Test)52 HelperTest (net.sf.latexdraw.HelperTest)27 Theory (org.junit.experimental.theories.Theory)23 NotNull (org.jetbrains.annotations.NotNull)19 Line (net.sf.latexdraw.model.api.shape.Line)10 Shape (net.sf.latexdraw.model.api.shape.Shape)9 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)9 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)9 Test (org.junit.jupiter.api.Test)8 ArrayList (java.util.ArrayList)7 Polyline (net.sf.latexdraw.model.api.shape.Polyline)5 Color (javafx.scene.paint.Color)4 MathUtils (net.sf.latexdraw.model.MathUtils)4 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)4 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)4 Canvas (net.sf.latexdraw.view.jfx.Canvas)4 Point2D (java.awt.geom.Point2D)3 List (java.util.List)3 ShapeData (net.sf.latexdraw.data.ShapeData)3