- // TODO : actually make connection if its detected
- boolean connectPrev = false;
- boolean connectNext = false;
-
- if (mu[0] < 0.0) {
- currentPosition.set(sStart);
- connectPrev = true;
- }
- else if (mu[0] > 1.0) {
- currentPosition.set(sEnd);
- connectNext = true;
- }
- boolean connect = false;
- if (connectPrev) {
- PipeControlPoint pcp = s.getControlPoint();
- if (pcp.getPrevious() == null)
- connect = true;
- } else if (connectNext) {
- PipeControlPoint pcp = s.getControlPoint();
- if (pcp.getNext() == null)
- connect = true;
- }
-
- updateCurrentPoint();
-
- if (connect)
- info += "Connect pipes :";
- else
- info += "Make Branch :";
-
- setInfoText(info + currentPosition + " " + Math.max(0.0, Math.min(mu[0], 1.0)));
- if (connect) {
- if (connectNext) {
- return PositionType.NEXT;
- } else {
- return PositionType.PREVIOUS;
- }
-
- }
- return PositionType.SPLIT;
-
+ return endingToStraight(mu, s, sStart, sEnd, currentPipePoint);
+ }
+
+ private PositionType endingToStraight(double mu[], InlineComponent s, Point3d sStart, Point3d sEnd , Point3d currentPipePoint) {
+ String info = "";
+
+ boolean connectPrev = false;
+ boolean connectNext = false;
+ boolean branch = false;
+ if (mu[0] < 0.1) {
+ connectPrev = true;
+ }
+ else if (mu[0] > 0.9) {
+ connectNext = true;
+ }
+
+
+ if (connectPrev) {
+ PipeControlPoint pcp = s.getControlPoint();
+ if (pcp.getPrevious() != null)
+ connectPrev = false;
+ } else if (connectNext) {
+ PipeControlPoint pcp = s.getControlPoint();
+ if (pcp.getNext() != null)
+ connectNext = false;
+ } else {
+ Vector3d dir = s.getControlPoint().getPathLegDirection(Direction.NEXT);
+ Vector3d currDir = getLast().getControlPoint().getPathLegDirection(Direction.NEXT);
+ dir.normalize();
+ currDir.normalize();
+ double dot = dir.dot(currDir);
+ System.out.println(dot + " " + currDir + " " + dir);
+ if (dot > BRANCH_DOT_PRODUCT || dot < -BRANCH_DOT_PRODUCT) {
+ // pipes are almost in the same direction, creating a branch is not feasible.
+ branch = false;
+ } else {
+ branch = true;
+ }
+ }
+
+
+ if (connectNext || connectPrev)
+ info += "Connect pipes :";
+ else if (branch)
+ info += "Create a Branch :";
+
+ setInfoText(info + currentPosition + " " + Math.max(0.0, Math.min(mu[0], 1.0)));
+ if (connectNext) {
+ currentPosition.set(sEnd);
+ updateCurrentPoint();
+ return PositionType.NEXT;
+ } else if (connectPrev){
+ currentPosition.set(sStart);
+ updateCurrentPoint();
+ return PositionType.PREVIOUS;
+ } else if (branch && allowBranches) {
+ return PositionType.SPLIT;
+ } else {
+ currentPosition.set(currentPipePoint);
+ updateCurrentPoint();
+ return null;
+ }