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;
}
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;
}
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;
}
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));
}
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());
}
Aggregations