use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class PSTRectView method getCode.
@Override
public String getCode(final IPoint position, final float ppc) {
if (!MathUtils.INST.isValidPt(position) || ppc < 1)
return "";
final StringBuilder params = getPropertiesCode(ppc);
final IPoint tl = shape.getTopLeftPoint();
final IPoint 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();
// $NON-NLS-1$
if (shape.isRoundCorner())
params.append(", framearc=").append(MathUtils.INST.getCutNumberFloat(shape.getLineArc()));
final StringBuilder rotation = getRotationHeaderCode(ppc, position);
if (rotation != null)
code.append(rotation);
// $NON-NLS-1$
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();
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class Pencil method bindDnDToDrawFreeHandShape.
/**
* Binds a DnD interaction to create shape.
*/
private void bindDnDToDrawFreeHandShape() {
nodeBinder(AddShape.class, new DnD(false, true)).on(canvas).map(i -> {
final IShape sh = createShapeInstance();
final IPoint pt = getAdaptedPoint(i.getSrcLocalPoint());
sh.getPoints().get(0).setPoint(pt.getX(), pt.getY());
return new AddShape(sh, canvas.getDrawing());
}).first((c, i) -> Platform.runLater(() -> canvas.requestFocus())).then((c, i) -> {
final IPoint last = c.getShape().get().getPtAt(-1);
final IPoint endPt = getAdaptedPoint(i.getEndLocalPt());
if (!MathUtils.INST.equalsDouble(last.getX(), endPt.getX(), 0.0001) && !MathUtils.INST.equalsDouble(last.getY(), endPt.getY(), 0.0001)) {
c.setShape(ShapeFactory.INST.createFreeHandFrom((IFreehand) c.getShape().get(), endPt));
}
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).endOrCancel((c, i) -> canvas.setTempView(null)).when(i -> i.getButton() == MouseButton.PRIMARY && currentChoice.get() == EditionChoice.FREE_HAND).strictStart().bind();
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class LAxes method getArrowLineY.
/**
* @return The line of the Y-axis.
*/
private ILine getArrowLineY(final boolean topY) {
final IPoint pos = getPosition();
final IPoint p2 = ShapeFactory.INST.createPoint(pos.getX(), pos.getY() - getGridEndY() * IShape.PPC);
final IPoint p1 = ShapeFactory.INST.createPoint(pos.getX(), pos.getY() - getGridStartY() * IShape.PPC);
if (topY) {
return ShapeFactory.INST.createLine(p2, p1);
}
return ShapeFactory.INST.createLine(p1, p2);
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class LAxes method getArrowLineX.
/**
* @return The line of the X-axis.
*/
private ILine getArrowLineX(final boolean leftX) {
final IPoint pos = getPosition();
final IPoint p2 = ShapeFactory.INST.createPoint(pos.getX() + getGridEndX() * IShape.PPC, pos.getY());
final IPoint p1 = ShapeFactory.INST.createPoint(pos.getX() + getGridStartX() * IShape.PPC, pos.getY());
if (leftX) {
return ShapeFactory.INST.createLine(p1, p2);
}
return ShapeFactory.INST.createLine(p2, p1);
}
use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.
the class LCircleArc method getArrowLine.
@Override
public ILine getArrowLine(final int index) {
final IArrow arrow = getArrowAt(index);
if (arrow == null) {
return null;
}
// Computing the angle to use for the second point of the line:
// the length of the arrow and the radius are used to compute the angle that separates the two points of the line.
final double gap = Math.asin(Math.max(-1d, Math.min(1d, arrow.getArrowShapeLength() / getRadius())));
if (index == 0) {
final IPoint sp = getStartPoint();
final IPoint ep = getPointOnArc(getAngleStart() < getAngleEnd() ? getAngleStart() + gap : getAngleStart() - gap);
return ShapeFactory.INST.createLine(sp, ep);
}
// For sure index == 1 here.
final IPoint sp = getEndPoint();
final IPoint ep = getPointOnArc(getAngleEnd() < getAngleStart() ? getAngleEnd() + gap : getAngleEnd() - gap);
return ShapeFactory.INST.createLine(sp, ep);
}
Aggregations