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