Skip to content

Commit

Permalink
Apply #464 on hppfcl3x (#465)
Browse files Browse the repository at this point in the history
* ruff --fix .

* add previous commit to git-blame-ignore-revs

* manual ruff fixes

* pre-commit-sort

* pre-commit: add ruff

* black .

* add previous commit to git-blame-ignore-revs

* README: add black & ruff badges

* fix noqa

* pre-commit autoupdate

* pre-commit run -a
  • Loading branch information
nim65s authored Nov 12, 2023
1 parent 7dcc8e5 commit 1cdd6e8
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 94 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
0067c8aa66aac548601e2a3fd029aa264cc59f2a
76b68f785df31b00e153290b45ec290a9c5f7963
# ruff --fix . (Guilhem Saurel, 2023-10-25)
02cef56abfacee590c8444fd379c8837bf007fa1
# black . (Guilhem Saurel, 2023-10-25)
febfbcbe9c98cdb4e0c7bbf4554a6925b391834b
36 changes: 22 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
ci:
autoupdate_branch: 'devel'
autoupdate_branch: devel
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6
hooks:
- id: clang-format
args: ['--style={BasedOnStyle: Google, SortIncludes: false}']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.2
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.3
hooks:
- id: clang-format
args:
- '--style={BasedOnStyle: Google, SortIncludes: false}'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
HPP-FCL — An extension of the Flexible Collision Library
=======
# HPP-FCL — An extension of the Flexible Collision Library

<p align="center">
<a href="https://gepgitlab.laas.fr/humanoid-path-planner/hpp-fcl/commits/master/"><img src="https://gepgitlab.laas.fr/humanoid-path-planner/hpp-fcl/badges/master/pipeline.svg" alt="Pipeline status"/></a>
Expand All @@ -8,6 +7,8 @@ HPP-FCL — An extension of the Flexible Collision Library
<a href="https://anaconda.org/conda-forge/hpp-fcl"><img src="https://img.shields.io/conda/dn/conda-forge/hpp-fcl.svg" alt="Conda Downloads"/></a>
<a href="https://anaconda.org/conda-forge/hpp-fcl"><img src="https://img.shields.io/conda/vn/conda-forge/hpp-fcl.svg" alt="Conda Version"/></a>
<a href="https://badge.fury.io/py/hpp-fcl"><img src="https://badge.fury.io/py/hpp-fcl.svg" alt="PyPI version"></a>
<a href="https://github.com/psf/black"><img alt="black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://github.com/astral-sh/ruff"><img alt="ruff" src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json"></a>
</p>

[FCL](https://github.com/flexible-collision-library/fcl) was forked in 2015. Since then, a large part of the code has been rewritten or removed (for the unused and untested part).
Expand Down Expand Up @@ -37,4 +38,3 @@ Unlike the original FCL library, HPP-FCL implements the well-established GJK alg
## Acknowledgments

The development of **HPP-FCL** is actively supported by the [Gepetto team](http://projects.laas.fr/gepetto/) [@LAAS-CNRS](http://www.laas.fr), the [Willow team](https://www.di.ens.fr/willow/) [@INRIA](http://www.inria.fr) and, to some extend, [Eureka Robotics](https://eurekarobotics.com/).

1 change: 0 additions & 1 deletion doc/generate_distance_plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import matplotlib.pyplot as plt
import numpy as np
from math import sqrt

interactive = False

Expand Down
58 changes: 29 additions & 29 deletions doc/gjk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
edge_fmt = "{j}a * {b}a_{c}a + {j}{b} * {c}a_aa - {j}{c} * {b}a_aa"

# These checks must be negative and not positive, as in the cheat sheet.
# They are the same as in the cheat sheet, except that we consider (...).dot(A) instead of (...).dot(-A)
# They are the same as in the cheat sheet, except that we consider (...).dot(A)
# instead of (...).dot(-A)
plane_tests = ["C.dot (a_cross_b)", "D.dot(a_cross_c)", "-D.dot(a_cross_b)"]
checks = (
plane_tests
Expand Down Expand Up @@ -247,9 +248,9 @@
def set_test_values(current_tests, test_values, itest, value):
def satisfies(values, indices):
for k in indices:
if k > 0 and values[k - 1] != True:
if k > 0 and values[k - 1] is not True:
return False
if k < 0 and values[-k - 1] != False:
if k < 0 and values[-k - 1] is not False:
return False
return True

Expand Down Expand Up @@ -286,17 +287,17 @@ def set_tests_values(current_tests, test_values, itests, values):
def apply_test_values(cases, test_values):
def canSatisfy(values, indices):
for k in indices:
if k > 0 and values[k - 1] == False:
if k > 0 and values[k - 1] is False:
return False
if k < 0 and values[-k - 1] == True:
if k < 0 and values[-k - 1] is True:
return False
return True

def satisfies(values, indices):
for k in indices:
if k > 0 and values[k - 1] != True:
if k > 0 and values[k - 1] is not True:
return False
if k < 0 and values[-k - 1] != False:
if k < 0 and values[-k - 1] is not False:
return False
return True

Expand Down Expand Up @@ -337,7 +338,7 @@ def max_number_of_tests(
prevScore=0,
):
for test in current_tests:
assert test_values[test] == None, "Test " + str(test) + " already performed"
assert test_values[test] is None, "Test " + str(test) + " already performed"

left_cases = apply_test_values(cases, test_values)

Expand Down Expand Up @@ -375,7 +376,8 @@ def max_number_of_tests(
remaining_tests = None

if remaining_tests is not None:
# Do not put this in try catch as I do not want other ValueError to be understood as an infeasible branch.
# Do not put this in try catch as I do not want other ValueError to be
# understood as an infeasible branch.
score_if_t, order_if_t = max_number_of_tests(
remaining_tests,
left_cases,
Expand All @@ -396,7 +398,8 @@ def max_number_of_tests(
remaining_tests = None

if remaining_tests is not None:
# Do not put this in try catch as I do not want other ValueError to be understood as an infeasible branch.
# Do not put this in try catch as I do not want other ValueError to be
# understood as an infeasible branch.
score_if_f, order_if_f = max_number_of_tests(
remaining_tests,
left_cases,
Expand Down Expand Up @@ -438,37 +441,37 @@ def printOrder(order, indent="", start=True, file=sys.stdout, curTests=[]):
file=file,
)
print(indent + "const vertex_id_t a = 3, b = 2, c = 1, d = 0;", file=file)
for l in "abcd":
for v in "abcd":
print(
indent
+ "const Vec3f& {} (current.vertex[{}]->w);".format(l.upper(), l),
+ "const Vec3f& {} (current.vertex[{}]->w);".format(v.upper(), v),
file=file,
)
print(indent + "const FCL_REAL aa = A.squaredNorm();".format(l), file=file)
for l in "dcb":
print(indent + "const FCL_REAL aa = A.squaredNorm();".format(), file=file)
for v in "dcb":
for m in "abcd":
if m <= l:
if m <= v:
print(
indent
+ "const FCL_REAL {0}{1} = {2}.dot({3});".format(
l, m, l.upper(), m.upper()
v, m, v.upper(), m.upper()
),
file=file,
)
else:
print(
indent + "const FCL_REAL& {0}{1} = {1}{0};".format(l, m),
indent + "const FCL_REAL& {0}{1} = {1}{0};".format(v, m),
file=file,
)
print(indent + "const FCL_REAL {0}a_aa = {0}a - aa;".format(l), file=file)
print(indent + "const FCL_REAL {0}a_aa = {0}a - aa;".format(v), file=file)
for l0, l1 in zip("bcd", "cdb"):
print(
indent + "const FCL_REAL {0}a_{1}a = {0}a - {1}a;".format(l0, l1),
file=file,
)
for l in "bc":
for v in "bc":
print(
indent + "const Vec3f a_cross_{0} = A.cross({1});".format(l, l.upper()),
indent + "const Vec3f a_cross_{0} = A.cross({1});".format(v, v.upper()),
file=file,
)
print("", file=file)
Expand Down Expand Up @@ -502,15 +505,12 @@ def printOrder(order, indent="", start=True, file=sys.stdout, curTests=[]):
elif region == "A":
print(indent + "originToPoint (current, a, A, next, ray);", file=file)
elif len(region) == 2:
a = region[0]
region[0]
B = region[1]
print(
indent
+ "originToSegment (current, a, {b}, A, {B}, {B}-A, -{b}a_aa, next, ray);".format(
**{
"b": B.lower(),
"B": B,
}
indent + "originToSegment "
"(current, a, {b}, A, {B}, {B}-A, -{b}a_aa, next, ray);".format(
**{"b": B.lower(), "B": B}
),
file=file,
)
Expand All @@ -524,8 +524,8 @@ def printOrder(order, indent="", start=True, file=sys.stdout, curTests=[]):
else:
test = "-" + test
print(
indent
+ "originToTriangle (current, a, {b}, {c}, ({B}-A).cross({C}-A), {t}, next, ray);".format(
indent + "originToTriangle "
"(current, a, {b}, {c}, ({B}-A).cross({C}-A), {t}, next, ray);".format(
**{"b": B.lower(), "c": C.lower(), "B": B, "C": C, "t": test}
),
file=file,
Expand Down
11 changes: 3 additions & 8 deletions doc/python/doxygen_xml_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python3
# ruff: noqa: E501

from __future__ import print_function
from lxml import etree
Expand Down Expand Up @@ -120,8 +121,6 @@ def _templateParamToDict(param):


def makeHeaderGuard(filename):
import os

return filename.upper().replace(".", "_").replace("/", "_").replace("-", "_")


Expand Down Expand Up @@ -326,8 +325,6 @@ def getdeclname(i, declname):
return ", ".join([arg.format(n) for n in argnames])

def include(self):
import os.path

loc = self.xml.find("location")
# The location is based on $CMAKE_SOURCE_DIR. Remove first directory.
return loc.attrib["file"].split("/", 1)[1]
Expand Down Expand Up @@ -705,8 +702,6 @@ def parseCompound(self):

def write(self):
# Header
from os.path import abspath, dirname
from time import asctime

self.output.open("doxygen_xml_parser_for_cmake.hh")
# self.output.out ("// Generated on {}".format (asctime()))
Expand Down Expand Up @@ -821,7 +816,7 @@ def __init__(self, output_dir, warn, error, errorPrefix=""):
self._created_files = dict()

def open(self, name):
assert self._out == None, "You did not close the previous file"
assert self._out is None, "You did not close the previous file"
import os

fullname = os.path.join(self.output_dir, name)
Expand Down Expand Up @@ -895,4 +890,4 @@ def err(self, *args):
index.parseCompound()
index.write()
index.output.writeFooterAndCloseFiles()
assert index.output._out == None
assert index.output._out is None
10 changes: 5 additions & 5 deletions doc/python/xml_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def _newline(self, n=1):

def _clean(self):
s = 0
for l in self.lines:
if len(l.strip()) == 0:
for line in self.lines:
if len(line.strip()) == 0:
s += 1
else:
break
e = len(self.lines)
for l in reversed(self.lines):
if len(l.strip()) == 0:
for line in reversed(self.lines):
if len(line.strip()) == 0:
e -= 1
else:
break
Expand All @@ -80,7 +80,7 @@ def getDocString(self, brief, detailled, output):
if brief is not None:
self._newline()
self.visit(detailled)
from sys import stdout, stderr, version_info
from sys import version_info

self.writeErrors(output)
self._clean()
Expand Down
3 changes: 2 additions & 1 deletion python/hppfcl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# ruff: noqa: F401, F403
from .hppfcl import *
from .hppfcl import __version__, __raw_version__
from .hppfcl import __raw_version__, __version__
11 changes: 6 additions & 5 deletions python/hppfcl/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# Copyright (c) 2019 CNRS
# Author: Joseph Mirabel

import hppfcl, numpy as np
import warnings

import numpy as np
from gepetto import Color

import hppfcl


def applyConfiguration(gui, name, tf):
gui.applyConfiguration(
Expand Down Expand Up @@ -43,10 +47,7 @@ def displayShape(gui, name, geom, color=(0.9, 0.9, 0.9, 1.0)):
gui.setLightingMode(name, "OFF")
return True
else:
msg = "Unsupported geometry type for %s (%s)" % (
geometry_object.name,
type(geom),
)
msg = "Unsupported geometry type for %s (%s)" % (name, type(geom))
warnings.warn(msg, category=UserWarning, stacklevel=2)
return False

Expand Down
2 changes: 1 addition & 1 deletion python/pickle.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct PickleObject : boost::python::pickle_suite {
static boost::python::tuple getstate(const T& obj) {
std::stringstream ss;
boost::archive::text_oarchive oa(ss);
oa& obj;
oa & obj;

return boost::python::make_tuple(boost::python::str(ss.str()));
}
Expand Down
10 changes: 5 additions & 5 deletions test/python_unit/geometric_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ def test_convex(self):
]
)
faces.append(hppfcl.Triangle(0, 1, 2))
convex = hppfcl.Convex(verts, faces)
hppfcl.Convex(verts, faces)

verts.append(np.array([0, 0, 1]))
try:
convexHull = hppfcl.Convex.convexHull(verts, False, None)
hppfcl.Convex.convexHull(verts, False, None)
qhullAvailable = True
except Exception as e:
self.assertEqual(
Expand All @@ -180,11 +180,11 @@ def test_convex(self):
qhullAvailable = False

if qhullAvailable:
convexHull = hppfcl.Convex.convexHull(verts, False, "")
convexHull = hppfcl.Convex.convexHull(verts, True, "")
hppfcl.Convex.convexHull(verts, False, "")
hppfcl.Convex.convexHull(verts, True, "")

try:
convexHull = hppfcl.Convex.convexHull(verts[:3], False, None)
hppfcl.Convex.convexHull(verts[:3], False, None)
except Exception as e:
self.assertIn(
str(e), "You shouldn't use this function with less than 4 points."
Expand Down
9 changes: 5 additions & 4 deletions test/scripts/collision-bench.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import csv
import sys

import matplotlib.pyplot as plt
import csv, sys, numpy as np
from math import sqrt

filename = sys.argv[1]

Expand Down Expand Up @@ -43,8 +44,8 @@
idx_reorder = sorted(list(range(len(xvals))), key=lambda i: xvals[i])


def reorder(l):
return [l[i] for i in idx_reorder]
def reorder(v):
return [v[i] for i in idx_reorder]


xvals_s = reorder(xvals)
Expand Down
Loading

0 comments on commit 1cdd6e8

Please sign in to comment.