Skip to content

Commit

Permalink
Merge pull request gazebosim#307 from scpeters/merge_6_some_python_to…
Browse files Browse the repository at this point in the history
…_main

Merge some ign-math6 python bindings to main
  • Loading branch information
scpeters authored Dec 17, 2021
2 parents e423313 + 21522c5 commit e0cc08f
Show file tree
Hide file tree
Showing 45 changed files with 1,857 additions and 150 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
uses: ignition-tooling/action-ignition-ci@bionic
with:
codecov-enabled: true
doxygen-enabled: true
focal-ci:
runs-on: ubuntu-latest
name: Ubuntu Focal CI
Expand Down
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if (NOT SWIG_FOUND)
IGN_BUILD_WARNING("Swig is missing: Language interfaces are disabled.")
message (STATUS "Searching for swig - not found.")
else()
message (STATUS "Searching for swig - found.")
message (STATUS "Searching for swig - found version ${SWIG_VERSION}.")
endif()

# Include other languages if swig was found
Expand All @@ -55,10 +55,23 @@ if (SWIG_FOUND)
IGN_BUILD_WARNING("Ruby is missing: Install ruby-dev to enable ruby interface to ignition math.")
message (STATUS "Searching for Ruby - not found.")
else()
message (STATUS "Searching for Ruby - found.")
message (STATUS "Searching for Ruby - found version ${RUBY_VERSION}.")
endif()

########################################
# Include python
find_package(PythonLibs QUIET)
if (NOT PYTHONLIBS_FOUND)
message (STATUS "Searching for Python - not found.")
else()
message (STATUS "Searching for Python - found version ${PYTHONLIBS_VERSION_STRING}.")
endif()
endif()

# Location of "fake install folder" used in tests
# Defined here at root scope so it is available for tests in src and test folders
set(FAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/fake/install")

#============================================================================
# Configure the build
#============================================================================
Expand Down
48 changes: 0 additions & 48 deletions bitbucket-pipelines.yml

This file was deleted.

43 changes: 43 additions & 0 deletions examples/angle_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (C) 2021 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.

# This example will only work if the Python interface library was compiled and
# installed.
#
# Modify the PYTHONPATH environment variable to include the ignition math
# library install path. For example, if you install to /user:
#
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH
#

import ignition.math

print("PI in degrees = {}\n".format(ignition.math.Angle.PI.degree()))

a1 = ignition.math.Angle(1.5707)
a2 = ignition.math.Angle(0.7854)
print("a1 = {} radians, {} degrees\n".format(a1.radian(), a1.degree()))
print("a2 = {} radians, {} degrees\n".format(a2.radian(), a2.degree()))
print("a1 * a2 = {} radians, {} degrees\n".format((a1 * a2).radian(),
(a1 * a2).degree()))
print("a1 + a2 = {} radians, {} degrees\n".format((a1 + a2).radian(),
(a1 + a2).degree()))
print("a1 - a2 = {} radians, {} degrees\n".format((a1 - a2).radian(),
(a1 - a2).degree()))

a3 = ignition.math.Angle(15.707)
print("a3 = {} radians, {} degrees\n".format(a3.radian(), a3.degree()))
a3.normalize()
print("a3.Normalize = {} radians, {} degrees\n".format(a3.radian(),
a3.degree()))
39 changes: 39 additions & 0 deletions examples/vector2_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2021 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.

# This example will only work if the Python interface library was compiled and
# installed.
#
# Modify the PYTHONPATH environment variable to include the ignition math
# library install path. For example, if you install to /user:
#
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH
#
import ignition.math

va = ignition.math.Vector2d(1, 2)
vb = ignition.math.Vector2d(3, 4)
vc = ignition.math.Vector2d(vb)

print("va = {} {}\n".format(va.x(), va.y()))
print("vb = {} {}\n".format(vb.x(), vb.y()))
print("vc = {} {}\n".format(vc.x(), vc.y()))

vb += va
print("vb += va: {} {}\n".format(vb.x(), vb.y()))

vb.normalize()
print("vb.normalize = {} {}\n".format(vb.x(), vb.y()))

print("vb.distance(va) = {}\n".format(vb.distance(va)))
34 changes: 34 additions & 0 deletions examples/vector3_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2021 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.

# This example will only work if the Python interface library was compiled and
# installed.
#
# Modify the PYTHONPATH environment variable to include the ignition math
# library install path. For example, if you install to /user:
#
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH
#
import ignition.math

v1 = ignition.math.Vector3d(0, 0, 3)
print("v =: {} {} {}\n".format(v1.x(), v1.y(), v1.z()))

v2 = ignition.math.Vector3d(4, 0, 0)
print("v2 = {} {} {}\n".format(v2.x(), v2.y(), v2.z()))

v3 = v1 + v2
print("v1 + v2 = {} {} {}\n".format(v3.x(), v3.y(), v3.z()))

print("v1.Distance(v2) = {}\n".format(v1.distance(v2)))
1 change: 0 additions & 1 deletion include/ignition/math/Cylinder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ namespace ignition
/// \brief Set the rotation offset.
/// See Quaternion<Precision> RotationalOffset() for details on the
/// rotational offset.
/// \return The cylinder's orientation.
/// \sa Quaternion<Precision> RotationalOffset() const
public: void SetRotationalOffset(
const Quaternion<Precision> &_rotOffset);
Expand Down
2 changes: 1 addition & 1 deletion include/ignition/math/Ellipsoid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace ignition
public: Vector3<Precision> Radii() const;

/// \brief Set the radius in meters.
/// \param[in] _radius The radius of the ellipsoid in meters.
/// \param[in] _radii The radii of the ellipsoid in meters.
public: void SetRadii(const Vector3<Precision> &_radii);

/// \brief Get the material associated with this ellipsoid.
Expand Down
2 changes: 1 addition & 1 deletion include/ignition/math/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ namespace ignition
/// \brief Append a number to a stream, specialized for int.
/// \param[out] _out Output stream.
/// \param[in] _number Number to append.
/// \param[in] _precision Not used for int.
// _precision Not used for int.
template<>
inline void appendToStream(std::ostream &_out, int _number, int)
{
Expand Down
8 changes: 0 additions & 8 deletions include/ignition/math/SignalStats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ namespace ignition
#pragma warning(pop)
#endif
};
/// \}

/// \class SignalMaximum SignalStats.hh ignition/math/SignalStats.hh
/// \brief Computing the maximum value of a discretely sampled signal.
Expand All @@ -94,7 +93,6 @@ namespace ignition
// Documentation inherited.
public: virtual void InsertData(const double _data) override;
};
/// \}

/// \class SignalMean SignalStats.hh ignition/math/SignalStats.hh
/// \brief Computing the mean value of a discretely sampled signal.
Expand All @@ -110,7 +108,6 @@ namespace ignition
// Documentation inherited.
public: virtual void InsertData(const double _data) override;
};
/// \}

/// \class SignalMinimum SignalStats.hh ignition/math/SignalStats.hh
/// \brief Computing the minimum value of a discretely sampled signal.
Expand All @@ -126,7 +123,6 @@ namespace ignition
// Documentation inherited.
public: virtual void InsertData(const double _data) override;
};
/// \}

/// \class SignalRootMeanSquare SignalStats.hh ignition/math/SignalStats.hh
/// \brief Computing the square root of the mean squared value
Expand All @@ -143,7 +139,6 @@ namespace ignition
// Documentation inherited.
public: virtual void InsertData(const double _data) override;
};
/// \}

/// \class SignalMaxAbsoluteValue SignalStats.hh
/// ignition/math/SignalStats.hh
Expand All @@ -162,7 +157,6 @@ namespace ignition
// Documentation inherited.
public: virtual void InsertData(const double _data) override;
};
/// \}

/// \class SignalVariance SignalStats.hh ignition/math/SignalStats.hh
/// \brief Computing the incremental variance
Expand All @@ -179,7 +173,6 @@ namespace ignition
// Documentation inherited.
public: virtual void InsertData(const double _data) override;
};
/// \}

/// \brief Forward declare private data class.
class SignalStatsPrivate;
Expand Down Expand Up @@ -256,7 +249,6 @@ namespace ignition
#endif
};
}
/// \}
}
}
#endif
Expand Down
1 change: 0 additions & 1 deletion include/ignition/math/SphericalCoordinates.hh
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ namespace ignition
#pragma warning(pop)
#endif
};
/// \}
}
}
}
Expand Down
77 changes: 3 additions & 74 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,6 @@ ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
# graph namespace
add_subdirectory(graph)

#################################################
# Setup swig
if (SWIG_FOUND)
if (POLICY CMP0078)
cmake_policy(SET CMP0078 NEW)
endif()
if (POLICY CMP0086)
cmake_policy(SET CMP0086 NEW)
endif()

include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")

include_directories(${PROJECT_SOURCE_DIR}/include)

set(swig_files
ruby
Angle
GaussMarkovProcess
Helpers
Matrix3
Pose3
Quaternion
Rand
Temperature
Vector2
Vector3
Vector4)
endif()

#################################################
# Create and install Ruby interfaces
# Example usage
# $ export RUBYLIB=/usr/local/lib/ruby
# $ ruby -e "require 'ignition/math'; a = Ignition::Math::Angle.new(20); puts a.Degree()"
if (RUBY_FOUND)
foreach (swig_file ${swig_files})
# Assuming that each swig file has a test
list(APPEND ruby_tests ${swig_file}_TEST)

# Generate the list if .i files
list(APPEND swig_i_files ${swig_file}.i)
endforeach()

# Turn on c++
set_source_files_properties(${swig_i_files} PROPERTIES CPLUSPLUS ON)

# Create the ruby library

if(CMAKE_VERSION VERSION_GREATER 3.8.0)
SWIG_ADD_LIBRARY(math LANGUAGE ruby SOURCES ruby.i ${swig_i_files} ${sources})
else()
SWIG_ADD_MODULE(math ruby ruby.i ${swig_i_files} ${sources})
endif()

# Suppress warnings on SWIG-generated files
target_compile_options(math PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Wno-pedantic -Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter>
$<$<CXX_COMPILER_ID:Clang>:-Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter>
)
target_include_directories(math SYSTEM PUBLIC ${RUBY_INCLUDE_DIRS})

SWIG_LINK_LIBRARIES(math ${RUBY_LIBRARY})
target_compile_features(math PUBLIC ${IGN_CXX_${c++standard}_FEATURES})
install(TARGETS math DESTINATION ${IGN_LIB_INSTALL_DIR}/ruby/ignition)

# Add the ruby tests
foreach (test ${ruby_tests})
add_test(NAME ${test}.rb COMMAND
ruby -I${CMAKE_BINARY_DIR}/lib ${CMAKE_SOURCE_DIR}/src/${test}.rb
--gtest_output=xml:${CMAKE_BINARY_DIR}/test_results/${test}rb.xml)
endforeach()
endif()
# Bindings subdirectories
add_subdirectory(python)
add_subdirectory(ruby)
Loading

0 comments on commit e0cc08f

Please sign in to comment.