use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method getIntersectLineSegmentPath.
public static Point2DArray getIntersectLineSegmentPath(final Point2D l0, final Point2D l1, final PathPartList path) {
// the line is on the root container, it's points must be translated to be within the group of the path
final Point2DArray line = new Point2DArray(l0, l1);
@SuppressWarnings("unchecked") final Set<Point2D>[] // this is a line, there won't be more than one
intersections = new Set[line.size()];
getCardinalIntersects(path, line, intersections, false);
Point2DArray intersectPoints = null;
if ((intersections[1] != null) && !intersections[1].isEmpty()) {
intersectPoints = new Point2DArray();
for (final Point2D p : intersections[1]) {
intersectPoints.push(p);
}
}
return intersectPoints;
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Geometry method intersectLineCircle.
/**
* @param a0 start of the line
* @param a1 end of the line
* @param pc centore of the circle
* @param r radius of the circle
* @return
*/
public static final Point2DArray intersectLineCircle(final Point2D a0, final Point2D a1, final Point2D pc, final double r) {
// http://stackoverflow.com/a/29067085
// http://mathworld.wolfram.com/Circle-LineIntersection.html
final Point2D p1 = a0.sub(pc);
final Point2D p2 = a1.sub(pc);
final Point2D d = p2.sub(p1);
final double det = p1.crossScalar(p2);
final double dSq = d.dot(d);
final double discrimant = (r * r * dSq) - (det * det);
if (discrimant < 0) {
// line does not intersect
return new Point2DArray();
}
if (discrimant == 0) {
// line only intersects once, so the start or end is inside of the circle
return new Point2DArray(((det * d.getY()) / dSq) + pc.getX(), ((-det * d.getX()) / dSq) + pc.getY());
}
final double discSqrt = Math.sqrt(discrimant);
double sgn = 1;
if (d.getY() < 0) {
sgn = -1;
}
final Point2DArray intr = new Point2DArray((((det * d.getY()) + (sgn * d.getX() * discSqrt)) / dSq) + pc.getX(), (((-det * d.getX()) + (Math.abs(d.getY()) * discSqrt)) / dSq) + pc.getY());
return intr.push((((det * d.getY()) - (sgn * d.getX() * discSqrt)) / dSq) + pc.getX(), (((-det * d.getX()) - (Math.abs(d.getY()) * discSqrt)) / dSq) + pc.getY());
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Spline method getPathPoints.
private static final PathPoint[] getPathPoints(final Point2DArray array) {
if ((null == array) || (array.size() < 2)) {
return new PathPoint[0];
}
final Point2DArray unique = array.noAdjacentPoints();
final int size = unique.size();
if (size < 2) {
return new PathPoint[0];
}
final PathPoint[] points = new PathPoint[size];
for (int i = 0; i < size; i++) {
final Point2D point = unique.get(i);
points[i] = new PathPoint(point.getX(), point.getY());
}
return points;
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class Star method parse.
private boolean parse(final Attributes attr) {
final int sp = attr.getStarPoints();
final double ir = attr.getInnerRadius();
final double or = attr.getOuterRadius();
if ((sp > 4) && (ir > 0) && (or > 0) && (or > ir)) {
m_list.M(0, 0 - or);
final int s2 = sp * 2;
final double corner = getCornerRadius();
if (corner <= 0) {
for (int n = 1; n < s2; n++) {
final double stheta = ((n * Math.PI) / sp);
final double radius = (((n % 2) == 0) ? or : ir);
m_list.L(radius * Math.sin(stheta), -1 * radius * Math.cos(stheta));
}
m_list.Z();
} else {
final Point2DArray list = new Point2DArray(0, 0 - or);
for (int n = 1; n < s2; n++) {
final double stheta = ((n * Math.PI) / sp);
final double radius = (((n % 2) == 0) ? or : ir);
list.push(radius * Math.sin(stheta), -1 * radius * Math.cos(stheta));
}
Geometry.drawArcJoinedLines(m_list, list.push(0, 0 - or), corner);
}
return true;
}
return false;
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class OrthogonalPolyLine method correctBreakDistance.
public static final Point2DArray correctBreakDistance(final Point2DArray points, final double breakDistance) {
final Point2DArray cPoints = points.copy();
Point2D p1, p2;
final int size = cPoints.size();
for (int i = 0; i < (size - 1); i++) {
p1 = cPoints.get(i);
p2 = cPoints.get(i + 1);
if (Geometry.closeEnough(p1.getX(), p2.getX(), breakDistance)) {
p2.setX(p1.getX());
}
if (Geometry.closeEnough(p1.getY(), p2.getY(), breakDistance)) {
p2.setY(p1.getY());
}
}
return cPoints;
}
Aggregations