- //GeomAPI_PointsToBSpline GBC (CurvePoints);
- //aShape = BRepBuilderAPI_MakeEdge(GBC).Edge();
-
- if (aCI.GetDoReordering()) {
- for (int curInd = 1; curInd < aLen - 1; curInd++) {
- gp_Pnt curPnt = CurvePoints.Value(curInd);
- int nearInd = 0;
- double nearDist = RealLast();
- for (ind = curInd + 1; ind <= aLen; ind++) {
- double dist = curPnt.SquareDistance(CurvePoints.Value(ind));
- if (dist < nearDist && (nearDist - dist) > Precision::Confusion()) {
- nearInd = ind;
- nearDist = dist;
- }
- }
- if (nearInd > 0 && nearInd != curInd + 1) {
- // Keep given order of points to use it in case of equidistant candidates
- // .-<---<-.
- // / \
- // o o o c o->o->o->o->n o o
- // | | |
- // curInd curInd+1 nearInd
- gp_Pnt nearPnt = CurvePoints.Value(nearInd);
- for (ind = nearInd; ind > curInd + 1; ind--) {
- CurvePoints.SetValue(ind, CurvePoints.Value(ind - 1));
- }
- CurvePoints.SetValue(curInd + 1, nearPnt);
- }
- }
- }
-
- Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
- for (ind = 1; ind <= aLen; ind++) {
- aHCurvePoints->SetValue(ind, CurvePoints.Value(ind));
+ // Below described processing of closed points set case
+ // is not done for constrained bsplined
+ bool typeok = aType == SPLINE_INTERPOLATION;
+#if BSPLINE_PROCESS_CLOSED_PNTSET == 1
+ // Last point is removed from the list if:
+ // a) first and last vertices are equal;
+ // b) "closed" flag is not taken into account.
+ // If first and last points are equal, we force "closed" flag to be set to true.
+ // For the case when first and last vertices are equal, this approach causes
+ // result different that would be if last point had NOT be removed and "closed" flag is false.
+ bool isClosed = typeok && (aCI.GetIsClosed() || closed);
+ bool removeLast = typeok && closed;
+ bool addFirst = false;
+#elif BSPLINE_PROCESS_CLOSED_PNTSET == 2
+ // Last point is removed from the list if:
+ // a) first and last vertices are equal;
+ // b) "closed" flag is set to true.
+ // Flag "closed" is taken "as is".
+ // For the case when first and last vertices are equal, this approach causes
+ // different results with "closed" flag set to true and false.
+ bool isClosed = typeok && aCI.GetIsClosed();
+ bool removeLast = typeok && aCI.GetIsClosed() && closed;
+ bool addFirst = false;
+#elif BSPLINE_PROCESS_CLOSED_PNTSET == 3
+ // Points are passed "as is" to the creator.
+ // If first and last points are equal, we force "closed" flag to be set to false.
+ // For the case when first and last vertices are equal, this approach gives
+ // the same results with "closed" flag set to true and false.
+ bool isClosed = typeok && aCI.GetIsClosed() && !closed;
+ bool removeLast = false;
+ bool addFirst = false;
+#elif BSPLINE_PROCESS_CLOSED_PNTSET == 4
+ // First point is added to the list if:
+ // a) first and last vertices are not equal;
+ // b) "closed" flag is set to true.
+ // In this case "closed" flag is forcidly set to false - bspline creator is
+ // capable to create closed edge in this case.
+ // This approach gives the same results with "closed" flag set to true not
+ // depending on if set of points is closed or no.
+ // Also, it gives equal reqults in both case if set of points is closed or not
+ // and "closed" flag is set to true, in contrast to solution 3 above.
+ bool isClosed = false;
+ bool removeLast = false;
+ bool addFirst = typeok && aCI.GetIsClosed() && !closed;
+#else
+ // Points are passed "as is" to the creator.
+ // This causes an error when first point is equal to last one and
+ // "closed" flag is set to true; see bug 0022885.
+ bool isClosed = typeok && aCI.GetIsClosed();
+ bool removeLast = false;
+ bool addFirst = false;
+#endif
+
+ // remove last point or append first one if the conditions are observed (see above)
+ if (removeLast || addFirst) {
+ int extra = removeLast ? -1 : (addFirst ? 1 : 0 );
+ int nb = removeLast ? length-1 : length;
+ Handle(TColgp_HArray1OfPnt) curvePoints = new TColgp_HArray1OfPnt (1, length+extra);
+ for (int i = 1; i <= nb; i++)
+ curvePoints->SetValue(i, points->Value(i));
+ if (addFirst) curvePoints->SetValue(length+1, points->Value(1));
+ points = curvePoints;