Skip to content

Commit

Permalink
Removing dimension from get_curvature in ABI.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Apr 19, 2018
1 parent b877641 commit 1e39c0c
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 105 deletions.
16 changes: 9 additions & 7 deletions docs/abi/curve.rst
Expand Up @@ -266,7 +266,6 @@ Procedures
bool *not_implemented);
.. c:function:: void get_curvature(int *num_nodes, \
int *dimension, \
double *nodes, \
double *tangent_vec, \
double *s, \
Expand All @@ -275,18 +274,21 @@ Procedures
Get the curvature of a B |eacute| zier curve at a point. See
:func:`._get_curvature` for more details.
.. note::
This **only** computes curvature for plane curves (i.e. curves
in :math:`\mathbf{R}^2`). An equivalent notion of curvature exists for
space curves, but support for that is not implemented here.
:param int* num_nodes:
**[Input]** The number of control points :math:`N` of a
B |eacute| zier curve.
:param int* dimension:
**[Input]** The dimension :math:`D` such that the curve lies in
:math:`\mathbf{R}^D`.
:param double* nodes:
**[Input]** The actual control points of the curve as a
:math:`D \times N` array. This should be laid out in Fortran order,
with :math:`D N` total values.
:math:`2 \times N` array. This should be laid out in Fortran order,
with :math:`2 N` total values.
:param double* tangent_vec:
**[Input]** The hodograph :math:`B'(s)` as a :math:`D \times 1` array.
**[Input]** The hodograph :math:`B'(s)` as a :math:`2 \times 1` array.
Note that this could be computed once :math:`s` and :math:`B` are known,
but this allows the caller to re-use an already computed tangent vector.
:param double* s:
Expand Down
2 changes: 1 addition & 1 deletion src/bezier/_curve.pxd
Expand Up @@ -41,7 +41,7 @@ cdef extern from "bezier/curve.h":
void elevate_nodes_curve(
int *num_nodes, int *dimension, double *nodes, double *elevated)
void get_curvature(
int *num_nodes, int *dimension, double *nodes, double *tangent_vec,
int *num_nodes, double *nodes, double *tangent_vec,
double *s, double *curvature)
void reduce_pseudo_inverse(
int *num_nodes, int *dimension, double *nodes, double *reduced,
Expand Down
159 changes: 79 additions & 80 deletions src/bezier/_speedup.c

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/bezier/_speedup.pyx
Expand Up @@ -278,15 +278,15 @@ def elevate_nodes(double[::1, :] nodes):


def get_curvature(double[::1, :] nodes, double[::1, :] tangent_vec, double s):
cdef int num_nodes, dimension
cdef int num_nodes
cdef double curvature

dimension, num_nodes = np.shape(nodes)
# NOTE: We don't check that ``np.shape(tangent_vec) == (dimension, 1)``.
# NOTE: We don't check that there are 2 rows.
_, num_nodes = np.shape(nodes)
# NOTE: We don't check that ``np.shape(tangent_vec) == (2, 1)``.

bezier._curve.get_curvature(
&num_nodes,
&dimension,
&nodes[0, 0],
&tangent_vec[0, 0],
&s,
Expand Down
18 changes: 11 additions & 7 deletions src/bezier/curve.f90
Expand Up @@ -570,17 +570,21 @@ subroutine elevate_nodes( &
end subroutine elevate_nodes

subroutine get_curvature( &
num_nodes, dimension_, nodes, tangent_vec, s, curvature) &
num_nodes, nodes, tangent_vec, s, curvature) &
bind(c, name='get_curvature')

integer(c_int), intent(in) :: num_nodes, dimension_
real(c_double), intent(in) :: nodes(dimension_, num_nodes)
real(c_double), intent(in) :: tangent_vec(dimension_, 1)
! NOTE: This **only** computes curvature for plane curves (i.e. curves
! in R^2). An equivalent notion of curvature exists for space
! curves, but support for that is not implemented here.

integer(c_int), intent(in) :: num_nodes
real(c_double), intent(in) :: nodes(2, num_nodes)
real(c_double), intent(in) :: tangent_vec(2, 1)
real(c_double), intent(in) :: s
real(c_double), intent(out) :: curvature
! Variables outside of signature.
real(c_double) :: work(dimension_, num_nodes - 1)
real(c_double) :: concavity(dimension_, 1)
real(c_double) :: work(2, num_nodes - 1)
real(c_double) :: concavity(2, 1)

if (num_nodes == 2) then
curvature = 0
Expand All @@ -596,7 +600,7 @@ subroutine get_curvature( &

! NOTE: The degree being evaluated is ``degree - 2 == num_nodes - 3``.
call evaluate_multi( &
num_nodes - 2, dimension_, work(:, :num_nodes - 2), 1, [s], concavity)
num_nodes - 2, 2, work(:, :num_nodes - 2), 1, [s], concavity)
! B''(s) = d (d - 1) D(s) where D(s) is defined by the "double hodograph".
concavity = concavity * (num_nodes - 1) * (num_nodes - 2)

Expand Down
2 changes: 1 addition & 1 deletion src/bezier/include/bezier/curve.h
Expand Up @@ -43,7 +43,7 @@ void locate_point_curve(
void elevate_nodes_curve(
int *num_nodes, int *dimension, double *nodes, double *elevated);
void get_curvature(
int *num_nodes, int *dimension, double *nodes, double *tangent_vec,
int *num_nodes, double *nodes, double *tangent_vec,
double *s, double *curvature);
void reduce_pseudo_inverse(
int *num_nodes, int *dimension, double *nodes, double *reduced,
Expand Down
4 changes: 2 additions & 2 deletions src/bezier/surface_intersection.f90
Expand Up @@ -582,12 +582,12 @@ subroutine classify_tangent_intersection( &
! parallel and we don't handle that case.
num_nodes = size(edges_first(intersection_%index_first)%nodes, 2)
call get_curvature( &
num_nodes, 2, edges_first(intersection_%index_first)%nodes, &
num_nodes, edges_first(intersection_%index_first)%nodes, &
tangent_s, intersection_%s, curvature1)

num_nodes = size(edges_second(intersection_%index_second)%nodes, 2)
call get_curvature( &
num_nodes, 2, edges_second(intersection_%index_second)%nodes, &
num_nodes, edges_second(intersection_%index_second)%nodes, &
tangent_t, intersection_%t, curvature2)

if (dot_prod < 0.0_dp) then
Expand Down
6 changes: 3 additions & 3 deletions tests/fortran/test_curve.f90
Expand Up @@ -574,7 +574,7 @@ subroutine test_get_curvature(success)
call evaluate_hodograph( &
s_val, 2, 2, nodes1, tangent_vec)
call get_curvature( &
2, 2, nodes1, tangent_vec, s_val, curvature)
2, nodes1, tangent_vec, s_val, curvature)
case_success = (curvature == 0.0_dp)
call print_status(name, case_id, case_success, success)

Expand All @@ -586,7 +586,7 @@ subroutine test_get_curvature(success)
call evaluate_hodograph( &
s_val, 3, 2, nodes2, tangent_vec)
call get_curvature( &
3, 2, nodes2, tangent_vec, s_val, curvature)
3, nodes2, tangent_vec, s_val, curvature)
case_success = (curvature == 0.0_dp)
call print_status(name, case_id, case_success, success)

Expand All @@ -598,7 +598,7 @@ subroutine test_get_curvature(success)
call evaluate_hodograph( &
s_val, 3, 2, nodes2, tangent_vec)
call get_curvature( &
3, 2, nodes2, tangent_vec, s_val, curvature)
3, nodes2, tangent_vec, s_val, curvature)
case_success = (curvature == -4.0_dp)
call print_status(name, case_id, case_success, success)

Expand Down

0 comments on commit 1e39c0c

Please sign in to comment.