Skip to content

Commit

Permalink
Merge branch 'main' into drop_mwf_pimpl
Browse files Browse the repository at this point in the history
  • Loading branch information
nkoenig authored Mar 28, 2022
2 parents fb6aedb + b1cb6bb commit 098bac5
Show file tree
Hide file tree
Showing 10 changed files with 1,757 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ target_link_libraries(graph_example ignition-math${IGN_MATH_VER}::ignition-math$
add_executable(helpers_example helpers_example.cc)
target_link_libraries(helpers_example ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

add_executable(interval_example interval_example.cc)
target_link_libraries(interval_example ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

add_executable(kmeans kmeans.cc)
target_link_libraries(kmeans ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

add_executable(matrix3_example matrix3_example.cc)
target_link_libraries(matrix3_example ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

add_executable(polynomial3_example polynomial3_example.cc)
target_link_libraries(polynomial3_example ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

add_executable(pose3_example pose3_example.cc)
target_link_libraries(pose3_example ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

Expand All @@ -45,6 +51,9 @@ target_link_libraries(quaternion_to_euler ignition-math${IGN_MATH_VER}::ignition
add_executable(rand_example rand_example.cc)
target_link_libraries(rand_example ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

add_executable(region3_example region3_example.cc)
target_link_libraries(region3_example ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

add_executable(temperature_example temperature_example.cc)
target_link_libraries(temperature_example ignition-math${IGN_MATH_VER}::ignition-math${IGN_MATH_VER})

Expand Down
60 changes: 60 additions & 0 deletions examples/interval_example.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* 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
*
* http://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.
*
*/
//! [complete]
#include <iostream>
#include <ignition/math/Interval.hh>

int main(int argc, char **argv)
{
std::cout << std::boolalpha;

const ignition::math::Intervald defaultInterval;
// A default constructed interval should be empty.
std::cout << "The " << defaultInterval << " interval is empty: "
<< defaultInterval.Empty() << std::endl;

const ignition::math::Intervald openInterval =
ignition::math::Intervald::Open(-1., 1.);
// An open interval should exclude its endpoints.
std::cout << "The " << openInterval << " interval contains its endpoints: "
<< (openInterval.Contains(openInterval.LeftValue()) ||
openInterval.Contains(openInterval.RightValue()))
<< std::endl;

const ignition::math::Intervald closedInterval =
ignition::math::Intervald::Closed(0., 1.);

// A closed interval should include its endpoints.
std::cout << "The " << closedInterval << " interval contains its endpoints: "
<< (closedInterval.Contains(closedInterval.LeftValue()) ||
closedInterval.Contains(closedInterval.RightValue()))
<< std::endl;

// Closed and open intervals may intersect.
std::cout << "Intervals " << closedInterval << " and " << openInterval
<< " intersect: " << closedInterval.Intersects(openInterval)
<< std::endl;

// The unbounded interval should include all non-empty intervals.
std::cout << "The " << ignition::math::Intervald::Unbounded
<< " interval contains all previous non-empty intervals: "
<< (ignition::math::Intervald::Unbounded.Contains(openInterval) ||
ignition::math::Intervald::Unbounded.Contains(closedInterval))
<< std::endl;

}
//! [complete]
59 changes: 59 additions & 0 deletions examples/polynomial3_example.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* 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
*
* http://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.
*
*/
//! [complete]
#include <iostream>
#include <ignition/math/Polynomial3.hh>
#include <ignition/math/Vector4.hh>

int main(int argc, char **argv)
{
// A default constructed polynomial should have zero coefficients.
std::cout << "A default constructed polynomial is always: "
<< ignition::math::Polynomial3d() << std::endl;

// A constant polynomial only has an independent term.
std::cout << "A constant polynomial only has an independent term: "
<< ignition::math::Polynomial3d::Constant(-1.) << std::endl;

// A cubic polynomial may be incomplete.
const ignition::math::Polynomial3d p(
ignition::math::Vector4d(1., 0., -1., 2.));
std::cout << "A cubic polynomial may be incomplete: " << p << std::endl;

// A polynomial can be evaluated.
const double x = 0.5;
std::cout << "Evaluating " << p << " at " << x
<< " yields " << p(x) << std::endl;

// A polynomial can be queried for its minimum in a given interval,
// as well as for its global minimum (which may not always be finite).
const ignition::math::Intervald interval =
ignition::math::Intervald::Closed(-1, 1.);
std::cout << "The minimum of " << p << " in the " << interval
<< " interval is " << p.Minimum(interval) << std::endl;
std::cout << "The global minimum of " << p
<< " is " << p.Minimum() << std::endl;

const ignition::math::Polynomial3d q(
ignition::math::Vector4d(0., 1., 2., 1.));
std::cout << "The minimum of " << q << " in the " << interval
<< " interval is " << q.Minimum(interval) << std::endl;
std::cout << "The global minimum of " << q
<< " is " << q.Minimum() << std::endl;

}
//! [complete]
61 changes: 61 additions & 0 deletions examples/region3_example.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* 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
*
* http://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.
*
*/
//! [complete]
#include <iostream>
#include <ignition/math/Region3.hh>
#include <ignition/math/Vector3.hh>

int main(int argc, char **argv)
{
std::cout << std::boolalpha;

const ignition::math::Region3d defaultRegion;
// A default constructed region should be empty.
std::cout << "The " << defaultRegion << " region is empty: "
<< defaultRegion.Empty() << std::endl;

const ignition::math::Region3d openRegion =
ignition::math::Region3d::Open(-1., -1., -1., 1., 1., 1.);
// An open region should exclude points on its boundary.
std::cout << "The " << openRegion << " region contains the "
<< ignition::math::Vector3d::UnitX << " point: "
<< openRegion.Contains(ignition::math::Vector3d::UnitX)
<< std::endl;

const ignition::math::Region3d closedRegion =
ignition::math::Region3d::Closed(0., 0., 0., 1., 1., 1.);

// A closed region should include points on its boundary.
std::cout << "The " << closedRegion << " region contains the "
<< ignition::math::Vector3d::UnitX << " point: "
<< closedRegion.Contains(ignition::math::Vector3d::UnitX)
<< std::endl;

// Closed and open regions may intersect.
std::cout << "Regions " << closedRegion << " and " << openRegion
<< " intersect: " << closedRegion.Intersects(openRegion)
<< std::endl;

// The unbounded region should include all non-empty regions.
std::cout << "The " << ignition::math::Region3d::Unbounded
<< " region contains all previous non-empty intervals: "
<< (ignition::math::Region3d::Unbounded.Contains(openRegion) ||
ignition::math::Region3d::Unbounded.Contains(closedRegion))
<< std::endl;

}
//! [complete]
Loading

0 comments on commit 098bac5

Please sign in to comment.