Skip to content

Commit

Permalink
sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Park authored and Mike Park committed Mar 22, 2022
1 parent 3ba1f5d commit 428dc98
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
22 changes: 19 additions & 3 deletions src/ref_geom.c
Original file line number Diff line number Diff line change
Expand Up @@ -4172,6 +4172,18 @@ REF_STATUS ref_geom_enrich3(REF_GRID ref_grid) {
return REF_SUCCESS;
}

static REF_STATUS ref_geom_bspline_span_check(REF_INT degree,
REF_INT n_control_point,
REF_DBL *knots, REF_DBL t,
REF_INT span) {
if (span >= degree) printf("span %d less than degree %d\n", span, degree);
if (n_control_point + degree - 1 < span)
printf("end %d equal larger than span %d\n", n_control_point + degree - 1,
span);
printf("%f < %f < %f\n", knots[span], t, knots[span + 1]);
return REF_SUCCESS;
}

/* number of knots is n_control_point + degree + 1 */
/* piegl-tiller m + 1 is number of knots, knots={t_0,...,t_m} */
/* n = m - degree - 1, m = n + degree + 1 */
Expand All @@ -4184,12 +4196,14 @@ REF_STATUS ref_geom_bspline_span_index(REF_INT degree, REF_INT n_control_point,
REF_INT *span) {
REF_INT low, high, mid;
*span = REF_EMPTY;
if (t >= knots[n_control_point]) {
*span = n_control_point - 1;
if (t >= knots[n_control_point + degree - 2]) {
*span = n_control_point + degree - 2;
RSS(ref_geom_bspline_span_check(degree, n_control_point, knots, t, *span),
"check");
return REF_SUCCESS;
}
low = degree;
high = n_control_point;
high = n_control_point + degree - 2;
mid = (low + high) / 2;
while ((t < knots[mid] || t >= knots[mid + 1]) && (low != high)) {
/* printf("t %f l %d m %d h %d\n",t,low,mid,high); */
Expand All @@ -4201,5 +4215,7 @@ REF_STATUS ref_geom_bspline_span_index(REF_INT degree, REF_INT n_control_point,
mid = (low + high) / 2;
}
*span = mid;
RSS(ref_geom_bspline_span_check(degree, n_control_point, knots, t, *span),
"check");
return REF_SUCCESS;
}
44 changes: 36 additions & 8 deletions src/ref_geom_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,24 +1199,52 @@ int main(int argc, char *argv[]) {
t = 0;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(1, span, "wrong span");
REIS(2, span, "wrong span");
t = 0.5;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(1, span, "wrong span");
REIS(2, span, "wrong span");
t = 1.0;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(1, span, "wrong span");
REIS(2, span, "wrong span");
t = 2.0;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(1, span, "wrong span");
REIS(2, span, "wrong span");
}

{
REF_INT degree = 3;
REF_INT n_control_points = 2;
REF_DBL knots[] = {0, 0, 0, 0, 1, 1, 1, 1};
REF_DBL t;
REF_INT span;
t = -1;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(3, span, "wrong span");
t = 0;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(3, span, "wrong span");
t = 0.5;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(3, span, "wrong span");
t = 1.0;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(3, span, "wrong span");
t = 2.0;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(3, span, "wrong span");
}

{
REF_INT degree = 2;
REF_INT n_control_points = 5;
REF_INT n_control_points = 7;
REF_DBL knots[] = {0, 0, 0, 1, 2, 3, 4, 4, 5, 5, 5};
REF_DBL t;
REF_INT span;
Expand All @@ -1243,15 +1271,15 @@ int main(int argc, char *argv[]) {
t = 4.0;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(4, span, "wrong span");
REIS(7, span, "wrong span");
t = 5;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(4, span, "wrong span");
REIS(7, span, "wrong span");
t = 6;
RSS(ref_geom_bspline_span_index(degree, n_control_points, knots, t, &span),
"index");
REIS(4, span, "wrong span");
REIS(7, span, "wrong span");
}

RSS(ref_mpi_free(ref_mpi), "free");
Expand Down

0 comments on commit 428dc98

Please sign in to comment.