Search in sources :

Example 31 with Point

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

the class PSTPolygonView method getPointsCode.

/**
 * @param position The reference point of the PSTricks drawing.
 * @param ppc The number of pixels per centimetre.
 * @return The PSTricks code of the polygon coordinates.
 */
@NotNull
protected StringBuilder getPointsCode(@NotNull final Point position, final float ppc) {
    Point p;
    int i;
    final int size = shape.getNbPoints();
    final StringBuilder points = new StringBuilder();
    for (i = 0; i < size; i++) {
        p = shape.getPtAt(i);
        points.append('(').append(MathUtils.INST.getCutNumberFloat((p.getX() - position.getX()) / ppc));
        points.append(',').append(MathUtils.INST.getCutNumberFloat((position.getY() - p.getY()) / ppc)).append(')');
    }
    return points;
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with Point

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

the class SVGCircle method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (doc.getFirstChild().getDefs() == null) {
        return null;
    }
    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();
    SVGElement elt;
    final SVGElement shad;
    final SVGElement dblBord;
    final SVGElement root = new SVGGElement(doc);
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_CIRCLE);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    final double gap = getPositionGap();
    final double abs = Math.abs((brx - tlx + gap) / 2d);
    if (shape.hasShadow()) {
        shad = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, abs, doc);
        setSVGShadowAttributes(shad, true);
        root.appendChild(shad);
    }
    if (shape.hasShadow() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken())) {
        // The background of the borders must be filled is there is a shadow.
        elt = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, abs, doc);
        setSVGBorderBackground(elt, root);
    }
    elt = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, abs, doc);
    root.appendChild(elt);
    if (shape.hasDbleBord()) {
        dblBord = new SVGCircleElement((brx + tlx) / 2d, (bry + tly) / 2d, abs, doc);
        setSVGDoubleBordersAttributes(dblBord);
        root.appendChild(dblBord);
    }
    setSVGAttributes(doc, elt, true);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGCircleElement(net.sf.latexdraw.parser.svg.SVGCircleElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) Point(net.sf.latexdraw.model.api.shape.Point)

Example 33 with Point

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

the class SVGEllipse method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (doc.getFirstChild().getDefs() == null) {
        return null;
    }
    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();
    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() && !PSTricksConstants.LINE_NONE_STYLE.equals(shape.getLineStyle().getLatexToken())) {
        // 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.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) Point(net.sf.latexdraw.model.api.shape.Point) SVGEllipseElement(net.sf.latexdraw.parser.svg.SVGEllipseElement)

Example 34 with Point

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

the class TestPolygon method testConstructor.

@Test
public void testConstructor() {
    final Point pt1 = ShapeFactory.INST.createPoint(1, 1);
    final Point pt2 = ShapeFactory.INST.createPoint(2, 2);
    final Polygon pol = ShapeFactory.INST.createPolygon(Arrays.asList(pt1, pt2));
    assertEquals(pt1, pol.getPtAt(0));
    assertEquals(pt2, pol.getPtAt(-1));
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Polygon(net.sf.latexdraw.model.api.shape.Polygon) Test(org.junit.Test)

Example 35 with Point

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

the class TestPositionShapeBase method testGetSetPositionKONULL.

@Theory
public void testGetSetPositionKONULL(@PosShapeData final PositionShape shape) {
    final Point pt = ShapeFactory.INST.createPoint(15d, 25d);
    shape.setPosition(pt);
    shape.setPosition(null);
    assertEqualsDouble(pt.getX(), shape.getPosition().getX());
    assertEqualsDouble(pt.getY(), shape.getPosition().getY());
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) Theory(org.junit.experimental.theories.Theory)

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