use of com.ait.lienzo.client.core.types.PathPartEntryJSO in project lienzo-core by ahome-it.
the class Geometry method drawArcJoinedLines.
public static final void drawArcJoinedLines(final PathPartList list, final PathPartList baseList, final Point2DArray basePoints, final double radius) {
final int pointsSize = basePoints.size();
final boolean closed = isClosed(baseList);
for (int i = 0; i < pointsSize; i++) {
final PathPartEntryJSO entry = baseList.get(i);
final PathPartEntryJSO nextEntry = baseList.get(i + 1);
Point2D p0 = basePoints.get(i - 1);
final Point2D p2 = basePoints.get(i);
Point2D p4 = basePoints.get(i + 1);
if (closed) {
if (i == 0) {
p0 = basePoints.get(pointsSize - 1);
}
if (i == (pointsSize - 1)) {
p4 = basePoints.get(0);
}
} else {
if ((i == 0) || (i == (pointsSize - 1))) {
p0 = null;
p4 = null;
}
}
boolean applyArcToList = false;
if (isCorner(entry, nextEntry)) {
if ((p0 != null) && (p4 != null)) {
if (!Geometry.collinear(p0, p2, p4)) {
applyArcToList = true;
}
}
}
if (applyArcToList) {
drawLines(list, p0, p2, p4, radius);
} else {
list.push(entry.copy());
}
}
if (closed) {
list.Z();
}
}
use of com.ait.lienzo.client.core.types.PathPartEntryJSO in project lienzo-core by ahome-it.
the class Geometry method getCardinalIntersects.
public static void getCardinalIntersects(final PathPartList path, final Point2DArray cardinals, final Set<Point2D>[] intersections, final boolean addCenter) {
final Point2D center = cardinals.get(0);
Point2D pathStart = new Point2D(0, 0);
Point2D segmentStart = pathStart;
int i = PathPartList.skipRedundantLeadingMoveTo(path);
// A set is used as vertex's may intersect, so the start/end of two liens will intersect
for (; i < path.size(); i++) {
final PathPartEntryJSO entry = path.get(i);
NFastDoubleArrayJSO points = entry.getPoints();
switch(entry.getCommand()) {
case PathPartEntryJSO.MOVETO_ABSOLUTE:
{
points = entry.getPoints();
final Point2D m = new Point2D(points.get(0), points.get(1));
if (i == 0) {
// This position is needed, if we close the path.
pathStart = m;
}
segmentStart = m;
break;
}
case PathPartEntryJSO.LINETO_ABSOLUTE:
{
points = entry.getPoints();
final double x0 = points.get(0);
final double y0 = points.get(1);
final Point2D end = new Point2D(x0, y0);
for (int j = 1; j < cardinals.size(); j++) {
final Point2D cardinal = cardinals.get(j);
final Point2D intersectPoint = Geometry.intersectLineLine(center, cardinal, segmentStart, end);
if (intersectPoint != null) {
addIntersect(intersections, j, intersectPoint);
}
}
segmentStart = end;
break;
}
case PathPartEntryJSO.CLOSE_PATH_PART:
{
final double x0 = pathStart.getX();
final double y0 = pathStart.getY();
final Point2D end = new Point2D(x0, y0);
for (int j = 1; j < cardinals.size(); j++) {
final Point2D cardinal = cardinals.get(j);
final Point2D intersectPoint = Geometry.intersectLineLine(center, cardinal, segmentStart, end);
if (intersectPoint != null) {
addIntersect(intersections, j, intersectPoint);
}
}
segmentStart = end;
break;
}
case PathPartEntryJSO.CANVAS_ARCTO_ABSOLUTE:
{
points = entry.getPoints();
final double x0 = points.get(0);
final double y0 = points.get(1);
final Point2D p0 = new Point2D(x0, y0);
final double x1 = points.get(2);
final double y1 = points.get(3);
final Point2D p1 = new Point2D(x1, y1);
final Point2D end = p1;
final double r = points.get(4);
for (int j = 1; j < cardinals.size(); j++) {
final Point2D cardinal = cardinals.get(j);
final Point2DArray intersectPoints = Geometry.intersectLineArcTo(center, cardinal, segmentStart, p0, p1, r);
if (intersectPoints.size() > 0) {
for (final Point2D p : intersectPoints) {
addIntersect(intersections, j, p);
}
}
}
segmentStart = end;
}
break;
}
}
if (addCenter) {
addIntersect(intersections, 0, center);
}
}
use of com.ait.lienzo.client.core.types.PathPartEntryJSO in project lienzo-core by ahome-it.
the class Geometry method isClosed.
private static final boolean isClosed(final PathPartList list) {
final int listSize = list.size();
if (listSize <= 2) {
return false;
}
final PathPartEntryJSO part = list.get(listSize - 1);
if (part.getCommand() == PathPartEntryJSO.CLOSE_PATH_PART) {
return true;
} else {
return false;
}
}
use of com.ait.lienzo.client.core.types.PathPartEntryJSO in project lienzo-core by ahome-it.
the class WiresConnectorControlImpl method getIndexForSelectedSegment.
public static int getIndexForSelectedSegment(final WiresConnector connector, final int mouseX, final int mouseY, final Point2DArray oldPoints) {
final NFastStringMap<Integer> colorMap = new NFastStringMap<>();
final AbstractDirectionalMultiPointShape<?> line = connector.getLine();
final ScratchPad scratch = line.getScratchPad();
scratch.clear();
final PathPartList path = line.getPathPartList();
int pointsIndex = 1;
String color = MagnetManager.m_c_rotor.next();
colorMap.put(color, pointsIndex);
final Context2D ctx = scratch.getContext();
final double strokeWidth = line.getStrokeWidth();
ctx.setStrokeWidth(strokeWidth);
final Point2D absolutePos = connector.getLine().getComputedLocation();
final double offsetX = absolutePos.getX();
final double offsetY = absolutePos.getY();
Point2D pathStart = new Point2D(offsetX, offsetY);
Point2D segmentStart = pathStart;
for (int i = 0; i < path.size(); i++) {
final PathPartEntryJSO entry = path.get(i);
NFastDoubleArrayJSO points = entry.getPoints();
switch(entry.getCommand()) {
case PathPartEntryJSO.MOVETO_ABSOLUTE:
{
final double x0 = points.get(0) + offsetX;
final double y0 = points.get(1) + offsetY;
final Point2D m = new Point2D(x0, y0);
if (i == 0) {
// this is position is needed, if we close the path.
pathStart = m;
}
segmentStart = m;
break;
}
case PathPartEntryJSO.LINETO_ABSOLUTE:
{
points = entry.getPoints();
final double x0 = points.get(0) + offsetX;
final double y0 = points.get(1) + offsetY;
final Point2D end = new Point2D(x0, y0);
if (oldPoints.get(pointsIndex).equals(segmentStart)) {
pointsIndex++;
color = MagnetManager.m_c_rotor.next();
colorMap.put(color, pointsIndex);
}
ctx.setStrokeColor(color);
ctx.beginPath();
ctx.moveTo(segmentStart.getX(), segmentStart.getY());
ctx.lineTo(x0, y0);
ctx.stroke();
segmentStart = end;
break;
}
case PathPartEntryJSO.CLOSE_PATH_PART:
{
final double x0 = pathStart.getX() + offsetX;
final double y0 = pathStart.getY() + offsetY;
final Point2D end = new Point2D(x0, y0);
if (oldPoints.get(pointsIndex).equals(segmentStart)) {
pointsIndex++;
color = MagnetManager.m_c_rotor.next();
colorMap.put(color, pointsIndex);
}
ctx.setStrokeColor(color);
ctx.beginPath();
ctx.moveTo(segmentStart.getX(), segmentStart.getY());
ctx.lineTo(x0, y0);
ctx.stroke();
segmentStart = end;
break;
}
case PathPartEntryJSO.CANVAS_ARCTO_ABSOLUTE:
{
points = entry.getPoints();
final double x0 = points.get(0) + offsetX;
final double y0 = points.get(1) + offsetY;
final Point2D p0 = new Point2D(x0, y0);
final double x1 = points.get(2) + offsetX;
final double y1 = points.get(3) + offsetY;
final double r = points.get(4);
final Point2D p1 = new Point2D(x1, y1);
final Point2D end = p1;
if (p0.equals(oldPoints.get(pointsIndex))) {
pointsIndex++;
color = MagnetManager.m_c_rotor.next();
colorMap.put(color, pointsIndex);
}
ctx.setStrokeColor(color);
ctx.beginPath();
ctx.moveTo(segmentStart.getX(), segmentStart.getY());
ctx.arcTo(x0, y0, x1, y1, r);
ctx.stroke();
segmentStart = end;
break;
}
}
}
final BoundingBox box = connector.getLine().getBoundingBox();
// Keep the ImageData small by clipping just the visible line area
// But remember the mouse must be offset for this clipped area.
final int sx = (int) (box.getX() - strokeWidth - offsetX);
final int sy = (int) (box.getY() - strokeWidth - offsetY);
final ImageData backing = ctx.getImageData(sx, sy, (int) (box.getWidth() + strokeWidth + strokeWidth), (int) (box.getHeight() + strokeWidth + strokeWidth));
color = BackingColorMapUtils.findColorAtPoint(backing, mouseX - sx, mouseY - sy);
return null != color ? colorMap.get(color) : -1;
}
use of com.ait.lienzo.client.core.types.PathPartEntryJSO in project lienzo-core by ahome-it.
the class BackingColorMapUtils method drawShapeToBacking.
public static void drawShapeToBacking(final Context2D ctx, final MultiPath multiPath, final String color, final double strokeWidth, final boolean fill) {
final NFastArrayList<PathPartList> listOfPaths = multiPath.getActualPathPartListArray();
for (int k = 0; k < listOfPaths.size(); k++) {
final PathPartList path = listOfPaths.get(k);
ctx.setStrokeWidth(strokeWidth);
ctx.setStrokeColor(color);
ctx.setFillColor(color);
ctx.beginPath();
final Point2D absLoc = multiPath.getComputedLocation();
final double offsetX = absLoc.getX();
final double offsetY = absLoc.getY();
ctx.moveTo(offsetX, offsetY);
boolean closed = false;
for (int i = 0; i < path.size(); i++) {
final PathPartEntryJSO entry = path.get(i);
NFastDoubleArrayJSO points = entry.getPoints();
switch(entry.getCommand()) {
case PathPartEntryJSO.MOVETO_ABSOLUTE:
{
ctx.moveTo(points.get(0) + offsetX, points.get(1) + offsetY);
break;
}
case PathPartEntryJSO.LINETO_ABSOLUTE:
{
points = entry.getPoints();
final double x0 = points.get(0) + offsetX;
final double y0 = points.get(1) + offsetY;
ctx.lineTo(x0, y0);
break;
}
case PathPartEntryJSO.CLOSE_PATH_PART:
{
ctx.closePath();
closed = true;
break;
}
case PathPartEntryJSO.CANVAS_ARCTO_ABSOLUTE:
{
points = entry.getPoints();
final double x0 = points.get(0) + offsetX;
final double y0 = points.get(1) + offsetY;
final double x1 = points.get(2) + offsetX;
final double y1 = points.get(3) + offsetY;
final double r = points.get(4);
ctx.arcTo(x0, y0, x1, y1, r);
}
break;
}
}
if (!closed) {
ctx.closePath();
}
if (fill) {
ctx.fill();
}
ctx.stroke();
}
}
Aggregations