use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class Canvas method convertToOrigin.
/**
* Converts the given point in the coordinate system based on the canvas' origin. The given
* point must be in the coordinate system of a container widget (the top-left point is the origin).
* @param pt The point to convert.
* @return The converted point or null if the given point is null.
*/
public IPoint convertToOrigin(final IPoint pt) {
final IPoint convertion;
if (pt == null) {
convertion = null;
} else {
convertion = ShapeFactory.INST.createPoint(pt);
convertion.translate(-ORIGIN.getX(), -ORIGIN.getY());
}
return convertion;
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class PSTTriangleView method getCode.
@Override
public String getCode(final IPoint origin, final float ppc) {
if (!MathUtils.INST.isValidPt(origin) || ppc < 1)
return "";
final IPoint tl = shape.getTopLeftPoint();
final IPoint br = shape.getBottomRightPoint();
final double tlx = tl.getX();
final double brx = br.getX();
final double bry = br.getY();
final StringBuilder rot = getRotationHeaderCode(ppc, origin);
final StringBuilder code = new StringBuilder();
if (rot != null)
code.append(rot);
// $NON-NLS-1$
code.append("\\pstriangle[");
code.append(getPropertiesCode(ppc)).append(']').append('(');
code.append(MathUtils.INST.getCutNumberFloat(((tlx + brx) / 2. - origin.getX()) / ppc)).append(',');
code.append(MathUtils.INST.getCutNumberFloat((origin.getY() - bry) / ppc)).append(')').append('(');
code.append(MathUtils.INST.getCutNumberFloat((brx - tlx) / ppc)).append(',');
code.append(MathUtils.INST.getCutNumberFloat((bry - tl.getY()) / ppc)).append(')');
if (rot != null)
code.append('}');
return code.toString();
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class SVGAxes method createFrame.
private void createFrame(final SVGElement elt, final SVGDocument document) {
final double gridEndx = shape.getGridEndX();
final double gridEndy = shape.getGridEndY();
if (gridEndx > 0 || gridEndy > 0) {
final double positionx = shape.getPosition().getX();
final double positiony = shape.getPosition().getY();
final double xMax = positionx + gridEndx * IShape.PPC;
final double yMax = positiony - gridEndy * IShape.PPC;
final IPoint pos = ShapeFactory.INST.createPoint(positionx, gridEndy > 0 ? yMax : positiony);
final IRectangle r = ShapeFactory.INST.createRectangle(pos, Math.abs(pos.getX() - (gridEndx > 0 ? xMax : positionx)), Math.abs(pos.getY() - positiony));
r.setBordersPosition(BorderPos.MID);
r.setLineColour(shape.getLineColour());
r.setLineStyle(shape.getLineStyle());
r.setThickness(shape.getThickness());
final SVGElement frame = new SVGRectangle(r).toSVG(document);
frame.setAttribute(SVGAttributes.SVG_TRANSFORM, "translate(" + MathUtils.INST.format.format(-shape.getPosition().getX()) + ',' + MathUtils.INST.format.format(-shape.getPosition().getY()) + ')');
elt.appendChild(frame);
}
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class SVGBezierCurve method getPathSegList.
/**
* @return The SVG segment path list of the current Bézier curve.
* @since 2.0.0
*/
protected SVGPathSegList getPathSegList() {
if (shape.getNbPoints() < 2) {
return null;
}
final int size = shape.getNbPoints();
int i;
final SVGPathSegList path = new SVGPathSegList();
path.add(new SVGPathSegMoveto(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), false));
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(1).getX(), shape.getPtAt(1).getY(), shape.getFirstCtrlPtAt(0).getX(), shape.getFirstCtrlPtAt(0).getY(), shape.getFirstCtrlPtAt(1).getX(), shape.getFirstCtrlPtAt(1).getY(), false));
for (i = 2; i < size; i++) {
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(i).getX(), shape.getPtAt(i).getY(), shape.getSecondCtrlPtAt(i - 1).getX(), shape.getSecondCtrlPtAt(i - 1).getY(), shape.getFirstCtrlPtAt(i).getX(), shape.getFirstCtrlPtAt(i).getY(), false));
}
if (!shape.isOpened()) {
final IPoint ctrl1b = shape.getFirstCtrlPtAt(0).centralSymmetry(shape.getPtAt(0));
final IPoint ctrl2b = shape.getFirstCtrlPtAt(-1).centralSymmetry(shape.getPtAt(-1));
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), ctrl2b.getX(), ctrl2b.getY(), ctrl1b.getX(), ctrl1b.getY(), false));
path.add(new SVGPathSegClosePath());
}
return path;
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class SVGPolygon method toSVG.
@Override
public SVGElement toSVG(final SVGDocument doc) {
if (doc == null) {
throw new IllegalArgumentException();
}
final SVGElement root = new SVGGElement(doc);
final StringBuilder pointsBuilder = new StringBuilder();
root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_POLYGON);
root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
for (final IPoint pt : shape.getPoints()) {
pointsBuilder.append(pt.getX()).append(',').append(pt.getY()).append(' ');
}
final String points = pointsBuilder.toString();
if (shape.hasShadow()) {
final SVGPolygonElement shad = new SVGPolygonElement(doc);
try {
shad.setPoints(points);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
setSVGShadowAttributes(shad, true);
root.appendChild(shad);
}
if (shape.hasShadow() && !shape.getLineStyle().getLatexToken().equals(PSTricksConstants.LINE_NONE_STYLE)) {
// The background of the borders must be filled is there is a shadow.
final SVGPolygonElement elt = new SVGPolygonElement(doc);
try {
elt.setPoints(points);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
setSVGBorderBackground(elt, root);
}
final SVGPolygonElement elt = new SVGPolygonElement(doc);
try {
elt.setPoints(points);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
root.appendChild(elt);
setSVGAttributes(doc, elt, true);
elt.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_ROTATION, String.valueOf(shape.getRotationAngle()));
if (shape.hasDbleBord()) {
final SVGPolygonElement dblBord = new SVGPolygonElement(doc);
try {
dblBord.setPoints(points);
} catch (final ParseException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
setSVGDoubleBordersAttributes(dblBord);
root.appendChild(dblBord);
}
return root;
}
Aggregations