Search in sources :

Example 51 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class SVGEllipse method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null || doc.getFirstChild().getDefs() == null)
        throw new IllegalArgumentException();
    final IPoint tl = shape.getTopLeftPoint();
    final IPoint br = shape.getBottomRightPoint();
    final double tlx = tl.getX();
    final double tly = tl.getY();
    final double brx = br.getX();
    final double bry = br.getY();
    SVGElement elt;
    final SVGElement root = new SVGGElement(doc);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_ELLIPSE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    final double gap = getPositionGap();
    final double width = Math.max(1., (brx - tlx + gap) / 2.);
    final double height = Math.max(1., (bry - tly + gap) / 2.);
    final double x = (brx + tlx) / 2.;
    final double y = (bry + tly) / 2.;
    if (shape.hasShadow()) {
        elt = new SVGEllipseElement(x, y, width, height, doc);
        setSVGShadowAttributes(elt, true);
        root.appendChild(elt);
    }
    if (shape.hasShadow() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE)) {
        // The background of the borders must be filled is there is a shadow.
        elt = new SVGEllipseElement(x, y, width, height, doc);
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGEllipseElement(x, y, width, height, doc);
    setSVGAttributes(doc, elt, true);
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        elt = new SVGEllipseElement(x, y, width, height, doc);
        setSVGDoubleBordersAttributes(elt);
        root.appendChild(elt);
    }
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGEllipseElement(net.sf.latexdraw.parsers.svg.SVGEllipseElement)

Example 52 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class SVGModifiablePointsShape method getLinePointsFromSVGPathElement.

/**
 * Gets the line points from the given SVGPathElement
 */
static List<IPoint> getLinePointsFromSVGPathElement(final SVGPathElement elt) {
    if (elt == null) {
        return Collections.emptyList();
    }
    final SVGPathSegList segs = elt.getSegList();
    final int size = segs.get(segs.size() - 1) instanceof SVGPathSegClosePath ? segs.size() - 1 : segs.size();
    // Creating a point to support when the first path element is relative.
    Point2D pt = new Point2D.Double();
    final List<IPoint> pts = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        final SVGPathSeg seg = segs.get(i);
        if (!(seg instanceof SVGPathSegLineto)) {
            // $NON-NLS-1$
            throw new IllegalArgumentException("The given SVG path element is not a set of lines.");
        }
        pt = ((SVGPathSegLineto) seg).getPoint(pt);
        pts.add(ShapeFactory.INST.createPoint(pt.getX(), pt.getY()));
    }
    return pts;
}
Also used : SVGPathSeg(net.sf.latexdraw.parsers.svg.path.SVGPathSeg) Point2D(java.awt.geom.Point2D) ArrayList(java.util.ArrayList) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) SVGPathSegLineto(net.sf.latexdraw.parsers.svg.path.SVGPathSegLineto) SVGPathSegList(net.sf.latexdraw.parsers.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parsers.svg.path.SVGPathSegClosePath) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 53 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class ViewSingleShape method computeGradient.

private LinearGradient computeGradient() {
    final IPoint tl = model.getTopLeftPoint();
    final IPoint br = model.getBottomRightPoint();
    IPoint pt1 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, tl.getY());
    IPoint pt2 = ShapeFactory.INST.createPoint((tl.getX() + br.getX()) / 2d, br.getY());
    double angle = model.getGradAngle() % (2d * Math.PI);
    double gradMidPt = model.getGradMidPt();
    if (tl.equals(br)) {
        return null;
    }
    if (angle < 0d) {
        angle = 2d * Math.PI + angle;
    }
    if (angle >= Math.PI) {
        gradMidPt = 1d - gradMidPt;
        angle -= Math.PI;
    }
    if (MathUtils.INST.equalsDouble(angle, 0d)) {
        if (gradMidPt < 0.5)
            pt1.setY(pt2.getY() - Point2D.distance(pt2.getX(), pt2.getY(), (tl.getX() + br.getX()) / 2d, br.getY()));
        pt2.setY(tl.getY() + (br.getY() - tl.getY()) * gradMidPt);
    } else {
        if (MathUtils.INST.equalsDouble(angle % (Math.PI / 2d), 0d)) {
            pt1 = ShapeFactory.INST.createPoint(tl.getX(), (tl.getY() + br.getY()) / 2d);
            pt2 = ShapeFactory.INST.createPoint(br.getX(), (tl.getY() + br.getY()) / 2d);
            if (gradMidPt < 0.5)
                pt1.setX(pt2.getX() - Point2D.distance(pt2.getX(), pt2.getY(), br.getX(), (tl.getY() + br.getY()) / 2d));
            pt2.setX(tl.getX() + (br.getX() - tl.getX()) * gradMidPt);
        } else {
            final IPoint cg = model.getGravityCentre();
            final ILine l2;
            final ILine l;
            pt1 = pt1.rotatePoint(cg, -angle);
            pt2 = pt2.rotatePoint(cg, -angle);
            l = ShapeFactory.INST.createLine(pt1, pt2);
            if (angle >= 0d && angle < Math.PI / 2d) {
                l2 = l.getPerpendicularLine(tl);
            } else {
                l2 = l.getPerpendicularLine(ShapeFactory.INST.createPoint(tl.getX(), br.getY()));
            }
            pt1 = l.getIntersection(l2);
            final double distance = Point2D.distance(cg.getX(), cg.getY(), pt1.getX(), pt1.getY());
            l.setX1(pt1.getX());
            l.setY1(pt1.getY());
            final IPoint[] pts = l.findPoints(pt1, 2d * distance * gradMidPt);
            pt2 = pts[0];
            if (gradMidPt < 0.5) {
                pt1 = pt1.rotatePoint(model.getGravityCentre(), Math.PI);
            }
        }
    }
    return new LinearGradient(pt1.getX(), pt1.getY(), pt2.getX(), pt2.getY(), false, CycleMethod.NO_CYCLE, new Stop(0d, model.getGradColStart().toJFX()), new Stop(1d, model.getGradColEnd().toJFX()));
}
Also used : LinearGradient(javafx.scene.paint.LinearGradient) ILine(net.sf.latexdraw.models.interfaces.shape.ILine) Stop(javafx.scene.paint.Stop) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 54 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class ViewArrowableTrait method getArrowReducedPoint.

protected static Optional<IPoint> getArrowReducedPoint(final IArrow arrow) {
    final ILine l = arrow.getArrowLine();
    if (l == null) {
        return Optional.empty();
    }
    final IPoint[] points = l.findPoints(l.getX1(), l.getY1(), arrow.getArrowShapeLength());
    if (points.length == 0) {
        return Optional.empty();
    }
    return Arrays.stream(points).reduce((p1, p2) -> p1.distance(l.getPoint2()) < p2.distance(l.getPoint2()) ? p1 : p2);
}
Also used : ILine(net.sf.latexdraw.models.interfaces.shape.ILine) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 55 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class ViewDot method setPathOLikeDot.

private void setPathOLikeDot(final double dec) {
    final IPoint pos = model.getPosition();
    final double radius = (model.getDiametre() - dec) / 2d;
    dot.setCenterX(pos.getX());
    dot.setCenterY(pos.getY());
    dot.setRadiusX(radius);
    dot.setRadiusY(radius);
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Aggregations

IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)191 Test (org.junit.Test)45 HelperTest (net.sf.latexdraw.HelperTest)25 Theory (org.junit.experimental.theories.Theory)21 IShape (net.sf.latexdraw.models.interfaces.shape.IShape)15 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)11 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)11 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)10 ILine (net.sf.latexdraw.models.interfaces.shape.ILine)10 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)9 IGroup (net.sf.latexdraw.models.interfaces.shape.IGroup)9 ArrayList (java.util.ArrayList)8 MathUtils (net.sf.latexdraw.models.MathUtils)8 Collections (java.util.Collections)7 IPolygon (net.sf.latexdraw.models.interfaces.shape.IPolygon)7 Arrays (java.util.Arrays)6 Cursor (javafx.scene.Cursor)6 BorderPos (net.sf.latexdraw.models.interfaces.shape.BorderPos)6 IModifiablePointsShape (net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape)6 Inject (net.sf.latexdraw.util.Inject)6