Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding idiomatic C++ equivalents for each subroutine in helpers.h. #227

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c4c0a86
Adding idiomatic C++ equivalents for each subroutine in `helpers.h`.
dhermes May 27, 2020
ffb285d
Adding TODO comments and implementations for two more ABI routines.
dhermes May 27, 2020
0ebaa7c
Formatting: line-wrapping and clang-format.
dhermes May 27, 2020
b847b32
Moving C++ interface into `.hpp` files.
dhermes May 30, 2020
d97d66b
Adding TODO for xarray.
dhermes May 30, 2020
705a4fd
Introducing dependency on `xtensor`.
dhermes May 31, 2020
43f58e0
Adding implementation for `contains_nd`.
dhermes May 31, 2020
23ccdc7
Adding implementation for `vector_close`.
dhermes May 31, 2020
69e7a55
Adding implementation for `polygon_collide`.
dhermes May 31, 2020
e0891c8
Adding implementation for `simple_convex_hull`.
dhermes May 31, 2020
59b45c9
Updating `abi/installation` to refer to new `.hpp` files.
dhermes May 31, 2020
5ea4970
Adding `evaluate_curve_barycentric` to C++ library.
dhermes May 31, 2020
7871d3b
Adding C++ equivalent to `example_evaluate_curve_barycentric.c`.
dhermes May 31, 2020
0c9e9de
Adding `evaluate_multi` to C++ library.
dhermes May 31, 2020
1e06a92
Adding `curve.hpp` to `abi/installation.rst`.
dhermes May 31, 2020
d165484
Adding `specialize_curve` to C++ library.
dhermes May 31, 2020
7969250
Adding `evaluate_hodograph` to C++ library.
dhermes May 31, 2020
78f05ee
Adding `subdivide_nodes_curve` to C++ library.
dhermes May 31, 2020
64de0ed
Adding `newton_refine_curve` to C++ library.
dhermes May 31, 2020
6543b75
Adding `locate_point_curve` to C++ library.
dhermes May 31, 2020
fe6acb1
Adding `elevate_nodes_curve` to C++ library.
dhermes May 31, 2020
0ac88ad
Adding `get_curvature` to C++ library.
dhermes May 31, 2020
fa30a6b
Replacing 1D `xtensor_fixed` with `std::array`.
dhermes May 31, 2020
c3dc9a8
Adding `reduce_pseudo_inverse` to C++ library.
dhermes May 31, 2020
b77ef1b
Adding `full_reduce` to C++ library.
dhermes May 31, 2020
8ed7b42
Adding `compute_length` to C++ library.
dhermes May 31, 2020
9f0d541
Introducing `Matrix` and `Vector` aliases in `bezier` namespace.
dhermes May 31, 2020
b4ea25a
Beginning process of documenting C++ API.
dhermes May 31, 2020
630bdee
Replacing all `size_t` with `std::size_t` in C++ contexts.
dhermes May 31, 2020
fdb0de7
Updating `docs/index.rst` templates for C++ docs.
dhermes May 31, 2020
269e907
Merge branch 'main' into issue-131
dhermes Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/abi/example_elevate_nodes_curve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"
#include "xtensor/xio.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 3> nodes {
{ 0.0, 1.5, 3.0 },
{ 0.0, 1.5, 0.0 },
};

// Outputs.
bezier::Matrix<2, 4> elevated = bezier::elevate_nodes_curve(nodes);

std::cout << "Elevated:" << std::endl;
std::cout << elevated << std::endl;

return 0;
}
37 changes: 37 additions & 0 deletions docs/abi/example_evaluate_curve_barycentric.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"
#include "xtensor/xio.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 3> nodes {
{ 0.0, 2.0, 3.0 },
{ 1.0, 1.0, 3.0 },
};
bezier::Vector<4> lambda1 { 0.25, 0.5, 0.0, 1.0 };
bezier::Vector<4> lambda2 { 0.75, 0.25, 0.5, 0.25 };

// Outputs.
bezier::Matrix<2, 4> evaluated
= bezier::evaluate_curve_barycentric(nodes, lambda1, lambda2);

std::cout << "Evaluated:" << std::endl;
std::cout << evaluated << std::endl;

return 0;
}
35 changes: 35 additions & 0 deletions docs/abi/example_evaluate_hodograph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"

int main(int argc, char* argv[])
{
// Inputs.
double s = 0.125;
bezier::Matrix<2, 4> nodes {
{ 1.0, 1.0, 2.0, 2.0 },
{ 0.0, 1.0, 0.0, 1.0 },
};

// Outputs.
bezier::Vector<2> hodograph = bezier::evaluate_hodograph(s, nodes);

std::cout << "Hodograph:" << std::endl;
std::cout << hodograph[0] << std::endl;
std::cout << hodograph[1] << std::endl;

return 0;
}
35 changes: 35 additions & 0 deletions docs/abi/example_evaluate_multi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"
#include "xtensor/xio.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 4> nodes {
{ 1.0, 1.0, 2.0, 2.0 },
{ 0.0, 1.0, 0.0, 1.0 },
};
bezier::Vector<3> s_vals { 0.0, 0.5, 1.0 };

// Outputs.
bezier::Matrix<2, 3> evaluated = bezier::evaluate_multi(nodes, s_vals);

std::cout << "Evaluated:" << std::endl;
std::cout << evaluated << std::endl;

return 0;
}
46 changes: 46 additions & 0 deletions docs/abi/example_full_reduce.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xview.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 5> nodes {
{ 1.0, 1.25, 1.5, 1.75, 2.0 },
{ 3.0, 3.5, 4.0, 4.5, 5.0 },
};

// Outputs.
int num_reduced_nodes;
bezier::Matrix<2, 5> reduced;
bool not_implemented;

std::tuple<int, bool> status_pair = bezier::full_reduce(nodes, reduced);
num_reduced_nodes = std::get<0>(status_pair);
not_implemented = std::get<1>(status_pair);
auto reduced_view
= xt::view(reduced, xt::all(), xt::range(0, num_reduced_nodes));

std::cout << "Number of reduced nodes: " << num_reduced_nodes << std::endl;
std::cout << "Reduced:" << std::endl;
std::cout << reduced_view << std::endl;
std::cout << "Not implemented: " << (not_implemented ? "TRUE" : "FALSE")
<< std::endl;

return 0;
}
34 changes: 34 additions & 0 deletions docs/abi/example_get_curvature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 5> nodes {
{ 1.0, 0.75, 0.5, 0.25, 0.0 },
{ 0.0, 2.0, -2.0, 2.0, 0.0 },
};
bezier::Vector<2> tangent_vec { -1.0, 0.0 };
double s = 0.5;

// Outputs.
double curvature = bezier::get_curvature(nodes, tangent_vec, s);

std::cout << "Curvature: " << curvature << std::endl;

return 0;
}
43 changes: 43 additions & 0 deletions docs/abi/example_locate_point_curve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 4> nodes {
{ 0.0, -1.0, 1.0, -0.75 },
{ 2.0, 0.0, 1.0, 1.625 },
};
bezier::Vector<2> point1 { -0.09375, 0.828125 };
bezier::Vector<2> point2 { 0.0, 1.5 };
bezier::Vector<2> point3 { -0.25, 1.375 };

// Outputs.
double s_approx;

s_approx = bezier::locate_point_curve(nodes, point1);
std::cout << "When B(s) = [" << point1[0] << ", " << point1[1]
<< "]; s = " << s_approx << std::endl;
s_approx = bezier::locate_point_curve(nodes, point2);
std::cout << "When B(s) = [" << point2[0] << ", " << point2[1]
<< "]; s = " << s_approx << std::endl;
s_approx = bezier::locate_point_curve(nodes, point3);
std::cout << "When B(s) = [" << point3[0] << ", " << point3[1]
<< "]; s = " << s_approx << std::endl;

return 0;
}
34 changes: 34 additions & 0 deletions docs/abi/example_newton_refine_curve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 3> nodes {
{ 0.0, 1.0, 3.0 },
{ 0.0, 2.0, 1.0 },
};
bezier::Vector<2> point { 0.5625, 0.8125 };
double s = 0.75;

// Outputs.
double updated_s = bezier::newton_refine_curve(nodes, point, s);

std::cout << "Updated s: " << updated_s << std::endl;

return 0;
}
39 changes: 39 additions & 0 deletions docs/abi/example_reduce_pseudo_inverse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"
#include "xtensor/xio.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 4> nodes {
{ -3.0, 0.0, 1.0, 0.0 },
{ 3.0, 2.0, 3.0, 6.0 },
};

// Outputs.
bezier::Matrix<2, 3> reduced;
bool not_implemented;

not_implemented = bezier::reduce_pseudo_inverse(nodes, reduced);

std::cout << "Reduced:" << std::endl;
std::cout << reduced << std::endl;
std::cout << "Not implemented: " << (not_implemented ? "TRUE" : "FALSE")
<< std::endl;

return 0;
}
37 changes: 37 additions & 0 deletions docs/abi/example_specialize_curve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "bezier.hpp"
#include "xtensor/xfixed.hpp"
#include "xtensor/xio.hpp"

int main(int argc, char* argv[])
{
// Inputs.
bezier::Matrix<2, 3> nodes {
{ 0.0, 0.5, 1.0 },
{ 0.0, 1.0, 0.0 },
};
double start = -0.25;
double end = 0.75;

// Outputs.
bezier::Matrix<2, 3> new_nodes
= bezier::specialize_curve(nodes, start, end);

std::cout << "New Nodes:" << std::endl;
std::cout << new_nodes << std::endl;

return 0;
}
Loading