Initial commit

remotes/origingl/master
Martin Felis 2020-10-03 22:55:14 +02:00
commit 5b6d7ec170
356 changed files with 104747 additions and 0 deletions

13
.clang-format Normal file
View File

@ -0,0 +1,13 @@
---
BasedOnStyle: Google
AlignAfterOpenBracket: AlwaysBreak
AlignOperands: 'true'
AllowAllArgumentsOnNextLine: 'false'
AllowAllParametersOfDeclarationOnNextLine: 'false'
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: NonAssignment
ExperimentalAutoDetectBinPacking: 'false'
ReflowComments: 'false'
...

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.*.swp
.idea/**
build**
cmake-build-**

14
3rdparty/libccd/.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
Makefile.in
autom4te.cache/*
aclocal.m4
config.guess
config.sub
configure
depcomp
install-sh
ltmain.sh
missing
*~
src/gjk/config.h.in
build/*
ccd.pc

23
3rdparty/libccd/.travis.yml vendored Normal file
View File

@ -0,0 +1,23 @@
dist: trusty
sudo: required
language: c
compiler:
- gcc
- clang
env:
global:
- PREFIX="$TRAVIS_BUILD_DIR/build/install"
matrix:
- USE_AUTOTOOLS=yes
- USE_CMAKE=yes
- USE_MAKEFILE=yes USE_DOUBLE=yes
- USE_MAKEFILE=yes USE_SINGLE=yes
script:
- mkdir -p "$PREFIX"
- if [[ "$USE_AUTOTOOLS" == "yes" ]]; then ./bootstrap && cd build && ../configure --prefix "$PREFIX"; fi
- if [[ "$USE_CMAKE" == "yes" ]]; then cd build && cmake "-DCMAKE_INSTALL_PREFIX=$PREFIX" ..; fi
- if [[ "$USE_MAKEFILE" == "yes" ]]; then cd src; fi
- make && make install

44
3rdparty/libccd/BSD-LICENSE vendored Normal file
View File

@ -0,0 +1,44 @@
libccd
-------
Copyright (c)2010-2012 Daniel Fiser <danfis@danfis.cz>,
Intelligent and Mobile Robotics Group, Department of Cybernetics,
Faculty of Electrical Engineering, Czech Technical University in Prague.
All rights reserved.
This work was supported by SYMBRION and REPLICATOR projects.
The SYMBRION project is funded by European Commission within the work
"Future and Emergent Technologies Proactive" under grant agreement no.
216342.
The REPLICATOR project is funded within the work programme "Cognitive
Systems, Interaction, Robotics" under grant agreement no. 216240.
http://www.symbrion.eu/
http://www.replicators.eu/
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

79
3rdparty/libccd/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,79 @@
cmake_minimum_required(VERSION 3.15)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
# Can not explicitly declared the software as C in project command due to bug:
# https://gitlab.kitware.com/cmake/cmake/issues/16967
project(libccd)
set(CCD_VERSION_MAJOR 2)
set(CCD_VERSION_MINOR 0)
set(CCD_VERSION ${CCD_VERSION_MAJOR}.${CCD_VERSION_MINOR})
set(CCD_SOVERSION 2)
project (CCD
VERSION ${CCD_VERSION}
LANGUAGES C)
# Include GNUInstallDirs to get canonical paths
include(GNUInstallDirs)
include(CTest)
option(BUILD_DOCUMENTATION "Build the documentation" OFF)
option(BUILD_SHARED_LIBS "Build libccd as a shared library" ON)
option(ENABLE_DOUBLE_PRECISION
"Enable double precision computations instead of single precision" OFF)
# Option for some bundle-like build system in order not to expose
# any FCL binary symbols in their public ABI
option(CCD_HIDE_ALL_SYMBOLS "Hide all binary symbols" OFF)
if (CCD_HIDE_ALL_SYMBOLS)
add_definitions("-DCCD_STATIC_DEFINE")
endif()
# set the default build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build; options are Debug Release RelWithDebInfo MinSizeRel"
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS
Debug
Release
RelWithDebInfo
MinSizeRel)
endif()
add_subdirectory(src)
if(BUILD_DOCUMENTATION)
add_subdirectory(doc)
endif()
include(CMakePackageConfigHelpers)
configure_package_config_file(ccd-config.cmake.in ccd-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/ccd"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(ccd-config-version.cmake
VERSION ${CCD_VERSION} COMPATIBILITY AnyNewerVersion)
install(FILES
"${CMAKE_BINARY_DIR}/ccd-config.cmake"
"${CMAKE_BINARY_DIR}/ccd-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/ccd")
set(CCD_PKGCONFIG_DESCRIPTION
"Library for collision detection between convex shapes")
configure_file(ccd.pc.in ccd.pc @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/ccd.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(FILES BSD-LICENSE DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/ccd")

6
3rdparty/libccd/Makefile.am vendored Normal file
View File

@ -0,0 +1,6 @@
SUBDIRS = src
EXTRA_DIST = doc \
BSD-LICENSE \
README.md \
make-release.sh

296
3rdparty/libccd/README.md vendored Normal file
View File

@ -0,0 +1,296 @@
# libccd [![Build Status](https://travis-ci.org/danfis/libccd.svg?branch=master)](https://travis-ci.org/danfis/libccd)
***libccd*** is library for a collision detection between two convex shapes.
libccd implements variation on GilbertJohnsonKeerthi algorithm plus Expand
Polytope Algorithm (EPA) and also implements algorithm Minkowski Portal
Refinement (MPR, a.k.a. XenoCollide) as described in Game Programming Gems 7.
libccd is the only available open source library of my knowledge that include
MPR algorithm working in 3-D space. However, there is a library called
[mpr2d](http://code.google.com/p/mpr2d/), implemented in D programming
language, that works in 2-D space.
libccd is currently part of:
1. [ODE](http://www.ode.org/) library (see ODE's *./configure --help* how to enable it),
2. [FCL](http://www.ros.org/wiki/fcl) library from [Willow Garage](http://www.willowgarage.com/),
3. [Bullet3](http://bulletphysics.org/) library (https://github.com/bulletphysics/bullet3).
For implementation details on GJK algorithm, see
http://www.win.tue.nl/~gino/solid/jgt98convex.pdf.
## Dependencies
This library is currently based only on standard libraries.
The only exception are testsuites that are built on top of CU
(https://github.com/danfis/cu) library licensed under LGPL, however only
testing depends on it and libccd library itself can be distributed without it.
## License
libccd is licensed under OSI-approved 3-clause BSD License, text of license
is distributed along with source code in BSD-LICENSE file.
Each file should include license notice, the rest should be considered as
licensed under 3-clause BSD License.
## Compile And Install
libccd contains several mechanisms for compiling and installing. Using a simple Makefile, using autotools, and using CMake.
### 1. Using Makefile
Directory src/ contains Makefile that should contain everything needed for compilation and installation:
```sh
$ cd src/
$ make
$ make install
```
Library libccd is by default compiled in double precision of floating point numbers - you can change this by options *USE_SINGLE/USE_DOUBLE*, i.e.:
```sh
$ make USE_SINGLE=yes
```
will compile library in single precision.
Installation directory can be changed by options PREFIX, INCLUDEDIR and LIBDIR.
For more info type 'make help'.
### 2. Using Autotools
libccd also contains support for autotools:
Generate configure script etc.:
```sh
$ ./bootstrap
```
Create new build/ directory:
```sh
$ mkdir build && cd build
```
Run configure script:
```sh
$ ../configure
```
Run make and make install:
```sh
$ make && make install
```
configure script can change the way libccd is compiled and installed, most significant option is *--enable-double-precision* which enables double precision (single is default in this case).
### 3. Using CMake
To build using `make`:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" ..
$ make && make install
```
To build using `ninja`:
```sh
$ mkdir build && cd build
$ cmake -G Ninja ..
$ ninja && ninja install
```
Other build tools may be using by specifying a different generator. For example:
```sh
$ cmake -G Xcode ..
```
```bat
> cmake -G "Visual Studio 14 2015" ..
```
To compile using double precision, set the `ENABLE_DOUBLE_PRECISION` option:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DENABLE_DOUBLE_PRECISION=ON ..
$ make && make install
```
To build libccd as a shared library, set the `BUILD_SHARED_LIBS` option:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON ..
$ make && make install
```
To build the test suite, set the `BUILD_TESTING` option:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DBUILD_TESTING=ON ..
$ make && make test
```
The installation directory may be changed using the `CMAKE_INSTALL_PREFIX` variable:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/install ..
$ make && make install
```
## GJK - Intersection Test
This section describes how to use libccd for testing if two convex objects intersects (i.e., 'yes/no' test) using Gilbert-Johnson-Keerthi (GJK) algorithm.
Procedure is very simple (and is similar for usages of library):
1. Include *<ccd/ccd.h>* file.
2. Implement support function for specific shapes. Support function is function that returns furthest point from object (shape) in specified direction.
3. Set up *ccd_t* structure.
4. Run ccdGJKIntersect() function on desired objects.
Here is skeleton of simple program:
```cpp
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function for box */
void support(const void *obj, const ccd_vec3_t *dir, ccd_vec3_t *vec)
{
// assume that obj_t is user-defined structure that holds info about
// object (in this case box: x, y, z, pos, quat - dimensions of box,
// position and rotation)
obj_t *obj = (obj_t *)_obj;
ccd_vec3_t dir;
ccd_quat_t qinv;
// apply rotation on direction vector
ccdVec3Copy(&dir, _dir);
ccdQuatInvert2(&qinv, &obj->quat);
ccdQuatRotVec(&dir, &qinv);
// compute support point in specified direction
ccdVec3Set(v, ccdSign(ccdVec3X(&dir)) * box->x * CCD_REAL(0.5),
ccdSign(ccdVec3Y(&dir)) * box->y * CCD_REAL(0.5),
ccdSign(ccdVec3Z(&dir)) * box->z * CCD_REAL(0.5));
// transform support point according to position and rotation of object
ccdQuatRotVec(v, &obj->quat);
ccdVec3Add(v, &obj->pos);
}
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.max_iterations = 100; // maximal number of iterations
int intersect = ccdGJKIntersect(obj1, obj2, &ccd);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
}
```
## GJK + EPA - Penetration Of Two Objects
If you want to obtain also penetration info about two intersection objects ccdGJKPenetration() function can be used.
Procedure is almost same as for previous case:
```cpp
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.max_iterations = 100; // maximal number of iterations
ccd.epa_tolerance = 0.0001; // maximal tolerance fro EPA part
ccd_real_t depth;
ccd_vec3_t dir, pos;
int intersect = ccdGJKPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
// now intersect holds 0 if obj1 and obj2 intersect, -1 otherwise
// in depth, dir and pos is stored penetration depth, direction of
// separation vector and position in global coordinate system
}
```
## MPR - Intersection Test
libccd also provides MPR - Minkowski Portal Refinement algorithm that can be used for testing if two objects intersects.
Procedure is similar to the one used for GJK algorithm. Support function is same but also function that returns center (or any point near center) of given object must be implemented:
```cpp
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
/** Center function - returns center of object */
void center(const void *_obj, ccd_vec3_t *center)
{
obj_t *obj = (obj_t *)_obj;
ccdVec3Copy(center, &obj->pos);
}
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.center1 = center; // center function for first object
ccd.center2 = center; // center function for second object
ccd.mpr_tolerance = 0.0001; // maximal tolerance
int intersect = ccdMPRIntersect(obj1, obj2, &ccd);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
}
```
## MPR - Penetration Of Two Objects
Using MPR algorithm for obtaining penetration info about two intersection objects is equally easy as in previous case instead ccdMPRPenetration() function is used:
```cpp
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
/** Center function is same as in prevous case */
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.center1 = center; // center function for first object
ccd.center2 = center; // center function for second object
ccd.mpr_tolerance = 0.0001; // maximal tolerance
ccd_real_t depth;
ccd_vec3_t dir, pos;
int intersect = ccdMPRPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
// now intersect holds 0 if obj1 and obj2 intersect, -1 otherwise
// in depth, dir and pos is stored penetration depth, direction of
// separation vector and position in global coordinate system
}
```

7
3rdparty/libccd/bootstrap vendored Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
libtoolize -f -c
aclocal
autoheader -f
autoconf
automake -a --foreign -f -c

14
3rdparty/libccd/ccd-config.cmake.in vendored Normal file
View File

@ -0,0 +1,14 @@
@PACKAGE_INIT@
set(CCD_VERSION_MAJOR @CCD_VERSION_MAJOR@)
set(CCD_VERSION_MINOR @CCD_VERSION_MINOR@)
set(CCD_VERSION @CCD_VERSION@)
set(CCD_SOVERSION @CCD_SOVERSION@)
set(CCD_FOUND ON)
set_and_check(CCD_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(CCD_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
set(CCD_LIBRARIES ccd)
include("${CMAKE_CURRENT_LIST_DIR}/ccd-targets.cmake")

13
3rdparty/libccd/ccd.pc.in vendored Normal file
View File

@ -0,0 +1,13 @@
# Generated by CMake @CMAKE_VERSION@ for ccd
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: @PROJECT_NAME@
Description: @CCD_PKGCONFIG_DESCRIPTION@
Version: @CCD_VERSION@
Requires: @CCD_PKGCONFIG_REQUIRES@
Libs: -L${libdir} -lccd @CCD_PKGCONFIG_EXTRA_LIBS@
Cflags: -I${includedir}

50
3rdparty/libccd/configure.ac vendored Normal file
View File

@ -0,0 +1,50 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
#AC_PREREQ([2.65])
AC_INIT([libccd], [2.0], [danfis@danfis.cz])
AC_CONFIG_SRCDIR([src/ccd.c])
AC_CONFIG_HEADERS([src/ccd/config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_INSTALL
AC_DISABLE_SHARED
LT_INIT
# Checks for libraries.
AC_CHECK_LIB([m], [main])
# FIXME: Replace `main' with a function in `-lrt':
AC_CHECK_LIB([rt], [main])
# Checks for header files.
AC_CHECK_HEADERS([float.h stdlib.h string.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_REALLOC
AC_CHECK_FUNCS([clock_gettime])
use_double=no
AC_ARG_ENABLE(double-precision,
AS_HELP_STRING([--enable-double-precision],
[enable double precision computations instead of single precision]),
[use_double=yes])
if test $use_double = no
then
AC_DEFINE([CCD_SINGLE], [], [use single precision])
else
AC_DEFINE([CCD_DOUBLE], [], [use double precision])
fi
AC_CONFIG_FILES([Makefile
src/Makefile
src/testsuites/Makefile
src/testsuites/cu/Makefile])
AC_OUTPUT

39
3rdparty/libccd/doc/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,39 @@
find_program(SPHINX_EXECUTABLE NAMES sphinx-build sphinx-build2)
if(NOT SPHINX_EXECUTABLE)
message(FATAL_ERROR "Could NOT find required executable sphinx-build")
endif()
add_custom_target(doc ALL)
set(CCD_DOCTREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/.doctrees")
set(CCD_HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
add_custom_target(html COMMAND
"${SPHINX_EXECUTABLE}" -b html -d "${CCD_DOCTREE_DIR}" -q
"${CMAKE_CURRENT_SOURCE_DIR}" "${CCD_HTML_OUTPUT_DIR}")
add_dependencies(doc html)
install(DIRECTORY "${CCD_HTML_OUTPUT_DIR}"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/ccd")
set(CCD_DOC_ADDITIONAL_MAKE_CLEAN_FILES
"${CCD_DOCTREE_DIR}"
"${CCD_HTML_OUTPUT_DIR}")
if(NOT WIN32)
set(CCD_MAN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/man")
add_custom_target(man COMMAND
"${SPHINX_EXECUTABLE}" -b man -d "${CCD_DOCTREE_DIR}" -q
"${CMAKE_CURRENT_SOURCE_DIR}" "${CCD_MAN_OUTPUT_DIR}")
add_dependencies(doc man)
install(DIRECTORY "${CCD_MAN_OUTPUT_DIR}/"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
list(APPEND CCD_DOC_ADDITIONAL_MAKE_CLEAN_FILES "${CCD_MAN_OUTPUT_DIR}")
endif()
set_directory_properties(PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES ${CCD_DOC_ADDITIONAL_MAKE_CLEAN_FILES})

225
3rdparty/libccd/doc/Makefile vendored Normal file
View File

@ -0,0 +1,225 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " applehelp to make an Apple Help Book"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " epub3 to make an epub3"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " coverage to run coverage check of the documentation (if enabled)"
@echo " dummy to check syntax errors of document sources"
.PHONY: clean
clean:
rm -rf $(BUILDDIR)/*
.PHONY: html
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
.PHONY: dirhtml
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
.PHONY: singlehtml
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
.PHONY: pickle
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
.PHONY: json
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
.PHONY: htmlhelp
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
.PHONY: qthelp
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/libccd.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/libccd.qhc"
.PHONY: applehelp
applehelp:
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
@echo
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
@echo "N.B. You won't be able to view it unless you put it in" \
"~/Library/Documentation/Help or install it in your application" \
"bundle."
.PHONY: devhelp
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/libccd"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/libccd"
@echo "# devhelp"
.PHONY: epub
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
.PHONY: epub3
epub3:
$(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3
@echo
@echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3."
.PHONY: latex
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
.PHONY: latexpdf
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
.PHONY: latexpdfja
latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
.PHONY: text
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
.PHONY: man
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
.PHONY: texinfo
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
.PHONY: info
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
.PHONY: gettext
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
.PHONY: changes
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
.PHONY: linkcheck
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
.PHONY: doctest
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
.PHONY: coverage
coverage:
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
@echo "Testing of coverage in the sources finished, look at the " \
"results in $(BUILDDIR)/coverage/python.txt."
.PHONY: xml
xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
.PHONY: pseudoxml
pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
.PHONY: dummy
dummy:
$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
@echo
@echo "Build finished. Dummy builder generates no files."

0
3rdparty/libccd/doc/_build/.dir vendored Normal file
View File

0
3rdparty/libccd/doc/_static/.dir vendored Normal file
View File

0
3rdparty/libccd/doc/_templates/.dir vendored Normal file
View File

View File

@ -0,0 +1,122 @@
Compile And Install
====================
libccd contains several mechanisms for compiling and installing.
Using a simple Makefile, using autotools, and using CMake.
1. Using Makefile
------------------
Directory ``src/`` contains Makefile that should contain everything needed for compilation and installation:
.. code-block:: bash
$ cd src/
$ make
$ make install
Library libccd is by default compiled in double precision of floating point
numbers - you can change this by options ``USE_SINGLE``/``USE_DOUBLE``, i.e.:
.. code-block:: bash
$ make USE_SINGLE=yes
will compile library in single precision.
Installation directory can be changed by options ``PREFIX``, ``INCLUDEDIR``
and ``LIBDIR``.
For more info type '``make help``'.
2. Using Autotools
-------------------
libccd also contains support for autotools:
Generate configure script etc.:
.. code-block:: bash
$ ./bootstrap
Create new ``build/`` directory:
.. code-block:: bash
$ mkdir build && cd build
Run configure script:
.. code-block:: bash
$ ../configure
Run make and make install:
.. code-block:: bash
$ make && make install
configure script can change the way libccd is compiled and installed, most
significant option is ``--enable-double-precision`` which enables double
precision (single is default in this case).
3. Using CMake
---------------
To build using ``make``:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" ..
$ make && make install
To build using ``ninja``:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G Ninja ..
$ ninja && ninja install
Other build tools may be using by specifying a different generator. For example:
.. code-block:: bash
$ cmake -G Xcode ..
.. code-block:: batch
> cmake -G "Visual Studio 14 2015" ..
To compile using double precision, set the ``ENABLE_DOUBLE_PRECISION`` option:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DENABLE_DOUBLE_PRECISION=ON ..
$ make && make install
To build libccd as a shared library, set the ``BUILD_SHARED_LIBS`` option:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON ..
$ make && make install
To build the test suite, set the ``BUILD_TESTING`` option:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DBUILD_TESTING=ON ..
$ make && make test
The installation directory may be changed by specifying the ``CMAKE_INSTALL_PREFIX`` variable:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/install ..
$ make && make install

338
3rdparty/libccd/doc/conf.py vendored Normal file
View File

@ -0,0 +1,338 @@
# -*- coding: utf-8 -*-
#
# libccd documentation build configuration file, created by
# sphinx-quickstart on Fri Sep 9 14:53:37 2016.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.mathjax']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The encoding of source files.
#
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'libccd'
copyright = u'2013, Daniel Fiser <danfis@danfis.cz>'
author = u'Daniel Fiser'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'2.0'
# The full version, including alpha/beta/rc tags.
release = u'2.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#
# today = ''
#
# Else, today_fmt is used as the format for a strftime call.
#
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# The reST default role (used for this markup: `text`) to use for all
# documents.
#
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
# keep_warnings = False
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
#
# html_title = u'libccd Documentation'
# A shorter title for the navigation bar. Default is the same as html_title.
#
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#
# html_logo = None
# The name of an image file (relative to this directory) to use as a favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#
# html_extra_path = []
# If not None, a 'Last updated on:' timestamp is inserted at every page
# bottom, using the given strftime format.
# The empty string is equivalent to '%b %d, %Y'.
#
# html_last_updated_fmt = None
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#
# html_additional_pages = {}
# If false, no module index is generated.
#
# html_domain_indices = True
# If false, no index is generated.
#
# html_use_index = True
# If true, the index is split into individual pages for each letter.
#
# html_split_index = False
# If true, links to the reST sources are added to the pages.
#
# html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#
# html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#
# html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = None
# Language to be used for generating the HTML full-text search index.
# Sphinx supports the following languages:
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh'
#
# html_search_language = 'en'
# A dictionary with options for the search language support, empty by default.
# 'ja' uses this config value.
# 'zh' user can custom change `jieba` dictionary path.
#
# html_search_options = {'type': 'default'}
# The name of a javascript file (relative to the configuration directory) that
# implements a search results scorer. If empty, the default will be used.
#
# html_search_scorer = 'scorer.js'
# Output file base name for HTML help builder.
htmlhelp_basename = 'libccddoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'libccd.tex', u'libccd Documentation',
author, 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#
# latex_use_parts = False
# If true, show page references after internal links.
#
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
#
# latex_show_urls = False
# Documents to append as an appendix to all manuals.
#
# latex_appendices = []
# It false, will not define \strong, \code, itleref, \crossref ... but only
# \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added
# packages.
#
# latex_keep_old_macro_names = True
# If false, no module index is generated.
#
# latex_domain_indices = True
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'libccd', u'libccd Documentation',
[author], 1)
]
# If true, show URL addresses after external links.
#
# man_show_urls = False
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'libccd', u'libccd Documentation',
author, 'libccd', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#
# texinfo_appendices = []
# If false, no module index is generated.
#
# texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#
# texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#
# texinfo_no_detailmenu = False

185
3rdparty/libccd/doc/examples.rst vendored Normal file
View File

@ -0,0 +1,185 @@
Example of Usage
=================
1. GJK - Intersection Test
---------------------------
This section describes how to use **libccd** for testing if two convex objects intersects (i.e., 'yes/no' test) using Gilbert-Johnson-Keerthi (GJK) algorithm.
Procedure is very simple (and similar to the usage of the rest of the
library):
#. Include ``<ccd/ccd.h>`` file.
#. Implement support function for specific shapes. Support function is
function that returns furthest point from object (shape) in specified
direction.
#. Set up ``ccd_t`` structure.
#. Run ``ccdGJKIntersect()`` function on desired objects.
Here is a skeleton of simple program:
.. code-block:: c
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function for box */
void support(const void *obj, const ccd_vec3_t *dir,
ccd_vec3_t *vec)
{
// assume that obj_t is user-defined structure that holds info about
// object (in this case box: x, y, z, pos, quat - dimensions of box,
// position and rotation)
obj_t *obj = (obj_t *)_obj;
ccd_vec3_t dir;
ccd_quat_t qinv;
// apply rotation on direction vector
ccdVec3Copy(&dir, _dir);
ccdQuatInvert2(&qinv, &obj->quat);
ccdQuatRotVec(&dir, &qinv);
// compute support point in specified direction
ccdVec3Set(v, ccdSign(ccdVec3X(&dir)) * box->x * CCD_REAL(0.5),
ccdSign(ccdVec3Y(&dir)) * box->y * CCD_REAL(0.5),
ccdSign(ccdVec3Z(&dir)) * box->z * CCD_REAL(0.5));
// transform support point according to position and rotation of object
ccdQuatRotVec(v, &obj->quat);
ccdVec3Add(v, &obj->pos);
}
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.max_iterations = 100; // maximal number of iterations
int intersect = ccdGJKIntersect(obj1, obj2, &ccd);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
}
2. GJK + EPA - Penetration Of Two Objects
------------------------------------------
If you want to obtain also penetration info about two intersection objects
``ccdGJKPenetration()`` function can be used.
Procedure is almost the same as for the previous case:
.. code-block:: c
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.max_iterations = 100; // maximal number of iterations
ccd.epa_tolerance = 0.0001; // maximal tolerance fro EPA part
ccd_real_t depth;
ccd_vec3_t dir, pos;
int intersect = ccdGJKPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
// in depth, dir and pos is stored penetration depth, direction of
// separation vector and position in global coordinate system
}
3. MPR - Intersection Test
---------------------------
**libccd** also provides *MPR* - Minkowski Portal Refinement algorithm that
can be used for testing if two objects intersects.
Procedure is similar to the one used for GJK algorithm. Support function is
the same but also function that returns a center (or any point near center)
of a given object must be implemented:
.. code-block:: c
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
/** Center function - returns center of object */
void center(const void *_obj, ccd_vec3_t *center)
{
obj_t *obj = (obj_t *)_obj;
ccdVec3Copy(center, &obj->pos);
}
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.center1 = center; // center function for first object
ccd.center2 = center; // center function for second object
ccd.mpr_tolerance = 0.0001; // maximal tolerance
int intersect = ccdMPRIntersect(obj1, obj2, &ccd);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
}
4. MPR - Penetration Of Two Objects
------------------------------------
Using MPR algorithm for obtaining penetration info about two intersection
objects is equally easy as in the previous case instead but
``ccdMPRPenetration()`` function is used:
.. code-block:: c
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
/** Center function is same as in prevous case */
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.center1 = center; // center function for first object
ccd.center2 = center; // center function for second object
ccd.mpr_tolerance = 0.0001; // maximal tolerance
ccd_real_t depth;
ccd_vec3_t dir, pos;
int intersect = ccdMPRPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
// in depth, dir and pos is stored penetration depth, direction of
// separation vector and position in global coordinate system
}

25
3rdparty/libccd/doc/index.rst vendored Normal file
View File

@ -0,0 +1,25 @@
.. libccd documentation master file, created by
sphinx-quickstart2 on Thu May 23 13:49:12 2013.
libccd's documentation
=======================
See homepage: http://libccd.danfis.cz
Contents:
.. toctree::
:maxdepth: 2
compile-and-install.rst
examples.rst
reference.rst
.. Indices and tables
.. ==================
.. * :ref:`genindex`
.. * :ref:`modindex`
.. * :ref:`search`

6
3rdparty/libccd/doc/reference.rst vendored Normal file
View File

@ -0,0 +1,6 @@
Reference
==========
.. literalinclude:: ../src/ccd/ccd.h
:language: c
:linenos:

31
3rdparty/libccd/make-release.sh vendored Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
# Creates .tar.gz package of specified version.
# Takes one argument - identification of commit
NAME=libccd
COMMIT=""
CMD="git archive"
# read arguments
COMMIT="$1"
if [ "$COMMIT" = "" ]; then
echo "Usage: $0 commit [--notest] [--nodoc]"
echo "Error: you must specify commit which should be packed"
exit -1;
fi;
PREFIX=${NAME}-$COMMIT/
FN=${NAME}-$COMMIT.tar.gz
if echo "$COMMIT" | grep '^v[0-9]\.[0-9]\+' >/dev/null 2>&1; then
tmp=$(echo "$COMMIT" | sed 's/^v//')
PREFIX=${NAME}-$tmp/
FN=${NAME}-$tmp.tar.gz
fi
$CMD --prefix="$PREFIX" --format=tar $COMMIT | gzip >"$FN"
echo "Package: $FN"

5
3rdparty/libccd/src/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.o
*.a
ccd/config.h
ccd/config.h.in

88
3rdparty/libccd/src/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,88 @@
if(DEFINED CCD_SINGLE OR DEFINED CCD_DOUBLE)
# make sure only DOUBLE or SINGLE is set; default to SINGLE
if(CCD_SINGLE)
set(CCD_DOUBLE OFF)
else()
set(CCD_SINGLE ON)
endif()
if(CCD_DOUBLE)
set(CCD_SINGLE OFF)
endif()
elseif(ENABLE_DOUBLE_PRECISION)
set(CCD_DOUBLE ON)
set(CCD_SINGLE OFF)
else()
set(CCD_DOUBLE OFF)
set(CCD_SINGLE ON)
endif()
configure_file(ccd/config.h.cmake.in ccd/config.h)
set(CCD_INCLUDES
ccd/ccd.h
ccd/compiler.h
ccd/ccd_export.h
ccd/quat.h
ccd/vec3.h
"${CMAKE_CURRENT_BINARY_DIR}/ccd/config.h")
set(CCD_SOURCES
alloc.h
ccd.c
dbg.h
list.h
mpr.c
polytope.c
polytope.h
simplex.h
support.c
support.h
vec3.c)
add_library(ccd ${CCD_INCLUDES} ${CCD_SOURCES})
set_target_properties(ccd PROPERTIES
PUBLIC_HEADER "${CCD_INCLUDES}"
SOVERSION ${CCD_SOVERSION}
VERSION ${CCD_VERSION})
target_include_directories(ccd PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
if(NOT WIN32)
find_library(LIBM_LIBRARY NAMES m)
if(NOT LIBM_LIBRARY)
message(FATAL_ERROR "Could NOT find required library LibM")
endif()
target_link_libraries(ccd "${LIBM_LIBRARY}")
if(BUILD_SHARED_LIBS)
set(CCD_PKGCONFIG_EXTRA_LIBS -lm PARENT_SCOPE)
endif()
endif()
export(TARGETS ccd FILE "${CMAKE_BINARY_DIR}/ccd-targets.cmake")
install(TARGETS ccd
EXPORT ccd-targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ccd"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(EXPORT ccd-targets DESTINATION "${CMAKE_INSTALL_LIBDIR}/ccd")
macro (check_compiler_visibility)
include (CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fvisibility=hidden COMPILER_SUPPORTS_VISIBILITY)
endmacro()
if(UNIX)
check_compiler_visibility()
if (COMPILER_SUPPORTS_VISIBILITY)
set_target_properties(ccd
PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
endif()
endif()
if(NOT WIN32 AND BUILD_TESTING AND NOT CCD_HIDE_ALL_SYMBOLS)
add_subdirectory(testsuites)
endif()

80
3rdparty/libccd/src/Makefile vendored Normal file
View File

@ -0,0 +1,80 @@
###
# libccd
# ---------------------------------
# Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
#
#
# This file is part of libccd.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file BDS-LICENSE for details or see
# <http://www.opensource.org/licenses/bsd-license.php>.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
##
-include Makefile.include
CFLAGS += -I. -fvisibility=hidden
TARGETS = libccd.a
OBJS = ccd.o mpr.o support.o vec3.o polytope.o
all: $(TARGETS)
libccd.a: $(OBJS)
ar cr $@ $(OBJS)
ranlib $@
ccd/config.h: ccd/config.h.m4
$(M4) $(CONFIG_FLAGS) $< >$@
%.o: %.c %.h ccd/config.h
$(CC) $(CFLAGS) $(DEFS) -c -o $@ $<
%.o: %.c ccd/config.h
$(CC) $(CFLAGS) $(DEFS) -c -o $@ $<
%.h: ccd/config.h
%.c: ccd/config.h
install:
mkdir -p $(PREFIX)/$(INCLUDEDIR)/ccd
mkdir -p $(PREFIX)/$(LIBDIR)
cp ccd/*.h $(PREFIX)/$(INCLUDEDIR)/ccd/
cp libccd.a $(PREFIX)/$(LIBDIR)
clean:
rm -f $(OBJS)
rm -f $(TARGETS)
rm -f ccd/config.h
if [ -d testsuites ]; then $(MAKE) -C testsuites clean; fi;
check:
$(MAKE) -C testsuites check
check-valgrind:
$(MAKE) -C testsuites check-valgrind
help:
@echo "Targets:"
@echo " all - Build library"
@echo " install - Install library into system"
@echo ""
@echo "Options:"
@echo " CC - Path to C compiler"
@echo " M4 - Path to m4 macro processor"
@echo ""
@echo " DEBUG 'yes'/'no' - Turn on/off debugging (default: 'no')"
@echo " PROFIL 'yes'/'no' - Compiles profiling info (default: 'no')"
@echo " NOWALL 'yes'/'no' - Turns off -Wall gcc option (default: 'no')"
@echo " NOPEDANTIC 'yes'/'no' - Turns off -pedantic gcc option (default: 'no')"
@echo ""
@echo " USE_SINGLE 'yes' - Use single precision (default: 'no')"
@echo " USE_DOUBLE 'yes' - Use double precision (default: 'yes')"
@echo ""
@echo " PREFIX - Prefix where library will be installed (default: /usr/local)"
@echo " INCLUDEDIR - Directory where header files will be installed (PREFIX/INCLUDEDIR) (default: include)"
@echo " LIBDIR - Directory where library will be installed (PREFIX/LIBDIR) (default: lib)"
@echo ""
.PHONY: all clean check check-valgrind help

18
3rdparty/libccd/src/Makefile.am vendored Normal file
View File

@ -0,0 +1,18 @@
SUBDIRS = . testsuites
lib_LTLIBRARIES = libccd.la
libccd_la_SOURCES = alloc.h \
ccd/compiler.h \
dbg.h \
ccd.c ccd/ccd.h \
ccd/ccd_export.h \
list.h \
polytope.c polytope.h \
ccd/quat.h \
simplex.h \
support.c support.h \
vec3.c ccd/vec3.h \
mpr.c
libccd_la_CFLAGS = -fvisibility=hidden

100
3rdparty/libccd/src/Makefile.include vendored Normal file
View File

@ -0,0 +1,100 @@
###
# libccd
# ---------------------------------
# Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
#
#
# This file is part of libccd.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file BDS-LICENSE for details or see
# <http://www.opensource.org/licenses/bsd-license.php>.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
##
CC ?= gcc
M4 ?= m4
PYTHON ?= python
SYSTEM = $(shell uname)
SYSTEM_CXXFLAGS =
SYSTEM_LDFLAGS =
ifeq '$(SYSTEM)' 'FreeBSD'
SYSTEM_CXXFLAGS = -Wno-long-long
else
endif
NOWALL ?= no
NOPEDANTIC ?= no
DEBUG ?= no
PROFIL ?= no
ifeq '$(PROFIL)' 'yes'
DEBUG = yes
endif
ifeq '$(DEBUG)' 'yes'
CFLAGS = -g
endif
ifeq '$(PROFIL)' 'yes'
CFLAGS += -pg
endif
ifneq '$(NOWALL)' 'yes'
CFLAGS += -Wall
endif
ifneq '$(NOPEDANTIC)' 'yes'
CFLAGS += -pedantic
endif
CONFIG_FLAGS =
USE_DOUBLE ?= yes
USE_SINGLE ?= no
ifeq '$(USE_SINGLE)' 'yes'
CONFIG_FLAGS += -DUSE_SINGLE
USE_DOUBLE = no
endif
ifeq '$(USE_DOUBLE)' 'yes'
CONFIG_FLAGS += -DUSE_DOUBLE
endif
CFLAGS += --std=gnu99
LDFLAGS += $(SYSTEM_LDFLAGS)
CHECKTARGETS =
check-dep: $(CHECKTARGETS)
PREFIX ?= /usr/local
INCLUDEDIR ?= include
LIBDIR ?= lib
showvars:
@echo "SYSTEM = "$(SYSTEM)
@echo ""
@echo "CC = $(CC)"
@echo "M4 = $(M4)"
@echo ""
@echo "DEBUG = $(DEBUG)"
@echo "PROFIL = $(PROFIL)"
@echo "NOWALL = $(NOWALL)"
@echo "NOPEDANTIC = $(NOPEDANTIC)"
@echo "USE_SINGLE = $(USE_SINGLE)"
@echo "USE_DOUBLE = $(USE_DOUBLE)"
@echo ""
@echo "CFLAGS = $(CFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)"
@echo "CONFIG_FLAGS = $(CONFIG_FLAGS)"
@echo ""
@echo "PREFIX = $(PREFIX)"
@echo "INCLUDEDIR = $(INCLUDEDIR)"
@echo "LIBDIR = $(LIBDIR)"
@echo ""
.DEFAULT_GOAL := all
.PHONY: showvars

50
3rdparty/libccd/src/alloc.h vendored Normal file
View File

@ -0,0 +1,50 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_ALLOC_H__
#define __CCD_ALLOC_H__
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Functions and macros required for memory allocation.
*/
/* Memory allocation: */
#define __CCD_ALLOC_MEMORY(type, ptr_old, size) \
(type *)realloc((void *)ptr_old, (size))
/** Allocate memory for one element of type. */
#define CCD_ALLOC(type) \
__CCD_ALLOC_MEMORY(type, NULL, sizeof(type))
/** Allocate memory for array of elements of type type. */
#define CCD_ALLOC_ARR(type, num_elements) \
__CCD_ALLOC_MEMORY(type, NULL, sizeof(type) * (num_elements))
#define CCD_REALLOC_ARR(ptr, type, num_elements) \
__CCD_ALLOC_MEMORY(type, ptr, sizeof(type) * (num_elements))
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_ALLOC_H__ */

996
3rdparty/libccd/src/ccd.c vendored Normal file
View File

@ -0,0 +1,996 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2012 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#include <stdio.h>
#include <float.h>
#include <ccd/ccd.h>
#include <ccd/vec3.h>
#include "simplex.h"
#include "polytope.h"
#include "alloc.h"
#include "dbg.h"
/** Performs GJK algorithm. Returns 0 if intersection was found and simplex
* is filled with resulting polytope. */
static int __ccdGJK(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *simplex);
/** Performs GJK+EPA algorithm. Returns 0 if intersection was found and
* pt is filled with resulting polytope and nearest with pointer to
* nearest element (vertex, edge, face) of polytope to origin. */
static int __ccdGJKEPA(const void *obj1, const void *obj2,
const ccd_t *ccd,
ccd_pt_t *pt, ccd_pt_el_t **nearest);
/** Returns true if simplex contains origin.
* This function also alteres simplex and dir according to further
* processing of GJK algorithm. */
static int doSimplex(ccd_simplex_t *simplex, ccd_vec3_t *dir);
static int doSimplex2(ccd_simplex_t *simplex, ccd_vec3_t *dir);
static int doSimplex3(ccd_simplex_t *simplex, ccd_vec3_t *dir);
static int doSimplex4(ccd_simplex_t *simplex, ccd_vec3_t *dir);
/** d = a x b x c */
_ccd_inline void tripleCross(const ccd_vec3_t *a, const ccd_vec3_t *b,
const ccd_vec3_t *c, ccd_vec3_t *d);
/** Transforms simplex to polytope. It is assumed that simplex has 4
* vertices. */
static int simplexToPolytope4(const void *obj1, const void *obj2,
const ccd_t *ccd,
ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest);
/** Transforms simplex to polytope, three vertices required */
static int simplexToPolytope3(const void *obj1, const void *obj2,
const ccd_t *ccd,
const ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest);
/** Transforms simplex to polytope, two vertices required */
static int simplexToPolytope2(const void *obj1, const void *obj2,
const ccd_t *ccd,
const ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest);
/** Expands polytope using new vertex v.
* Return 0 on success, -2 on memory allocation failure.*/
static int expandPolytope(ccd_pt_t *pt, ccd_pt_el_t *el,
const ccd_support_t *newv);
/** Finds next support point (at stores it in out argument).
* Returns 0 on success, -1 otherwise */
static int nextSupport(const void *obj1, const void *obj2, const ccd_t *ccd,
const ccd_pt_el_t *el,
ccd_support_t *out);
void ccdFirstDirDefault(const void *o1, const void *o2, ccd_vec3_t *dir)
{
ccdVec3Set(dir, CCD_ONE, CCD_ZERO, CCD_ZERO);
}
int ccdGJKIntersect(const void *obj1, const void *obj2, const ccd_t *ccd)
{
ccd_simplex_t simplex;
return __ccdGJK(obj1, obj2, ccd, &simplex) == 0;
}
int ccdGJKSeparate(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_vec3_t *sep)
{
ccd_pt_t polytope;
ccd_pt_el_t *nearest;
int ret;
ccdPtInit(&polytope);
ret = __ccdGJKEPA(obj1, obj2, ccd, &polytope, &nearest);
// set separation vector
if (nearest)
ccdVec3Copy(sep, &nearest->witness);
ccdPtDestroy(&polytope);
return ret;
}
static int penEPAPosCmp(const void *a, const void *b)
{
ccd_pt_vertex_t *v1, *v2;
v1 = *(ccd_pt_vertex_t **)a;
v2 = *(ccd_pt_vertex_t **)b;
if (ccdEq(v1->dist, v2->dist)){
return 0;
}else if (v1->dist < v2->dist){
return -1;
}else{
return 1;
}
}
static int penEPAPos(const ccd_pt_t *pt, const ccd_pt_el_t *nearest,
ccd_vec3_t *pos)
{
ccd_pt_vertex_t *v;
ccd_pt_vertex_t **vs;
size_t i, len;
ccd_real_t scale;
// compute median
len = 0;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
len++;
}
vs = CCD_ALLOC_ARR(ccd_pt_vertex_t *, len);
if (vs == NULL)
return -1;
i = 0;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
vs[i++] = v;
}
qsort(vs, len, sizeof(ccd_pt_vertex_t *), penEPAPosCmp);
ccdVec3Set(pos, CCD_ZERO, CCD_ZERO, CCD_ZERO);
scale = CCD_ZERO;
if (len % 2 == 1)
len++;
for (i = 0; i < len / 2; i++){
ccdVec3Add(pos, &vs[i]->v.v1);
ccdVec3Add(pos, &vs[i]->v.v2);
scale += CCD_REAL(2.);
}
ccdVec3Scale(pos, CCD_ONE / scale);
free(vs);
return 0;
}
int ccdGJKPenetration(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos)
{
ccd_pt_t polytope;
ccd_pt_el_t *nearest;
int ret;
ccdPtInit(&polytope);
ret = __ccdGJKEPA(obj1, obj2, ccd, &polytope, &nearest);
// set separation vector
if (ret == 0 && nearest){
// compute depth of penetration
*depth = CCD_SQRT(nearest->dist);
// store normalized direction vector
ccdVec3Copy(dir, &nearest->witness);
ccdVec3Normalize(dir);
// compute position
if (penEPAPos(&polytope, nearest, pos) != 0){
ccdPtDestroy(&polytope);
return -2;
}
}
ccdPtDestroy(&polytope);
return ret;
}
static int __ccdGJK(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *simplex)
{
unsigned long iterations;
ccd_vec3_t dir; // direction vector
ccd_support_t last; // last support point
int do_simplex_res;
// initialize simplex struct
ccdSimplexInit(simplex);
// get first direction
ccd->first_dir(obj1, obj2, &dir);
// get first support point
__ccdSupport(obj1, obj2, &dir, ccd, &last);
// and add this point to simplex as last one
ccdSimplexAdd(simplex, &last);
// set up direction vector to as (O - last) which is exactly -last
ccdVec3Copy(&dir, &last.v);
ccdVec3Scale(&dir, -CCD_ONE);
// start iterations
for (iterations = 0UL; iterations < ccd->max_iterations; ++iterations) {
// obtain support point
__ccdSupport(obj1, obj2, &dir, ccd, &last);
// check if farthest point in Minkowski difference in direction dir
// isn't somewhere before origin (the test on negative dot product)
// - because if it is, objects are not intersecting at all.
if (ccdVec3Dot(&last.v, &dir) < CCD_ZERO){
return -1; // intersection not found
}
// add last support vector to simplex
ccdSimplexAdd(simplex, &last);
// if doSimplex returns 1 if objects intersect, -1 if objects don't
// intersect and 0 if algorithm should continue
do_simplex_res = doSimplex(simplex, &dir);
if (do_simplex_res == 1){
return 0; // intersection found
}else if (do_simplex_res == -1){
return -1; // intersection not found
}
if (ccdIsZero(ccdVec3Len2(&dir))){
return -1; // intersection not found
}
}
// intersection wasn't found
return -1;
}
static int __ccdGJKEPA(const void *obj1, const void *obj2,
const ccd_t *ccd,
ccd_pt_t *polytope, ccd_pt_el_t **nearest)
{
ccd_simplex_t simplex;
ccd_support_t supp; // support point
int ret, size;
*nearest = NULL;
// run GJK and obtain terminal simplex
ret = __ccdGJK(obj1, obj2, ccd, &simplex);
if (ret != 0)
return -1;
// transform simplex to polytope - simplex won't be used anymore
size = ccdSimplexSize(&simplex);
if (size == 4){
ret = simplexToPolytope4(obj1, obj2, ccd, &simplex, polytope, nearest);
}else if (size == 3){
ret = simplexToPolytope3(obj1, obj2, ccd, &simplex, polytope, nearest);
}else{ // size == 2
ret = simplexToPolytope2(obj1, obj2, ccd, &simplex, polytope, nearest);
}
if (ret == -1){
// touching contact
return 0;
}else if (ret == -2){
// failed memory allocation
return -2;
}
while (1){
// get triangle nearest to origin
*nearest = ccdPtNearest(polytope);
// get next support point
if (nextSupport(obj1, obj2, ccd, *nearest, &supp) != 0)
break;
// expand nearest triangle using new point - supp
if (expandPolytope(polytope, *nearest, &supp) != 0)
return -2;
}
return 0;
}
static int doSimplex2(ccd_simplex_t *simplex, ccd_vec3_t *dir)
{
const ccd_support_t *A, *B;
ccd_vec3_t AB, AO, tmp;
ccd_real_t dot;
// get last added as A
A = ccdSimplexLast(simplex);
// get the other point
B = ccdSimplexPoint(simplex, 0);
// compute AB oriented segment
ccdVec3Sub2(&AB, &B->v, &A->v);
// compute AO vector
ccdVec3Copy(&AO, &A->v);
ccdVec3Scale(&AO, -CCD_ONE);
// dot product AB . AO
dot = ccdVec3Dot(&AB, &AO);
// check if origin doesn't lie on AB segment
ccdVec3Cross(&tmp, &AB, &AO);
if (ccdIsZero(ccdVec3Len2(&tmp)) && dot > CCD_ZERO){
return 1;
}
// check if origin is in area where AB segment is
if (ccdIsZero(dot) || dot < CCD_ZERO){
// origin is in outside are of A
ccdSimplexSet(simplex, 0, A);
ccdSimplexSetSize(simplex, 1);
ccdVec3Copy(dir, &AO);
}else{
// origin is in area where AB segment is
// keep simplex untouched and set direction to
// AB x AO x AB
tripleCross(&AB, &AO, &AB, dir);
}
return 0;
}
static int doSimplex3(ccd_simplex_t *simplex, ccd_vec3_t *dir)
{
const ccd_support_t *A, *B, *C;
ccd_vec3_t AO, AB, AC, ABC, tmp;
ccd_real_t dot, dist;
// get last added as A
A = ccdSimplexLast(simplex);
// get the other points
B = ccdSimplexPoint(simplex, 1);
C = ccdSimplexPoint(simplex, 0);
// check touching contact
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &A->v, &B->v, &C->v, NULL);
if (ccdIsZero(dist)){
return 1;
}
// check if triangle is really triangle (has area > 0)
// if not simplex can't be expanded and thus no itersection is found
if (ccdVec3Eq(&A->v, &B->v) || ccdVec3Eq(&A->v, &C->v)){
return -1;
}
// compute AO vector
ccdVec3Copy(&AO, &A->v);
ccdVec3Scale(&AO, -CCD_ONE);
// compute AB and AC segments and ABC vector (perpendircular to triangle)
ccdVec3Sub2(&AB, &B->v, &A->v);
ccdVec3Sub2(&AC, &C->v, &A->v);
ccdVec3Cross(&ABC, &AB, &AC);
ccdVec3Cross(&tmp, &ABC, &AC);
dot = ccdVec3Dot(&tmp, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
dot = ccdVec3Dot(&AC, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
// C is already in place
ccdSimplexSet(simplex, 1, A);
ccdSimplexSetSize(simplex, 2);
tripleCross(&AC, &AO, &AC, dir);
}else{
ccd_do_simplex3_45:
dot = ccdVec3Dot(&AB, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
ccdSimplexSet(simplex, 0, B);
ccdSimplexSet(simplex, 1, A);
ccdSimplexSetSize(simplex, 2);
tripleCross(&AB, &AO, &AB, dir);
}else{
ccdSimplexSet(simplex, 0, A);
ccdSimplexSetSize(simplex, 1);
ccdVec3Copy(dir, &AO);
}
}
}else{
ccdVec3Cross(&tmp, &AB, &ABC);
dot = ccdVec3Dot(&tmp, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
goto ccd_do_simplex3_45;
}else{
dot = ccdVec3Dot(&ABC, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
ccdVec3Copy(dir, &ABC);
}else{
ccd_support_t Ctmp;
ccdSupportCopy(&Ctmp, C);
ccdSimplexSet(simplex, 0, B);
ccdSimplexSet(simplex, 1, &Ctmp);
ccdVec3Copy(dir, &ABC);
ccdVec3Scale(dir, -CCD_ONE);
}
}
}
return 0;
}
static int doSimplex4(ccd_simplex_t *simplex, ccd_vec3_t *dir)
{
const ccd_support_t *A, *B, *C, *D;
ccd_vec3_t AO, AB, AC, AD, ABC, ACD, ADB;
int B_on_ACD, C_on_ADB, D_on_ABC;
int AB_O, AC_O, AD_O;
ccd_real_t dist;
// get last added as A
A = ccdSimplexLast(simplex);
// get the other points
B = ccdSimplexPoint(simplex, 2);
C = ccdSimplexPoint(simplex, 1);
D = ccdSimplexPoint(simplex, 0);
// check if tetrahedron is really tetrahedron (has volume > 0)
// if it is not simplex can't be expanded and thus no intersection is
// found
dist = ccdVec3PointTriDist2(&A->v, &B->v, &C->v, &D->v, NULL);
if (ccdIsZero(dist)){
return -1;
}
// check if origin lies on some of tetrahedron's face - if so objects
// intersect
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &A->v, &B->v, &C->v, NULL);
if (ccdIsZero(dist))
return 1;
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &A->v, &C->v, &D->v, NULL);
if (ccdIsZero(dist))
return 1;
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &A->v, &B->v, &D->v, NULL);
if (ccdIsZero(dist))
return 1;
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &B->v, &C->v, &D->v, NULL);
if (ccdIsZero(dist))
return 1;
// compute AO, AB, AC, AD segments and ABC, ACD, ADB normal vectors
ccdVec3Copy(&AO, &A->v);
ccdVec3Scale(&AO, -CCD_ONE);
ccdVec3Sub2(&AB, &B->v, &A->v);
ccdVec3Sub2(&AC, &C->v, &A->v);
ccdVec3Sub2(&AD, &D->v, &A->v);
ccdVec3Cross(&ABC, &AB, &AC);
ccdVec3Cross(&ACD, &AC, &AD);
ccdVec3Cross(&ADB, &AD, &AB);
// side (positive or negative) of B, C, D relative to planes ACD, ADB
// and ABC respectively
B_on_ACD = ccdSign(ccdVec3Dot(&ACD, &AB));
C_on_ADB = ccdSign(ccdVec3Dot(&ADB, &AC));
D_on_ABC = ccdSign(ccdVec3Dot(&ABC, &AD));
// whether origin is on same side of ACD, ADB, ABC as B, C, D
// respectively
AB_O = ccdSign(ccdVec3Dot(&ACD, &AO)) == B_on_ACD;
AC_O = ccdSign(ccdVec3Dot(&ADB, &AO)) == C_on_ADB;
AD_O = ccdSign(ccdVec3Dot(&ABC, &AO)) == D_on_ABC;
if (AB_O && AC_O && AD_O){
// origin is in tetrahedron
return 1;
// rearrange simplex to triangle and call doSimplex3()
}else if (!AB_O){
// B is farthest from the origin among all of the tetrahedron's
// points, so remove it from the list and go on with the triangle
// case
// D and C are in place
ccdSimplexSet(simplex, 2, A);
ccdSimplexSetSize(simplex, 3);
}else if (!AC_O){
// C is farthest
ccdSimplexSet(simplex, 1, D);
ccdSimplexSet(simplex, 0, B);
ccdSimplexSet(simplex, 2, A);
ccdSimplexSetSize(simplex, 3);
}else{ // (!AD_O)
ccdSimplexSet(simplex, 0, C);
ccdSimplexSet(simplex, 1, B);
ccdSimplexSet(simplex, 2, A);
ccdSimplexSetSize(simplex, 3);
}
return doSimplex3(simplex, dir);
}
static int doSimplex(ccd_simplex_t *simplex, ccd_vec3_t *dir)
{
if (ccdSimplexSize(simplex) == 2){
// simplex contains segment only one segment
return doSimplex2(simplex, dir);
}else if (ccdSimplexSize(simplex) == 3){
// simplex contains triangle
return doSimplex3(simplex, dir);
}else{ // ccdSimplexSize(simplex) == 4
// tetrahedron - this is the only shape which can encapsule origin
// so doSimplex4() also contains test on it
return doSimplex4(simplex, dir);
}
}
_ccd_inline void tripleCross(const ccd_vec3_t *a, const ccd_vec3_t *b,
const ccd_vec3_t *c, ccd_vec3_t *d)
{
ccd_vec3_t e;
ccdVec3Cross(&e, a, b);
ccdVec3Cross(d, &e, c);
}
/** Transforms simplex to polytope. It is assumed that simplex has 4
* vertices! */
static int simplexToPolytope4(const void *obj1, const void *obj2,
const ccd_t *ccd,
ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest)
{
const ccd_support_t *a, *b, *c, *d;
int use_polytope3;
ccd_real_t dist;
ccd_pt_vertex_t *v[4];
ccd_pt_edge_t *e[6];
size_t i;
a = ccdSimplexPoint(simplex, 0);
b = ccdSimplexPoint(simplex, 1);
c = ccdSimplexPoint(simplex, 2);
d = ccdSimplexPoint(simplex, 3);
// check if origin lies on some of tetrahedron's face - if so use
// simplexToPolytope3()
use_polytope3 = 0;
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &a->v, &b->v, &c->v, NULL);
if (ccdIsZero(dist)){
use_polytope3 = 1;
}
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &a->v, &c->v, &d->v, NULL);
if (ccdIsZero(dist)){
use_polytope3 = 1;
ccdSimplexSet(simplex, 1, c);
ccdSimplexSet(simplex, 2, d);
}
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &a->v, &b->v, &d->v, NULL);
if (ccdIsZero(dist)){
use_polytope3 = 1;
ccdSimplexSet(simplex, 2, d);
}
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &b->v, &c->v, &d->v, NULL);
if (ccdIsZero(dist)){
use_polytope3 = 1;
ccdSimplexSet(simplex, 0, b);
ccdSimplexSet(simplex, 1, c);
ccdSimplexSet(simplex, 2, d);
}
if (use_polytope3){
ccdSimplexSetSize(simplex, 3);
return simplexToPolytope3(obj1, obj2, ccd, simplex, pt, nearest);
}
// no touching contact - simply create tetrahedron
for (i = 0; i < 4; i++){
v[i] = ccdPtAddVertex(pt, ccdSimplexPoint(simplex, i));
}
e[0] = ccdPtAddEdge(pt, v[0], v[1]);
e[1] = ccdPtAddEdge(pt, v[1], v[2]);
e[2] = ccdPtAddEdge(pt, v[2], v[0]);
e[3] = ccdPtAddEdge(pt, v[3], v[0]);
e[4] = ccdPtAddEdge(pt, v[3], v[1]);
e[5] = ccdPtAddEdge(pt, v[3], v[2]);
// ccdPtAdd*() functions return NULL either if the memory allocation
// failed of if any of the input pointers are NULL, so the bad
// allocation can be checked by the last calls of ccdPtAddFace()
// because the rest of the bad allocations eventually "bubble up" here
if (ccdPtAddFace(pt, e[0], e[1], e[2]) == NULL
|| ccdPtAddFace(pt, e[3], e[4], e[0]) == NULL
|| ccdPtAddFace(pt, e[4], e[5], e[1]) == NULL
|| ccdPtAddFace(pt, e[5], e[3], e[2]) == NULL){
return -2;
}
return 0;
}
/** Transforms simplex to polytope, three vertices required */
static int simplexToPolytope3(const void *obj1, const void *obj2,
const ccd_t *ccd,
const ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest)
{
const ccd_support_t *a, *b, *c;
ccd_support_t d, d2;
ccd_vec3_t ab, ac, dir;
ccd_pt_vertex_t *v[5];
ccd_pt_edge_t *e[9];
ccd_real_t dist, dist2;
*nearest = NULL;
a = ccdSimplexPoint(simplex, 0);
b = ccdSimplexPoint(simplex, 1);
c = ccdSimplexPoint(simplex, 2);
// If only one triangle left from previous GJK run origin lies on this
// triangle. So it is necessary to expand triangle into two
// tetrahedrons connected with base (which is exactly abc triangle).
// get next support point in direction of normal of triangle
ccdVec3Sub2(&ab, &b->v, &a->v);
ccdVec3Sub2(&ac, &c->v, &a->v);
ccdVec3Cross(&dir, &ab, &ac);
__ccdSupport(obj1, obj2, &dir, ccd, &d);
dist = ccdVec3PointTriDist2(&d.v, &a->v, &b->v, &c->v, NULL);
// and second one take in opposite direction
ccdVec3Scale(&dir, -CCD_ONE);
__ccdSupport(obj1, obj2, &dir, ccd, &d2);
dist2 = ccdVec3PointTriDist2(&d2.v, &a->v, &b->v, &c->v, NULL);
// check if face isn't already on edge of minkowski sum and thus we
// have touching contact
if (ccdIsZero(dist) || ccdIsZero(dist2)){
v[0] = ccdPtAddVertex(pt, a);
v[1] = ccdPtAddVertex(pt, b);
v[2] = ccdPtAddVertex(pt, c);
e[0] = ccdPtAddEdge(pt, v[0], v[1]);
e[1] = ccdPtAddEdge(pt, v[1], v[2]);
e[2] = ccdPtAddEdge(pt, v[2], v[0]);
*nearest = (ccd_pt_el_t *)ccdPtAddFace(pt, e[0], e[1], e[2]);
if (*nearest == NULL)
return -2;
return -1;
}
// form polyhedron
v[0] = ccdPtAddVertex(pt, a);
v[1] = ccdPtAddVertex(pt, b);
v[2] = ccdPtAddVertex(pt, c);
v[3] = ccdPtAddVertex(pt, &d);
v[4] = ccdPtAddVertex(pt, &d2);
e[0] = ccdPtAddEdge(pt, v[0], v[1]);
e[1] = ccdPtAddEdge(pt, v[1], v[2]);
e[2] = ccdPtAddEdge(pt, v[2], v[0]);
e[3] = ccdPtAddEdge(pt, v[3], v[0]);
e[4] = ccdPtAddEdge(pt, v[3], v[1]);
e[5] = ccdPtAddEdge(pt, v[3], v[2]);
e[6] = ccdPtAddEdge(pt, v[4], v[0]);
e[7] = ccdPtAddEdge(pt, v[4], v[1]);
e[8] = ccdPtAddEdge(pt, v[4], v[2]);
if (ccdPtAddFace(pt, e[3], e[4], e[0]) == NULL
|| ccdPtAddFace(pt, e[4], e[5], e[1]) == NULL
|| ccdPtAddFace(pt, e[5], e[3], e[2]) == NULL
|| ccdPtAddFace(pt, e[6], e[7], e[0]) == NULL
|| ccdPtAddFace(pt, e[7], e[8], e[1]) == NULL
|| ccdPtAddFace(pt, e[8], e[6], e[2]) == NULL){
return -2;
}
return 0;
}
/** Transforms simplex to polytope, two vertices required */
static int simplexToPolytope2(const void *obj1, const void *obj2,
const ccd_t *ccd,
const ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest)
{
const ccd_support_t *a, *b;
ccd_vec3_t ab, ac, dir;
ccd_support_t supp[4];
ccd_pt_vertex_t *v[6];
ccd_pt_edge_t *e[12];
size_t i;
int found;
a = ccdSimplexPoint(simplex, 0);
b = ccdSimplexPoint(simplex, 1);
// This situation is a bit tricky. If only one segment comes from
// previous run of GJK - it means that either this segment is on
// minkowski edge (and thus we have touch contact) or it it isn't and
// therefore segment is somewhere *inside* minkowski sum and it *must*
// be possible to fully enclose this segment with polyhedron formed by
// at least 8 triangle faces.
// get first support point (any)
found = 0;
for (i = 0; i < ccd_points_on_sphere_len; i++){
__ccdSupport(obj1, obj2, &ccd_points_on_sphere[i], ccd, &supp[0]);
if (!ccdVec3Eq(&a->v, &supp[0].v) && !ccdVec3Eq(&b->v, &supp[0].v)){
found = 1;
break;
}
}
if (!found)
goto simplexToPolytope2_touching_contact;
// get second support point in opposite direction than supp[0]
ccdVec3Copy(&dir, &supp[0].v);
ccdVec3Scale(&dir, -CCD_ONE);
__ccdSupport(obj1, obj2, &dir, ccd, &supp[1]);
if (ccdVec3Eq(&a->v, &supp[1].v) || ccdVec3Eq(&b->v, &supp[1].v))
goto simplexToPolytope2_touching_contact;
// next will be in direction of normal of triangle a,supp[0],supp[1]
ccdVec3Sub2(&ab, &supp[0].v, &a->v);
ccdVec3Sub2(&ac, &supp[1].v, &a->v);
ccdVec3Cross(&dir, &ab, &ac);
__ccdSupport(obj1, obj2, &dir, ccd, &supp[2]);
if (ccdVec3Eq(&a->v, &supp[2].v) || ccdVec3Eq(&b->v, &supp[2].v))
goto simplexToPolytope2_touching_contact;
// and last one will be in opposite direction
ccdVec3Scale(&dir, -CCD_ONE);
__ccdSupport(obj1, obj2, &dir, ccd, &supp[3]);
if (ccdVec3Eq(&a->v, &supp[3].v) || ccdVec3Eq(&b->v, &supp[3].v))
goto simplexToPolytope2_touching_contact;
goto simplexToPolytope2_not_touching_contact;
simplexToPolytope2_touching_contact:
v[0] = ccdPtAddVertex(pt, a);
v[1] = ccdPtAddVertex(pt, b);
*nearest = (ccd_pt_el_t *)ccdPtAddEdge(pt, v[0], v[1]);
if (*nearest == NULL)
return -2;
return -1;
simplexToPolytope2_not_touching_contact:
// form polyhedron
v[0] = ccdPtAddVertex(pt, a);
v[1] = ccdPtAddVertex(pt, &supp[0]);
v[2] = ccdPtAddVertex(pt, b);
v[3] = ccdPtAddVertex(pt, &supp[1]);
v[4] = ccdPtAddVertex(pt, &supp[2]);
v[5] = ccdPtAddVertex(pt, &supp[3]);
e[0] = ccdPtAddEdge(pt, v[0], v[1]);
e[1] = ccdPtAddEdge(pt, v[1], v[2]);
e[2] = ccdPtAddEdge(pt, v[2], v[3]);
e[3] = ccdPtAddEdge(pt, v[3], v[0]);
e[4] = ccdPtAddEdge(pt, v[4], v[0]);
e[5] = ccdPtAddEdge(pt, v[4], v[1]);
e[6] = ccdPtAddEdge(pt, v[4], v[2]);
e[7] = ccdPtAddEdge(pt, v[4], v[3]);
e[8] = ccdPtAddEdge(pt, v[5], v[0]);
e[9] = ccdPtAddEdge(pt, v[5], v[1]);
e[10] = ccdPtAddEdge(pt, v[5], v[2]);
e[11] = ccdPtAddEdge(pt, v[5], v[3]);
if (ccdPtAddFace(pt, e[4], e[5], e[0]) == NULL
|| ccdPtAddFace(pt, e[5], e[6], e[1]) == NULL
|| ccdPtAddFace(pt, e[6], e[7], e[2]) == NULL
|| ccdPtAddFace(pt, e[7], e[4], e[3]) == NULL
|| ccdPtAddFace(pt, e[8], e[9], e[0]) == NULL
|| ccdPtAddFace(pt, e[9], e[10], e[1]) == NULL
|| ccdPtAddFace(pt, e[10], e[11], e[2]) == NULL
|| ccdPtAddFace(pt, e[11], e[8], e[3]) == NULL){
return -2;
}
return 0;
}
/** Expands polytope's tri by new vertex v. Triangle tri is replaced by
* three triangles each with one vertex in v. */
static int expandPolytope(ccd_pt_t *pt, ccd_pt_el_t *el,
const ccd_support_t *newv)
{
ccd_pt_vertex_t *v[5];
ccd_pt_edge_t *e[8];
ccd_pt_face_t *f[2];
// element can be either segment or triangle
if (el->type == CCD_PT_EDGE){
// In this case, segment should be replaced by new point.
// Simpliest case is when segment stands alone and in this case
// this segment is replaced by two other segments both connected to
// newv.
// Segment can be also connected to max two faces and in that case
// each face must be replaced by two other faces. To do this
// correctly it is necessary to have correctly ordered edges and
// vertices which is exactly what is done in following code.
//
ccdPtEdgeVertices((const ccd_pt_edge_t *)el, &v[0], &v[2]);
ccdPtEdgeFaces((ccd_pt_edge_t *)el, &f[0], &f[1]);
if (f[0]){
ccdPtFaceEdges(f[0], &e[0], &e[1], &e[2]);
if (e[0] == (ccd_pt_edge_t *)el){
e[0] = e[2];
}else if (e[1] == (ccd_pt_edge_t *)el){
e[1] = e[2];
}
ccdPtEdgeVertices(e[0], &v[1], &v[3]);
if (v[1] != v[0] && v[3] != v[0]){
e[2] = e[0];
e[0] = e[1];
e[1] = e[2];
if (v[1] == v[2])
v[1] = v[3];
}else{
if (v[1] == v[0])
v[1] = v[3];
}
if (f[1]){
ccdPtFaceEdges(f[1], &e[2], &e[3], &e[4]);
if (e[2] == (ccd_pt_edge_t *)el){
e[2] = e[4];
}else if (e[3] == (ccd_pt_edge_t *)el){
e[3] = e[4];
}
ccdPtEdgeVertices(e[2], &v[3], &v[4]);
if (v[3] != v[2] && v[4] != v[2]){
e[4] = e[2];
e[2] = e[3];
e[3] = e[4];
if (v[3] == v[0])
v[3] = v[4];
}else{
if (v[3] == v[2])
v[3] = v[4];
}
}
v[4] = ccdPtAddVertex(pt, newv);
ccdPtDelFace(pt, f[0]);
if (f[1]){
ccdPtDelFace(pt, f[1]);
ccdPtDelEdge(pt, (ccd_pt_edge_t *)el);
}
e[4] = ccdPtAddEdge(pt, v[4], v[2]);
e[5] = ccdPtAddEdge(pt, v[4], v[0]);
e[6] = ccdPtAddEdge(pt, v[4], v[1]);
if (f[1])
e[7] = ccdPtAddEdge(pt, v[4], v[3]);
if (ccdPtAddFace(pt, e[1], e[4], e[6]) == NULL
|| ccdPtAddFace(pt, e[0], e[6], e[5]) == NULL){
return -2;
}
if (f[1]){
if (ccdPtAddFace(pt, e[3], e[5], e[7]) == NULL
|| ccdPtAddFace(pt, e[4], e[7], e[2]) == NULL){
return -2;
}
}else{
if (ccdPtAddFace(pt, e[4], e[5], (ccd_pt_edge_t *)el) == NULL)
return -2;
}
}
}else{ // el->type == CCD_PT_FACE
// replace triangle by tetrahedron without base (base would be the
// triangle that will be removed)
// get triplet of surrounding edges and vertices of triangle face
ccdPtFaceEdges((const ccd_pt_face_t *)el, &e[0], &e[1], &e[2]);
ccdPtEdgeVertices(e[0], &v[0], &v[1]);
ccdPtEdgeVertices(e[1], &v[2], &v[3]);
// following code sorts edges to have e[0] between vertices 0-1,
// e[1] between 1-2 and e[2] between 2-0
if (v[2] != v[1] && v[3] != v[1]){
// swap e[1] and e[2]
e[3] = e[1];
e[1] = e[2];
e[2] = e[3];
}
if (v[3] != v[0] && v[3] != v[1])
v[2] = v[3];
// remove triangle face
ccdPtDelFace(pt, (ccd_pt_face_t *)el);
// expand triangle to tetrahedron
v[3] = ccdPtAddVertex(pt, newv);
e[3] = ccdPtAddEdge(pt, v[3], v[0]);
e[4] = ccdPtAddEdge(pt, v[3], v[1]);
e[5] = ccdPtAddEdge(pt, v[3], v[2]);
if (ccdPtAddFace(pt, e[3], e[4], e[0]) == NULL
|| ccdPtAddFace(pt, e[4], e[5], e[1]) == NULL
|| ccdPtAddFace(pt, e[5], e[3], e[2]) == NULL){
return -2;
}
}
return 0;
}
/** Finds next support point (and stores it in out argument).
* Returns 0 on success, -1 otherwise */
static int nextSupport(const void *obj1, const void *obj2, const ccd_t *ccd,
const ccd_pt_el_t *el,
ccd_support_t *out)
{
ccd_vec3_t *a, *b, *c;
ccd_real_t dist;
if (el->type == CCD_PT_VERTEX)
return -1;
// touch contact
if (ccdIsZero(el->dist))
return -1;
__ccdSupport(obj1, obj2, &el->witness, ccd, out);
// Compute dist of support point along element witness point direction
// so we can determine whether we expanded a polytope surrounding the
// origin a bit.
dist = ccdVec3Dot(&out->v, &el->witness);
if (dist - el->dist < ccd->epa_tolerance)
return -1;
if (el->type == CCD_PT_EDGE){
// fetch end points of edge
ccdPtEdgeVec3((ccd_pt_edge_t *)el, &a, &b);
// get distance from segment
dist = ccdVec3PointSegmentDist2(&out->v, a, b, NULL);
}else{ // el->type == CCD_PT_FACE
// fetch vertices of triangle face
ccdPtFaceVec3((ccd_pt_face_t *)el, &a, &b, &c);
// check if new point can significantly expand polytope
dist = ccdVec3PointTriDist2(&out->v, a, b, c, NULL);
}
if (dist < ccd->epa_tolerance)
return -1;
return 0;
}

154
3rdparty/libccd/src/ccd/ccd.h vendored Normal file
View File

@ -0,0 +1,154 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010,2011 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_H__
#define __CCD_H__
#include <ccd/vec3.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Type of *support* function that takes pointer to 3D object and direction
* and returns (via vec argument) furthest point from object in specified
* direction.
*/
typedef void (*ccd_support_fn)(const void *obj, const ccd_vec3_t *dir,
ccd_vec3_t *vec);
/**
* Returns (via dir argument) first direction vector that will be used in
* initialization of algorithm.
*/
typedef void (*ccd_first_dir_fn)(const void *obj1, const void *obj2,
ccd_vec3_t *dir);
/**
* Returns (via center argument) geometric center (some point near center)
* of given object.
*/
typedef void (*ccd_center_fn)(const void *obj1, ccd_vec3_t *center);
/**
* Main structure of CCD algorithm.
*/
struct _ccd_t {
ccd_first_dir_fn first_dir; //!< Returns initial direction where first
//!< support point will be searched
ccd_support_fn support1; //!< Function that returns support point of
//!< first object
ccd_support_fn support2; //!< Function that returns support point of
//!< second object
ccd_center_fn center1; //!< Function that returns geometric center of
//!< first object
ccd_center_fn center2; //!< Function that returns geometric center of
//!< second object
unsigned long max_iterations; //!< Maximal number of iterations
ccd_real_t epa_tolerance;
ccd_real_t mpr_tolerance; //!< Boundary tolerance for MPR algorithm
ccd_real_t dist_tolerance;
};
typedef struct _ccd_t ccd_t;
/**
* Default first direction.
*/
CCD_EXPORT void ccdFirstDirDefault(const void *o1, const void *o2,
ccd_vec3_t *dir);
#define CCD_INIT(ccd) \
do { \
(ccd)->first_dir = ccdFirstDirDefault; \
(ccd)->support1 = NULL; \
(ccd)->support2 = NULL; \
(ccd)->center1 = NULL; \
(ccd)->center2 = NULL; \
\
(ccd)->max_iterations = (unsigned long)-1; \
(ccd)->epa_tolerance = CCD_REAL(0.0001); \
(ccd)->mpr_tolerance = CCD_REAL(0.0001); \
(ccd)->dist_tolerance = CCD_REAL(1E-6); \
} while(0)
/**
* Returns true if two given objects interest.
*/
CCD_EXPORT int ccdGJKIntersect(const void *obj1, const void *obj2,
const ccd_t *ccd);
/**
* This function computes separation vector of two objects. Separation
* vector is minimal translation of obj2 to get obj1 and obj2 speparated
* (without intersection).
* Returns 0 if obj1 and obj2 intersect and sep is filled with translation
* vector. If obj1 and obj2 don't intersect -1 is returned.
* If memory allocation fails -2 is returned.
*/
CCD_EXPORT int ccdGJKSeparate(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_vec3_t *sep);
/**
* Computes penetration of obj2 into obj1.
* Depth of penetration, direction and position is returned. It means that
* if obj2 is translated by distance depth in direction dir objects will
* have touching contact, pos should be position in global coordinates
* where force should take a place.
*
* CCD+EPA algorithm is used.
*
* Returns 0 if obj1 and obj2 intersect and depth, dir and pos are filled
* if given non-NULL pointers.
* If obj1 and obj2 don't intersect -1 is returned.
* If memory allocation fails -2 is returned.
*/
CCD_EXPORT int ccdGJKPenetration(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_real_t *depth,
ccd_vec3_t *dir, ccd_vec3_t *pos);
/**
* Returns true if two given objects intersect - MPR algorithm is used.
*/
CCD_EXPORT int ccdMPRIntersect(const void *obj1, const void *obj2,
const ccd_t *ccd);
/**
* Computes penetration of obj2 into obj1.
* Depth of penetration, direction and position is returned, i.e. if obj2
* is translated by computed depth in resulting direction obj1 and obj2
* would have touching contact. Position is point in global coordinates
* where force should take a place.
*
* Minkowski Portal Refinement algorithm is used (MPR, a.k.a. XenoCollide,
* see Game Programming Gem 7).
*
* Returns 0 if obj1 and obj2 intersect, otherwise -1 is returned.
*/
CCD_EXPORT int ccdMPRPenetration(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_real_t *depth,
ccd_vec3_t *dir, ccd_vec3_t *pos);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_H__ */

26
3rdparty/libccd/src/ccd/ccd_export.h vendored Normal file
View File

@ -0,0 +1,26 @@
#ifndef CCD_EXPORT_H
#define CCD_EXPORT_H
#ifdef CCD_STATIC_DEFINE
# define CCD_EXPORT
#else
# ifdef _MSC_VER
# ifdef ccd_EXPORTS
# define CCD_EXPORT __declspec(dllexport)
# else /* ccd_EXPORTS */
# define CCD_EXPORT __declspec(dllimport)
# endif /* ccd_EXPORTS */
# else
# ifndef CCD_EXPORT
# ifdef ccd_EXPORTS
/* We are building this library */
# define CCD_EXPORT __attribute__((visibility("default")))
# else
/* We are using this library */
# define CCD_EXPORT __attribute__((visibility("default")))
# endif
# endif
# endif
#endif
#endif

64
3rdparty/libccd/src/ccd/compiler.h vendored Normal file
View File

@ -0,0 +1,64 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_COMPILER_H__
#define __CCD_COMPILER_H__
#include <stddef.h>
#define ccd_offsetof(TYPE, MEMBER) offsetof(TYPE, MEMBER)
#define ccd_container_of(ptr, type, member) \
(type *)( (char *)ptr - ccd_offsetof(type, member))
/**
* Marks inline function.
*/
#ifdef __GNUC__
# define _ccd_inline static inline __attribute__((always_inline))
#else /* __GNUC__ */
# define _ccd_inline static __inline
#endif /* __GNUC__ */
/**
* __prefetch(x) - prefetches the cacheline at "x" for read
* __prefetchw(x) - prefetches the cacheline at "x" for write
*/
#ifdef __GNUC__
# define _ccd_prefetch(x) __builtin_prefetch(x)
# define _ccd_prefetchw(x) __builtin_prefetch(x,1)
#else /* __GNUC__ */
# define _ccd_prefetch(x) ((void)0)
# define _ccd_prefetchw(x) ((void)0)
#endif /* __GNUC__ */
#ifdef __ICC
// disable unused parameter warning
# pragma warning(disable:869)
// disable annoying "operands are evaluated in unspecified order" warning
# pragma warning(disable:981)
#endif /* __ICC */
#ifdef _MSC_VER
// disable unsafe function warning
# define _CRT_SECURE_NO_WARNINGS
#endif /* _MSC_VER */
#endif /* __CCD_COMPILER_H__ */

View File

@ -0,0 +1,7 @@
#ifndef __CCD_CONFIG_H__
#define __CCD_CONFIG_H__
#cmakedefine CCD_SINGLE
#cmakedefine CCD_DOUBLE
#endif /* __CCD_CONFIG_H__ */

7
3rdparty/libccd/src/ccd/config.h.m4 vendored Normal file
View File

@ -0,0 +1,7 @@
#ifndef __CCD_CONFIG_H__
#define __CCD_CONFIG_H__
ifdef(`USE_SINGLE', `#define CCD_SINGLE')
ifdef(`USE_DOUBLE', `#define CCD_DOUBLE')
#endif /* __CCD_CONFIG_H__ */

231
3rdparty/libccd/src/ccd/quat.h vendored Normal file
View File

@ -0,0 +1,231 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_QUAT_H__
#define __CCD_QUAT_H__
#include <ccd/compiler.h>
#include <ccd/vec3.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _ccd_quat_t {
ccd_real_t q[4]; //!< x, y, z, w
};
typedef struct _ccd_quat_t ccd_quat_t;
#define CCD_QUAT(name, x, y, z, w) \
ccd_quat_t name = { {x, y, z, w} }
_ccd_inline ccd_real_t ccdQuatLen2(const ccd_quat_t *q);
_ccd_inline ccd_real_t ccdQuatLen(const ccd_quat_t *q);
_ccd_inline void ccdQuatSet(ccd_quat_t *q, ccd_real_t x, ccd_real_t y, ccd_real_t z, ccd_real_t w);
_ccd_inline void ccdQuatCopy(ccd_quat_t *dest, const ccd_quat_t *src);
_ccd_inline int ccdQuatNormalize(ccd_quat_t *q);
_ccd_inline void ccdQuatSetAngleAxis(ccd_quat_t *q,
ccd_real_t angle, const ccd_vec3_t *axis);
_ccd_inline void ccdQuatScale(ccd_quat_t *q, ccd_real_t k);
/**
* q = q * q2
*/
_ccd_inline void ccdQuatMul(ccd_quat_t *q, const ccd_quat_t *q2);
/**
* q = a * b
*/
_ccd_inline void ccdQuatMul2(ccd_quat_t *q,
const ccd_quat_t *a, const ccd_quat_t *b);
/**
* Inverts quaternion.
* Returns 0 on success.
*/
_ccd_inline int ccdQuatInvert(ccd_quat_t *q);
_ccd_inline int ccdQuatInvert2(ccd_quat_t *dest, const ccd_quat_t *src);
/**
* Rotate vector v by quaternion q.
*/
_ccd_inline void ccdQuatRotVec(ccd_vec3_t *v, const ccd_quat_t *q);
/**** INLINES ****/
_ccd_inline ccd_real_t ccdQuatLen2(const ccd_quat_t *q)
{
ccd_real_t len;
len = q->q[0] * q->q[0];
len += q->q[1] * q->q[1];
len += q->q[2] * q->q[2];
len += q->q[3] * q->q[3];
return len;
}
_ccd_inline ccd_real_t ccdQuatLen(const ccd_quat_t *q)
{
return CCD_SQRT(ccdQuatLen2(q));
}
_ccd_inline void ccdQuatSet(ccd_quat_t *q, ccd_real_t x, ccd_real_t y, ccd_real_t z, ccd_real_t w)
{
q->q[0] = x;
q->q[1] = y;
q->q[2] = z;
q->q[3] = w;
}
_ccd_inline void ccdQuatCopy(ccd_quat_t *dest, const ccd_quat_t *src)
{
*dest = *src;
}
_ccd_inline int ccdQuatNormalize(ccd_quat_t *q)
{
ccd_real_t len = ccdQuatLen(q);
if (len < CCD_EPS)
return 0;
ccdQuatScale(q, CCD_ONE / len);
return 1;
}
_ccd_inline void ccdQuatSetAngleAxis(ccd_quat_t *q,
ccd_real_t angle, const ccd_vec3_t *axis)
{
ccd_real_t a, x, y, z, n, s;
a = angle/2;
x = ccdVec3X(axis);
y = ccdVec3Y(axis);
z = ccdVec3Z(axis);
n = CCD_SQRT(x*x + y*y + z*z);
// axis==0? (treat this the same as angle==0 with an arbitrary axis)
if (n < CCD_EPS){
q->q[0] = q->q[1] = q->q[2] = CCD_ZERO;
q->q[3] = CCD_ONE;
}else{
s = sin(a)/n;
q->q[3] = cos(a);
q->q[0] = x*s;
q->q[1] = y*s;
q->q[2] = z*s;
ccdQuatNormalize(q);
}
}
_ccd_inline void ccdQuatScale(ccd_quat_t *q, ccd_real_t k)
{
size_t i;
for (i = 0; i < 4; i++)
q->q[i] *= k;
}
_ccd_inline void ccdQuatMul(ccd_quat_t *q, const ccd_quat_t *q2)
{
ccd_quat_t a;
ccdQuatCopy(&a, q);
ccdQuatMul2(q, &a, q2);
}
_ccd_inline void ccdQuatMul2(ccd_quat_t *q,
const ccd_quat_t *a, const ccd_quat_t *b)
{
q->q[0] = a->q[3] * b->q[0]
+ a->q[0] * b->q[3]
+ a->q[1] * b->q[2]
- a->q[2] * b->q[1];
q->q[1] = a->q[3] * b->q[1]
+ a->q[1] * b->q[3]
- a->q[0] * b->q[2]
+ a->q[2] * b->q[0];
q->q[2] = a->q[3] * b->q[2]
+ a->q[2] * b->q[3]
+ a->q[0] * b->q[1]
- a->q[1] * b->q[0];
q->q[3] = a->q[3] * b->q[3]
- a->q[0] * b->q[0]
- a->q[1] * b->q[1]
- a->q[2] * b->q[2];
}
_ccd_inline int ccdQuatInvert(ccd_quat_t *q)
{
ccd_real_t len2 = ccdQuatLen2(q);
if (len2 < CCD_EPS)
return -1;
len2 = CCD_ONE / len2;
q->q[0] = -q->q[0] * len2;
q->q[1] = -q->q[1] * len2;
q->q[2] = -q->q[2] * len2;
q->q[3] = q->q[3] * len2;
return 0;
}
_ccd_inline int ccdQuatInvert2(ccd_quat_t *dest, const ccd_quat_t *src)
{
ccdQuatCopy(dest, src);
return ccdQuatInvert(dest);
}
_ccd_inline void ccdQuatRotVec(ccd_vec3_t *v, const ccd_quat_t *q)
{
// original version: 31 mul + 21 add
// optimized version: 18 mul + 12 add
// formula: v = v + 2 * cross(q.xyz, cross(q.xyz, v) + q.w * v)
ccd_real_t cross1_x, cross1_y, cross1_z, cross2_x, cross2_y, cross2_z;
ccd_real_t x, y, z, w;
ccd_real_t vx, vy, vz;
vx = ccdVec3X(v);
vy = ccdVec3Y(v);
vz = ccdVec3Z(v);
w = q->q[3];
x = q->q[0];
y = q->q[1];
z = q->q[2];
cross1_x = y * vz - z * vy + w * vx;
cross1_y = z * vx - x * vz + w * vy;
cross1_z = x * vy - y * vx + w * vz;
cross2_x = y * cross1_z - z * cross1_y;
cross2_y = z * cross1_x - x * cross1_z;
cross2_z = x * cross1_y - y * cross1_x;
ccdVec3Set(v, vx + 2 * cross2_x, vy + 2 * cross2_y, vz + 2 * cross2_z);
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_QUAT_H__ */

340
3rdparty/libccd/src/ccd/vec3.h vendored Normal file
View File

@ -0,0 +1,340 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010-2013 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_VEC3_H__
#define __CCD_VEC3_H__
#include <math.h>
#include <float.h>
#include <stdlib.h>
#include <ccd/compiler.h>
#include <ccd/config.h>
#include <ccd/ccd_export.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifndef CCD_SINGLE
# ifndef CCD_DOUBLE
# error You must define CCD_SINGLE or CCD_DOUBLE
# endif /* CCD_DOUBLE */
#endif /* CCD_SINGLE */
#ifdef WIN32
# define CCD_FMIN(x, y) ((x) < (y) ? (x) : (y))
#endif /* WIN32 */
#ifdef CCD_SINGLE
# ifdef CCD_DOUBLE
# error You can define either CCD_SINGLE or CCD_DOUBLE, not both!
# endif /* CCD_DOUBLE */
typedef float ccd_real_t;
//# define CCD_EPS 1E-6
# define CCD_EPS FLT_EPSILON
# define CCD_REAL_MAX FLT_MAX
# define CCD_REAL(x) (x ## f) /*!< form a constant */
# define CCD_SQRT(x) (sqrtf(x)) /*!< square root */
# define CCD_FABS(x) (fabsf(x)) /*!< absolute value */
# define CCD_FMAX(x, y) (fmaxf((x), (y))) /*!< maximum of two floats */
# ifndef CCD_FMIN
# define CCD_FMIN(x, y) (fminf((x), (y))) /*!< minimum of two floats */
# endif /* CCD_FMIN */
#endif /* CCD_SINGLE */
#ifdef CCD_DOUBLE
typedef double ccd_real_t;
//# define CCD_EPS 1E-10
# define CCD_EPS DBL_EPSILON
# define CCD_REAL_MAX DBL_MAX
# define CCD_REAL(x) (x) /*!< form a constant */
# define CCD_SQRT(x) (sqrt(x)) /*!< square root */
# define CCD_FABS(x) (fabs(x)) /*!< absolute value */
# define CCD_FMAX(x, y) (fmax((x), (y))) /*!< maximum of two floats */
# ifndef CCD_FMIN
# define CCD_FMIN(x, y) (fmin((x), (y))) /*!< minimum of two floats */
# endif /* CCD_FMIN */
#endif /* CCD_DOUBLE */
#define CCD_ONE CCD_REAL(1.)
#define CCD_ZERO CCD_REAL(0.)
struct _ccd_vec3_t {
ccd_real_t v[3];
};
typedef struct _ccd_vec3_t ccd_vec3_t;
/**
* Holds origin (0,0,0) - this variable is meant to be read-only!
*/
CCD_EXPORT extern ccd_vec3_t *ccd_vec3_origin;
/**
* Array of points uniformly distributed on unit sphere.
*/
CCD_EXPORT extern ccd_vec3_t *ccd_points_on_sphere;
CCD_EXPORT extern size_t ccd_points_on_sphere_len;
/** Returns sign of value. */
_ccd_inline int ccdSign(ccd_real_t val);
/** Returns true if val is zero. **/
_ccd_inline int ccdIsZero(ccd_real_t val);
/** Returns true if a and b equal. **/
_ccd_inline int ccdEq(ccd_real_t a, ccd_real_t b);
#define CCD_VEC3_STATIC(x, y, z) \
{ { (x), (y), (z) } }
#define CCD_VEC3(name, x, y, z) \
ccd_vec3_t name = CCD_VEC3_STATIC((x), (y), (z))
_ccd_inline ccd_real_t ccdVec3X(const ccd_vec3_t *v);
_ccd_inline ccd_real_t ccdVec3Y(const ccd_vec3_t *v);
_ccd_inline ccd_real_t ccdVec3Z(const ccd_vec3_t *v);
/**
* Returns true if a and b equal.
*/
_ccd_inline int ccdVec3Eq(const ccd_vec3_t *a, const ccd_vec3_t *b);
/**
* Returns squared length of vector.
*/
_ccd_inline ccd_real_t ccdVec3Len2(const ccd_vec3_t *v);
/**
* Returns distance between a and b.
*/
_ccd_inline ccd_real_t ccdVec3Dist2(const ccd_vec3_t *a, const ccd_vec3_t *b);
_ccd_inline void ccdVec3Set(ccd_vec3_t *v, ccd_real_t x, ccd_real_t y, ccd_real_t z);
/**
* v = w
*/
_ccd_inline void ccdVec3Copy(ccd_vec3_t *v, const ccd_vec3_t *w);
/**
* Substracts coordinates of vector w from vector v. v = v - w
*/
_ccd_inline void ccdVec3Sub(ccd_vec3_t *v, const ccd_vec3_t *w);
/**
* Adds coordinates of vector w to vector v. v = v + w
*/
_ccd_inline void ccdVec3Add(ccd_vec3_t *v, const ccd_vec3_t *w);
/**
* d = v - w
*/
_ccd_inline void ccdVec3Sub2(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *w);
/**
* d = d * k;
*/
_ccd_inline void ccdVec3Scale(ccd_vec3_t *d, ccd_real_t k);
/**
* Normalizes given vector to unit length.
*/
_ccd_inline void ccdVec3Normalize(ccd_vec3_t *d);
/**
* Dot product of two vectors.
*/
_ccd_inline ccd_real_t ccdVec3Dot(const ccd_vec3_t *a, const ccd_vec3_t *b);
/**
* Cross product: d = a x b.
*/
_ccd_inline void ccdVec3Cross(ccd_vec3_t *d, const ccd_vec3_t *a, const ccd_vec3_t *b);
/**
* Returns distance^2 of point P to segment ab.
* If witness is non-NULL it is filled with coordinates of point from which
* was computed distance to point P.
*/
CCD_EXPORT ccd_real_t ccdVec3PointSegmentDist2(const ccd_vec3_t *P,
const ccd_vec3_t *a,
const ccd_vec3_t *b,
ccd_vec3_t *witness);
/**
* Returns distance^2 of point P from triangle formed by triplet a, b, c.
* If witness vector is provided it is filled with coordinates of point
* from which was computed distance to point P.
*/
CCD_EXPORT ccd_real_t ccdVec3PointTriDist2(const ccd_vec3_t *P,
const ccd_vec3_t *a,
const ccd_vec3_t *b,
const ccd_vec3_t *c,
ccd_vec3_t *witness);
/**** INLINES ****/
_ccd_inline int ccdSign(ccd_real_t val)
{
if (ccdIsZero(val)){
return 0;
}else if (val < CCD_ZERO){
return -1;
}
return 1;
}
_ccd_inline int ccdIsZero(ccd_real_t val)
{
return CCD_FABS(val) < CCD_EPS;
}
_ccd_inline int ccdEq(ccd_real_t _a, ccd_real_t _b)
{
ccd_real_t ab;
ccd_real_t a, b;
ab = CCD_FABS(_a - _b);
if (CCD_FABS(ab) < CCD_EPS)
return 1;
a = CCD_FABS(_a);
b = CCD_FABS(_b);
if (b > a){
return ab < CCD_EPS * b;
}else{
return ab < CCD_EPS * a;
}
}
_ccd_inline ccd_real_t ccdVec3X(const ccd_vec3_t *v)
{
return v->v[0];
}
_ccd_inline ccd_real_t ccdVec3Y(const ccd_vec3_t *v)
{
return v->v[1];
}
_ccd_inline ccd_real_t ccdVec3Z(const ccd_vec3_t *v)
{
return v->v[2];
}
_ccd_inline int ccdVec3Eq(const ccd_vec3_t *a, const ccd_vec3_t *b)
{
return ccdEq(ccdVec3X(a), ccdVec3X(b))
&& ccdEq(ccdVec3Y(a), ccdVec3Y(b))
&& ccdEq(ccdVec3Z(a), ccdVec3Z(b));
}
_ccd_inline ccd_real_t ccdVec3Len2(const ccd_vec3_t *v)
{
return ccdVec3Dot(v, v);
}
_ccd_inline ccd_real_t ccdVec3Dist2(const ccd_vec3_t *a, const ccd_vec3_t *b)
{
ccd_vec3_t ab;
ccdVec3Sub2(&ab, a, b);
return ccdVec3Len2(&ab);
}
_ccd_inline void ccdVec3Set(ccd_vec3_t *v, ccd_real_t x, ccd_real_t y, ccd_real_t z)
{
v->v[0] = x;
v->v[1] = y;
v->v[2] = z;
}
_ccd_inline void ccdVec3Copy(ccd_vec3_t *v, const ccd_vec3_t *w)
{
*v = *w;
}
_ccd_inline void ccdVec3Sub(ccd_vec3_t *v, const ccd_vec3_t *w)
{
v->v[0] -= w->v[0];
v->v[1] -= w->v[1];
v->v[2] -= w->v[2];
}
_ccd_inline void ccdVec3Sub2(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *w)
{
d->v[0] = v->v[0] - w->v[0];
d->v[1] = v->v[1] - w->v[1];
d->v[2] = v->v[2] - w->v[2];
}
_ccd_inline void ccdVec3Add(ccd_vec3_t *v, const ccd_vec3_t *w)
{
v->v[0] += w->v[0];
v->v[1] += w->v[1];
v->v[2] += w->v[2];
}
_ccd_inline void ccdVec3Scale(ccd_vec3_t *d, ccd_real_t k)
{
d->v[0] *= k;
d->v[1] *= k;
d->v[2] *= k;
}
_ccd_inline void ccdVec3Normalize(ccd_vec3_t *d)
{
ccd_real_t k = CCD_ONE / CCD_SQRT(ccdVec3Len2(d));
ccdVec3Scale(d, k);
}
_ccd_inline ccd_real_t ccdVec3Dot(const ccd_vec3_t *a, const ccd_vec3_t *b)
{
ccd_real_t dot;
dot = a->v[0] * b->v[0];
dot += a->v[1] * b->v[1];
dot += a->v[2] * b->v[2];
return dot;
}
_ccd_inline void ccdVec3Cross(ccd_vec3_t *d, const ccd_vec3_t *a, const ccd_vec3_t *b)
{
d->v[0] = (a->v[1] * b->v[2]) - (a->v[2] * b->v[1]);
d->v[1] = (a->v[2] * b->v[0]) - (a->v[0] * b->v[2]);
d->v[2] = (a->v[0] * b->v[1]) - (a->v[1] * b->v[0]);
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_VEC3_H__ */

65
3rdparty/libccd/src/dbg.h vendored Normal file
View File

@ -0,0 +1,65 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_DBG_H__
#define __CCD_DBG_H__
/**
* Some macros which can be used for printing debug info to stderr if macro
* NDEBUG not defined.
*
* DBG_PROLOGUE can be specified as string and this string will be
* prepended to output text
*/
#ifndef NDEBUG
#include <stdio.h>
#ifndef DBG_PROLOGUE
# define DBG_PROLOGUE
#endif
# define DBG(format, ...) do { \
fprintf(stderr, DBG_PROLOGUE "%s :: " format "\n", __func__, ## __VA_ARGS__); \
fflush(stderr); \
} while (0)
# define DBG2(str) do { \
fprintf(stderr, DBG_PROLOGUE "%s :: " str "\n", __func__); \
fflush(stderr); \
} while (0)
# define DBG_VEC3(vec, prefix) do {\
fprintf(stderr, DBG_PROLOGUE "%s :: %s[%lf %lf %lf]\n", \
__func__, prefix, ccdVec3X(vec), ccdVec3Y(vec), ccdVec3Z(vec)); \
fflush(stderr); \
} while (0)
/*
# define DBG_VEC3(vec, prefix) do {\
fprintf(stderr, DBG_PROLOGUE "%s :: %s[%.20lf %.20lf %.20lf]\n", \
__func__, prefix, ccdVec3X(vec), ccdVec3Y(vec), ccdVec3Z(vec)); \
fflush(stderr); \
} while (0)
*/
#else
# define DBG(format, ...)
# define DBG2(str)
# define DBG_VEC3(v, prefix)
#endif
#endif /* __CCD_DBG_H__ */

155
3rdparty/libccd/src/list.h vendored Normal file
View File

@ -0,0 +1,155 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_LIST_H__
#define __CCD_LIST_H__
#include <string.h>
#include <ccd/compiler.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _ccd_list_t {
struct _ccd_list_t *next, *prev;
};
typedef struct _ccd_list_t ccd_list_t;
/**
* Get the struct for this entry.
* @ptr: the &ccd_list_t pointer.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#define ccdListEntry(ptr, type, member) \
ccd_container_of(ptr, type, member)
/**
* Iterates over list.
*/
#define ccdListForEach(list, item) \
for (item = (list)->next; \
_ccd_prefetch((item)->next), item != (list); \
item = (item)->next)
/**
* Iterates over list safe against remove of list entry
*/
#define ccdListForEachSafe(list, item, tmp) \
for (item = (list)->next, tmp = (item)->next; \
item != (list); \
item = tmp, tmp = (item)->next)
/**
* Iterates over list of given type.
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define ccdListForEachEntry(head, pos, postype, member) \
for (pos = ccdListEntry((head)->next, postype, member); \
_ccd_prefetch(pos->member.next), &pos->member != (head); \
pos = ccdListEntry(pos->member.next, postype, member))
/**
* Iterates over list of given type safe against removal of list entry
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define ccdListForEachEntrySafe(head, pos, postype, n, ntype, member) \
for (pos = ccdListEntry((head)->next, postype, member), \
n = ccdListEntry(pos->member.next, postype, member); \
&pos->member != (head); \
pos = n, n = ccdListEntry(n->member.next, ntype, member))
/**
* Initialize list.
*/
_ccd_inline void ccdListInit(ccd_list_t *l);
_ccd_inline ccd_list_t *ccdListNext(ccd_list_t *l);
_ccd_inline ccd_list_t *ccdListPrev(ccd_list_t *l);
/**
* Returns true if list is empty.
*/
_ccd_inline int ccdListEmpty(const ccd_list_t *head);
/**
* Appends item to end of the list l.
*/
_ccd_inline void ccdListAppend(ccd_list_t *l, ccd_list_t *item);
/**
* Removes item from list.
*/
_ccd_inline void ccdListDel(ccd_list_t *item);
///
/// INLINES:
///
_ccd_inline void ccdListInit(ccd_list_t *l)
{
l->next = l;
l->prev = l;
}
_ccd_inline ccd_list_t *ccdListNext(ccd_list_t *l)
{
return l->next;
}
_ccd_inline ccd_list_t *ccdListPrev(ccd_list_t *l)
{
return l->prev;
}
_ccd_inline int ccdListEmpty(const ccd_list_t *head)
{
return head->next == head;
}
_ccd_inline void ccdListAppend(ccd_list_t *l, ccd_list_t *new)
{
new->prev = l->prev;
new->next = l;
l->prev->next = new;
l->prev = new;
}
_ccd_inline void ccdListDel(ccd_list_t *item)
{
item->next->prev = item->prev;
item->prev->next = item->next;
item->next = item;
item->prev = item;
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_LIST_H__ */

543
3rdparty/libccd/src/mpr.c vendored Normal file
View File

@ -0,0 +1,543 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010,2011 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#include <stdlib.h>
#include <ccd/ccd.h>
#include "simplex.h"
#include "dbg.h"
/** Finds origin (center) of Minkowski difference (actually it can be any
* interior point of Minkowski difference. */
_ccd_inline void findOrigin(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_support_t *center);
/** Discovers initial portal - that is tetrahedron that intersects with
* origin ray (ray from center of Minkowski diff to (0,0,0).
*
* Returns -1 if already recognized that origin is outside Minkowski
* portal.
* Returns 1 if origin lies on v1 of simplex (only v0 and v1 are present
* in simplex).
* Returns 2 if origin lies on v0-v1 segment.
* Returns 0 if portal was built.
*/
static int discoverPortal(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *portal);
/** Expands portal towards origin and determine if objects intersect.
* Already established portal must be given as argument.
* If intersection is found 0 is returned, -1 otherwise */
static int refinePortal(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *portal);
/** Finds penetration info by expanding provided portal. */
static void findPenetr(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos);
/** Finds penetration info if origin lies on portal's v1 */
static void findPenetrTouch(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos);
/** Find penetration info if origin lies on portal's segment v0-v1 */
static void findPenetrSegment(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos);
/** Finds position vector from fully established portal */
static void findPos(const void *obj1, const void *obj2, const ccd_t *ccd,
const ccd_simplex_t *portal, ccd_vec3_t *pos);
/** Extends portal with new support point.
* Portal must have face v1-v2-v3 arranged to face outside portal. */
_ccd_inline void expandPortal(ccd_simplex_t *portal,
const ccd_support_t *v4);
/** Fill dir with direction outside portal. Portal's v1-v2-v3 face must be
* arranged in correct order! */
_ccd_inline void portalDir(const ccd_simplex_t *portal, ccd_vec3_t *dir);
/** Returns true if portal encapsules origin (0,0,0), dir is direction of
* v1-v2-v3 face. */
_ccd_inline int portalEncapsulesOrigin(const ccd_simplex_t *portal,
const ccd_vec3_t *dir);
/** Returns true if portal with new point v4 would reach specified
* tolerance (i.e. returns true if portal can _not_ significantly expand
* within Minkowski difference).
*
* v4 is candidate for new point in portal, dir is direction in which v4
* was obtained. */
_ccd_inline int portalReachTolerance(const ccd_simplex_t *portal,
const ccd_support_t *v4,
const ccd_vec3_t *dir,
const ccd_t *ccd);
/** Returns true if portal expanded by new point v4 could possibly contain
* origin, dir is direction in which v4 was obtained. */
_ccd_inline int portalCanEncapsuleOrigin(const ccd_simplex_t *portal,
const ccd_support_t *v4,
const ccd_vec3_t *dir);
int ccdMPRIntersect(const void *obj1, const void *obj2, const ccd_t *ccd)
{
ccd_simplex_t portal;
int res;
// Phase 1: Portal discovery - find portal that intersects with origin
// ray (ray from center of Minkowski diff to origin of coordinates)
res = discoverPortal(obj1, obj2, ccd, &portal);
if (res < 0)
return 0;
if (res > 0)
return 1;
// Phase 2: Portal refinement
res = refinePortal(obj1, obj2, ccd, &portal);
return (res == 0 ? 1 : 0);
}
int ccdMPRPenetration(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos)
{
ccd_simplex_t portal;
int res;
// Phase 1: Portal discovery
res = discoverPortal(obj1, obj2, ccd, &portal);
if (res < 0){
// Origin isn't inside portal - no collision.
return -1;
}else if (res == 1){
// Touching contact on portal's v1.
findPenetrTouch(obj1, obj2, ccd, &portal, depth, dir, pos);
}else if (res == 2){
// Origin lies on v0-v1 segment.
findPenetrSegment(obj1, obj2, ccd, &portal, depth, dir, pos);
}else if (res == 0){
// Phase 2: Portal refinement
res = refinePortal(obj1, obj2, ccd, &portal);
if (res < 0)
return -1;
// Phase 3. Penetration info
findPenetr(obj1, obj2, ccd, &portal, depth, dir, pos);
}
return 0;
}
_ccd_inline void findOrigin(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_support_t *center)
{
ccd->center1(obj1, &center->v1);
ccd->center2(obj2, &center->v2);
ccdVec3Sub2(&center->v, &center->v1, &center->v2);
}
static int discoverPortal(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *portal)
{
ccd_vec3_t dir, va, vb;
ccd_real_t dot;
int cont;
// vertex 0 is center of portal
findOrigin(obj1, obj2, ccd, ccdSimplexPointW(portal, 0));
ccdSimplexSetSize(portal, 1);
if (ccdVec3Eq(&ccdSimplexPoint(portal, 0)->v, ccd_vec3_origin)){
// Portal's center lies on origin (0,0,0) => we know that objects
// intersect but we would need to know penetration info.
// So move center little bit...
ccdVec3Set(&va, CCD_EPS * CCD_REAL(10.), CCD_ZERO, CCD_ZERO);
ccdVec3Add(&ccdSimplexPointW(portal, 0)->v, &va);
}
// vertex 1 = support in direction of origin
ccdVec3Copy(&dir, &ccdSimplexPoint(portal, 0)->v);
ccdVec3Scale(&dir, CCD_REAL(-1.));
ccdVec3Normalize(&dir);
__ccdSupport(obj1, obj2, &dir, ccd, ccdSimplexPointW(portal, 1));
ccdSimplexSetSize(portal, 2);
// test if origin isn't outside of v1
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 1)->v, &dir);
if (ccdIsZero(dot) || dot < CCD_ZERO)
return -1;
// vertex 2
ccdVec3Cross(&dir, &ccdSimplexPoint(portal, 0)->v,
&ccdSimplexPoint(portal, 1)->v);
if (ccdIsZero(ccdVec3Len2(&dir))){
if (ccdVec3Eq(&ccdSimplexPoint(portal, 1)->v, ccd_vec3_origin)){
// origin lies on v1
return 1;
}else{
// origin lies on v0-v1 segment
return 2;
}
}
ccdVec3Normalize(&dir);
__ccdSupport(obj1, obj2, &dir, ccd, ccdSimplexPointW(portal, 2));
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 2)->v, &dir);
if (ccdIsZero(dot) || dot < CCD_ZERO)
return -1;
ccdSimplexSetSize(portal, 3);
// vertex 3 direction
ccdVec3Sub2(&va, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 0)->v);
ccdVec3Sub2(&vb, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 0)->v);
ccdVec3Cross(&dir, &va, &vb);
ccdVec3Normalize(&dir);
// it is better to form portal faces to be oriented "outside" origin
dot = ccdVec3Dot(&dir, &ccdSimplexPoint(portal, 0)->v);
if (dot > CCD_ZERO){
ccdSimplexSwap(portal, 1, 2);
ccdVec3Scale(&dir, CCD_REAL(-1.));
}
while (ccdSimplexSize(portal) < 4){
__ccdSupport(obj1, obj2, &dir, ccd, ccdSimplexPointW(portal, 3));
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 3)->v, &dir);
if (ccdIsZero(dot) || dot < CCD_ZERO)
return -1;
cont = 0;
// test if origin is outside (v1, v0, v3) - set v2 as v3 and
// continue
ccdVec3Cross(&va, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 3)->v);
dot = ccdVec3Dot(&va, &ccdSimplexPoint(portal, 0)->v);
if (dot < CCD_ZERO && !ccdIsZero(dot)){
ccdSimplexSet(portal, 2, ccdSimplexPoint(portal, 3));
cont = 1;
}
if (!cont){
// test if origin is outside (v3, v0, v2) - set v1 as v3 and
// continue
ccdVec3Cross(&va, &ccdSimplexPoint(portal, 3)->v,
&ccdSimplexPoint(portal, 2)->v);
dot = ccdVec3Dot(&va, &ccdSimplexPoint(portal, 0)->v);
if (dot < CCD_ZERO && !ccdIsZero(dot)){
ccdSimplexSet(portal, 1, ccdSimplexPoint(portal, 3));
cont = 1;
}
}
if (cont){
ccdVec3Sub2(&va, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 0)->v);
ccdVec3Sub2(&vb, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 0)->v);
ccdVec3Cross(&dir, &va, &vb);
ccdVec3Normalize(&dir);
}else{
ccdSimplexSetSize(portal, 4);
}
}
return 0;
}
static int refinePortal(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *portal)
{
ccd_vec3_t dir;
ccd_support_t v4;
while (1){
// compute direction outside the portal (from v0 throught v1,v2,v3
// face)
portalDir(portal, &dir);
// test if origin is inside the portal
if (portalEncapsulesOrigin(portal, &dir))
return 0;
// get next support point
__ccdSupport(obj1, obj2, &dir, ccd, &v4);
// test if v4 can expand portal to contain origin and if portal
// expanding doesn't reach given tolerance
if (!portalCanEncapsuleOrigin(portal, &v4, &dir)
|| portalReachTolerance(portal, &v4, &dir, ccd)){
return -1;
}
// v1-v2-v3 triangle must be rearranged to face outside Minkowski
// difference (direction from v0).
expandPortal(portal, &v4);
}
return -1;
}
static void findPenetr(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *pdir, ccd_vec3_t *pos)
{
ccd_vec3_t dir;
ccd_support_t v4;
unsigned long iterations;
iterations = 0UL;
while (1){
// compute portal direction and obtain next support point
portalDir(portal, &dir);
__ccdSupport(obj1, obj2, &dir, ccd, &v4);
// reached tolerance -> find penetration info
if (portalReachTolerance(portal, &v4, &dir, ccd)
|| iterations > ccd->max_iterations){
*depth = ccdVec3PointTriDist2(ccd_vec3_origin,
&ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 3)->v,
pdir);
*depth = CCD_SQRT(*depth);
if (ccdIsZero(*depth)){
// If depth is zero, then we have a touching contact.
// So following findPenetrTouch(), we assign zero to
// the direction vector (it can actually be anything
// according to the decription of ccdMPRPenetration
// function).
ccdVec3Copy(pdir, ccd_vec3_origin);
}else{
ccdVec3Normalize(pdir);
}
// barycentric coordinates:
findPos(obj1, obj2, ccd, portal, pos);
return;
}
expandPortal(portal, &v4);
iterations++;
}
}
static void findPenetrTouch(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos)
{
// Touching contact on portal's v1 - so depth is zero and direction
// is unimportant and pos can be guessed
*depth = CCD_REAL(0.);
ccdVec3Copy(dir, ccd_vec3_origin);
ccdVec3Copy(pos, &ccdSimplexPoint(portal, 1)->v1);
ccdVec3Add(pos, &ccdSimplexPoint(portal, 1)->v2);
ccdVec3Scale(pos, 0.5);
}
static void findPenetrSegment(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos)
{
/*
ccd_vec3_t vec;
ccd_real_t k;
*/
// Origin lies on v0-v1 segment.
// Depth is distance to v1, direction also and position must be
// computed
ccdVec3Copy(pos, &ccdSimplexPoint(portal, 1)->v1);
ccdVec3Add(pos, &ccdSimplexPoint(portal, 1)->v2);
ccdVec3Scale(pos, CCD_REAL(0.5));
/*
ccdVec3Sub2(&vec, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 0)->v);
k = CCD_SQRT(ccdVec3Len2(&ccdSimplexPoint(portal, 0)->v));
k /= CCD_SQRT(ccdVec3Len2(&vec));
ccdVec3Scale(&vec, -k);
ccdVec3Add(pos, &vec);
*/
ccdVec3Copy(dir, &ccdSimplexPoint(portal, 1)->v);
*depth = CCD_SQRT(ccdVec3Len2(dir));
ccdVec3Normalize(dir);
}
static void findPos(const void *obj1, const void *obj2, const ccd_t *ccd,
const ccd_simplex_t *portal, ccd_vec3_t *pos)
{
ccd_vec3_t dir;
size_t i;
ccd_real_t b[4], sum, inv;
ccd_vec3_t vec, p1, p2;
portalDir(portal, &dir);
// use barycentric coordinates of tetrahedron to find origin
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 2)->v);
b[0] = ccdVec3Dot(&vec, &ccdSimplexPoint(portal, 3)->v);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 3)->v,
&ccdSimplexPoint(portal, 2)->v);
b[1] = ccdVec3Dot(&vec, &ccdSimplexPoint(portal, 0)->v);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 0)->v,
&ccdSimplexPoint(portal, 1)->v);
b[2] = ccdVec3Dot(&vec, &ccdSimplexPoint(portal, 3)->v);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 1)->v);
b[3] = ccdVec3Dot(&vec, &ccdSimplexPoint(portal, 0)->v);
sum = b[0] + b[1] + b[2] + b[3];
if (ccdIsZero(sum) || sum < CCD_ZERO){
b[0] = CCD_REAL(0.);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 3)->v);
b[1] = ccdVec3Dot(&vec, &dir);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 3)->v,
&ccdSimplexPoint(portal, 1)->v);
b[2] = ccdVec3Dot(&vec, &dir);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 2)->v);
b[3] = ccdVec3Dot(&vec, &dir);
sum = b[1] + b[2] + b[3];
}
inv = CCD_REAL(1.) / sum;
ccdVec3Copy(&p1, ccd_vec3_origin);
ccdVec3Copy(&p2, ccd_vec3_origin);
for (i = 0; i < 4; i++){
ccdVec3Copy(&vec, &ccdSimplexPoint(portal, i)->v1);
ccdVec3Scale(&vec, b[i]);
ccdVec3Add(&p1, &vec);
ccdVec3Copy(&vec, &ccdSimplexPoint(portal, i)->v2);
ccdVec3Scale(&vec, b[i]);
ccdVec3Add(&p2, &vec);
}
ccdVec3Scale(&p1, inv);
ccdVec3Scale(&p2, inv);
ccdVec3Copy(pos, &p1);
ccdVec3Add(pos, &p2);
ccdVec3Scale(pos, 0.5);
}
_ccd_inline void expandPortal(ccd_simplex_t *portal,
const ccd_support_t *v4)
{
ccd_real_t dot;
ccd_vec3_t v4v0;
ccdVec3Cross(&v4v0, &v4->v, &ccdSimplexPoint(portal, 0)->v);
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 1)->v, &v4v0);
if (dot > CCD_ZERO){
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 2)->v, &v4v0);
if (dot > CCD_ZERO){
ccdSimplexSet(portal, 1, v4);
}else{
ccdSimplexSet(portal, 3, v4);
}
}else{
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 3)->v, &v4v0);
if (dot > CCD_ZERO){
ccdSimplexSet(portal, 2, v4);
}else{
ccdSimplexSet(portal, 1, v4);
}
}
}
_ccd_inline void portalDir(const ccd_simplex_t *portal, ccd_vec3_t *dir)
{
ccd_vec3_t v2v1, v3v1;
ccdVec3Sub2(&v2v1, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 1)->v);
ccdVec3Sub2(&v3v1, &ccdSimplexPoint(portal, 3)->v,
&ccdSimplexPoint(portal, 1)->v);
ccdVec3Cross(dir, &v2v1, &v3v1);
ccdVec3Normalize(dir);
}
_ccd_inline int portalEncapsulesOrigin(const ccd_simplex_t *portal,
const ccd_vec3_t *dir)
{
ccd_real_t dot;
dot = ccdVec3Dot(dir, &ccdSimplexPoint(portal, 1)->v);
return ccdIsZero(dot) || dot > CCD_ZERO;
}
_ccd_inline int portalReachTolerance(const ccd_simplex_t *portal,
const ccd_support_t *v4,
const ccd_vec3_t *dir,
const ccd_t *ccd)
{
ccd_real_t dv1, dv2, dv3, dv4;
ccd_real_t dot1, dot2, dot3;
// find the smallest dot product of dir and {v1-v4, v2-v4, v3-v4}
dv1 = ccdVec3Dot(&ccdSimplexPoint(portal, 1)->v, dir);
dv2 = ccdVec3Dot(&ccdSimplexPoint(portal, 2)->v, dir);
dv3 = ccdVec3Dot(&ccdSimplexPoint(portal, 3)->v, dir);
dv4 = ccdVec3Dot(&v4->v, dir);
dot1 = dv4 - dv1;
dot2 = dv4 - dv2;
dot3 = dv4 - dv3;
dot1 = CCD_FMIN(dot1, dot2);
dot1 = CCD_FMIN(dot1, dot3);
return ccdEq(dot1, ccd->mpr_tolerance) || dot1 < ccd->mpr_tolerance;
}
_ccd_inline int portalCanEncapsuleOrigin(const ccd_simplex_t *portal,
const ccd_support_t *v4,
const ccd_vec3_t *dir)
{
ccd_real_t dot;
dot = ccdVec3Dot(&v4->v, dir);
return ccdIsZero(dot) || dot > CCD_ZERO;
}

298
3rdparty/libccd/src/polytope.c vendored Normal file
View File

@ -0,0 +1,298 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#include <stdio.h>
#include <float.h>
#include "polytope.h"
#include "alloc.h"
_ccd_inline void _ccdPtNearestUpdate(ccd_pt_t *pt, ccd_pt_el_t *el)
{
if (ccdEq(pt->nearest_dist, el->dist)){
if (el->type < pt->nearest_type){
pt->nearest = el;
pt->nearest_dist = el->dist;
pt->nearest_type = el->type;
}
}else if (el->dist < pt->nearest_dist){
pt->nearest = el;
pt->nearest_dist = el->dist;
pt->nearest_type = el->type;
}
}
static void _ccdPtNearestRenew(ccd_pt_t *pt)
{
ccd_pt_vertex_t *v;
ccd_pt_edge_t *e;
ccd_pt_face_t *f;
pt->nearest_dist = CCD_REAL_MAX;
pt->nearest_type = 3;
pt->nearest = NULL;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)v);
}
ccdListForEachEntry(&pt->edges, e, ccd_pt_edge_t, list){
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)e);
}
ccdListForEachEntry(&pt->faces, f, ccd_pt_face_t, list){
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)f);
}
}
void ccdPtInit(ccd_pt_t *pt)
{
ccdListInit(&pt->vertices);
ccdListInit(&pt->edges);
ccdListInit(&pt->faces);
pt->nearest = NULL;
pt->nearest_dist = CCD_REAL_MAX;
pt->nearest_type = 3;
}
void ccdPtDestroy(ccd_pt_t *pt)
{
ccd_pt_face_t *f, *f2;
ccd_pt_edge_t *e, *e2;
ccd_pt_vertex_t *v, *v2;
// first delete all faces
ccdListForEachEntrySafe(&pt->faces, f, ccd_pt_face_t, f2, ccd_pt_face_t, list){
ccdPtDelFace(pt, f);
}
// delete all edges
ccdListForEachEntrySafe(&pt->edges, e, ccd_pt_edge_t, e2, ccd_pt_edge_t, list){
ccdPtDelEdge(pt, e);
}
// delete all vertices
ccdListForEachEntrySafe(&pt->vertices, v, ccd_pt_vertex_t, v2, ccd_pt_vertex_t, list){
ccdPtDelVertex(pt, v);
}
}
ccd_pt_vertex_t *ccdPtAddVertex(ccd_pt_t *pt, const ccd_support_t *v)
{
ccd_pt_vertex_t *vert;
vert = CCD_ALLOC(ccd_pt_vertex_t);
if (vert == NULL)
return NULL;
vert->type = CCD_PT_VERTEX;
ccdSupportCopy(&vert->v, v);
vert->dist = ccdVec3Len2(&vert->v.v);
ccdVec3Copy(&vert->witness, &vert->v.v);
ccdListInit(&vert->edges);
// add vertex to list
ccdListAppend(&pt->vertices, &vert->list);
// update position in .nearest array
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)vert);
return vert;
}
ccd_pt_edge_t *ccdPtAddEdge(ccd_pt_t *pt, ccd_pt_vertex_t *v1,
ccd_pt_vertex_t *v2)
{
const ccd_vec3_t *a, *b;
ccd_pt_edge_t *edge;
if (v1 == NULL || v2 == NULL)
return NULL;
edge = CCD_ALLOC(ccd_pt_edge_t);
if (edge == NULL)
return NULL;
edge->type = CCD_PT_EDGE;
edge->vertex[0] = v1;
edge->vertex[1] = v2;
edge->faces[0] = edge->faces[1] = NULL;
a = &edge->vertex[0]->v.v;
b = &edge->vertex[1]->v.v;
edge->dist = ccdVec3PointSegmentDist2(ccd_vec3_origin, a, b, &edge->witness);
ccdListAppend(&edge->vertex[0]->edges, &edge->vertex_list[0]);
ccdListAppend(&edge->vertex[1]->edges, &edge->vertex_list[1]);
ccdListAppend(&pt->edges, &edge->list);
// update position in .nearest array
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)edge);
return edge;
}
ccd_pt_face_t *ccdPtAddFace(ccd_pt_t *pt, ccd_pt_edge_t *e1,
ccd_pt_edge_t *e2,
ccd_pt_edge_t *e3)
{
const ccd_vec3_t *a, *b, *c;
ccd_pt_face_t *face;
ccd_pt_edge_t *e;
size_t i;
if (e1 == NULL || e2 == NULL || e3 == NULL)
return NULL;
face = CCD_ALLOC(ccd_pt_face_t);
if (face == NULL)
return NULL;
face->type = CCD_PT_FACE;
face->edge[0] = e1;
face->edge[1] = e2;
face->edge[2] = e3;
// obtain triplet of vertices
a = &face->edge[0]->vertex[0]->v.v;
b = &face->edge[0]->vertex[1]->v.v;
e = face->edge[1];
if (e->vertex[0] != face->edge[0]->vertex[0]
&& e->vertex[0] != face->edge[0]->vertex[1]){
c = &e->vertex[0]->v.v;
}else{
c = &e->vertex[1]->v.v;
}
face->dist = ccdVec3PointTriDist2(ccd_vec3_origin, a, b, c, &face->witness);
for (i = 0; i < 3; i++){
if (face->edge[i]->faces[0] == NULL){
face->edge[i]->faces[0] = face;
}else{
face->edge[i]->faces[1] = face;
}
}
ccdListAppend(&pt->faces, &face->list);
// update position in .nearest array
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)face);
return face;
}
void ccdPtRecomputeDistances(ccd_pt_t *pt)
{
ccd_pt_vertex_t *v;
ccd_pt_edge_t *e;
ccd_pt_face_t *f;
const ccd_vec3_t *a, *b, *c;
ccd_real_t dist;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
dist = ccdVec3Len2(&v->v.v);
v->dist = dist;
ccdVec3Copy(&v->witness, &v->v.v);
}
ccdListForEachEntry(&pt->edges, e, ccd_pt_edge_t, list){
a = &e->vertex[0]->v.v;
b = &e->vertex[1]->v.v;
dist = ccdVec3PointSegmentDist2(ccd_vec3_origin, a, b, &e->witness);
e->dist = dist;
}
ccdListForEachEntry(&pt->faces, f, ccd_pt_face_t, list){
// obtain triplet of vertices
a = &f->edge[0]->vertex[0]->v.v;
b = &f->edge[0]->vertex[1]->v.v;
e = f->edge[1];
if (e->vertex[0] != f->edge[0]->vertex[0]
&& e->vertex[0] != f->edge[0]->vertex[1]){
c = &e->vertex[0]->v.v;
}else{
c = &e->vertex[1]->v.v;
}
dist = ccdVec3PointTriDist2(ccd_vec3_origin, a, b, c, &f->witness);
f->dist = dist;
}
}
ccd_pt_el_t *ccdPtNearest(ccd_pt_t *pt)
{
if (!pt->nearest){
_ccdPtNearestRenew(pt);
}
return pt->nearest;
}
void ccdPtDumpSVT(ccd_pt_t *pt, const char *fn)
{
FILE *fout;
fout = fopen(fn, "a");
if (fout == NULL)
return;
ccdPtDumpSVT2(pt, fout);
fclose(fout);
}
void ccdPtDumpSVT2(ccd_pt_t *pt, FILE *fout)
{
ccd_pt_vertex_t *v, *a, *b, *c;
ccd_pt_edge_t *e;
ccd_pt_face_t *f;
size_t i;
fprintf(fout, "-----\n");
fprintf(fout, "Points:\n");
i = 0;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
v->id = i++;
fprintf(fout, "%lf %lf %lf\n",
ccdVec3X(&v->v.v), ccdVec3Y(&v->v.v), ccdVec3Z(&v->v.v));
}
fprintf(fout, "Edges:\n");
ccdListForEachEntry(&pt->edges, e, ccd_pt_edge_t, list){
fprintf(fout, "%d %d\n", e->vertex[0]->id, e->vertex[1]->id);
}
fprintf(fout, "Faces:\n");
ccdListForEachEntry(&pt->faces, f, ccd_pt_face_t, list){
a = f->edge[0]->vertex[0];
b = f->edge[0]->vertex[1];
c = f->edge[1]->vertex[0];
if (c == a || c == b){
c = f->edge[1]->vertex[1];
}
fprintf(fout, "%d %d %d\n", a->id, b->id, c->id);
}
}

322
3rdparty/libccd/src/polytope.h vendored Normal file
View File

@ -0,0 +1,322 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_POLYTOPE_H__
#define __CCD_POLYTOPE_H__
#include <stdlib.h>
#include <stdio.h>
#include "support.h"
#include "list.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define CCD_PT_VERTEX 1
#define CCD_PT_EDGE 2
#define CCD_PT_FACE 3
#define __CCD_PT_EL \
int type; /*! type of element */ \
ccd_real_t dist; /*! distance from origin */ \
ccd_vec3_t witness; /*! witness point of projection of origin */ \
ccd_list_t list; /*! list of elements of same type */
/**
* General polytope element.
* Could be vertex, edge or triangle.
*/
struct _ccd_pt_el_t {
__CCD_PT_EL
};
typedef struct _ccd_pt_el_t ccd_pt_el_t;
struct _ccd_pt_edge_t;
struct _ccd_pt_face_t;
/**
* Polytope's vertex.
*/
struct _ccd_pt_vertex_t {
__CCD_PT_EL
int id;
ccd_support_t v;
ccd_list_t edges; //!< List of edges
};
typedef struct _ccd_pt_vertex_t ccd_pt_vertex_t;
/**
* Polytope's edge.
*/
struct _ccd_pt_edge_t {
__CCD_PT_EL
ccd_pt_vertex_t *vertex[2]; //!< Reference to vertices
struct _ccd_pt_face_t *faces[2]; //!< Reference to faces
ccd_list_t vertex_list[2]; //!< List items in vertices' lists
};
typedef struct _ccd_pt_edge_t ccd_pt_edge_t;
/**
* Polytope's triangle faces.
*/
struct _ccd_pt_face_t {
__CCD_PT_EL
ccd_pt_edge_t *edge[3]; //!< Reference to surrounding edges
};
typedef struct _ccd_pt_face_t ccd_pt_face_t;
/**
* Struct containing polytope.
*/
struct _ccd_pt_t {
ccd_list_t vertices; //!< List of vertices
ccd_list_t edges; //!< List of edges
ccd_list_t faces; //!< List of faces
ccd_pt_el_t *nearest;
ccd_real_t nearest_dist;
int nearest_type;
};
typedef struct _ccd_pt_t ccd_pt_t;
CCD_EXPORT void ccdPtInit(ccd_pt_t *pt);
CCD_EXPORT void ccdPtDestroy(ccd_pt_t *pt);
/**
* Returns vertices surrounding given triangle face.
*/
_ccd_inline void ccdPtFaceVec3(const ccd_pt_face_t *face,
ccd_vec3_t **a,
ccd_vec3_t **b,
ccd_vec3_t **c);
_ccd_inline void ccdPtFaceVertices(const ccd_pt_face_t *face,
ccd_pt_vertex_t **a,
ccd_pt_vertex_t **b,
ccd_pt_vertex_t **c);
_ccd_inline void ccdPtFaceEdges(const ccd_pt_face_t *f,
ccd_pt_edge_t **a,
ccd_pt_edge_t **b,
ccd_pt_edge_t **c);
_ccd_inline void ccdPtEdgeVec3(const ccd_pt_edge_t *e,
ccd_vec3_t **a,
ccd_vec3_t **b);
_ccd_inline void ccdPtEdgeVertices(const ccd_pt_edge_t *e,
ccd_pt_vertex_t **a,
ccd_pt_vertex_t **b);
_ccd_inline void ccdPtEdgeFaces(const ccd_pt_edge_t *e,
ccd_pt_face_t **f1,
ccd_pt_face_t **f2);
/**
* Adds vertex to polytope and returns pointer to newly created vertex.
*/
CCD_EXPORT ccd_pt_vertex_t *ccdPtAddVertex(ccd_pt_t *pt, const ccd_support_t *v);
_ccd_inline ccd_pt_vertex_t *ccdPtAddVertexCoords(ccd_pt_t *pt,
ccd_real_t x, ccd_real_t y, ccd_real_t z);
/**
* Adds edge to polytope.
*/
CCD_EXPORT ccd_pt_edge_t *ccdPtAddEdge(ccd_pt_t *pt, ccd_pt_vertex_t *v1,
ccd_pt_vertex_t *v2);
/**
* Adds face to polytope.
*/
CCD_EXPORT ccd_pt_face_t *ccdPtAddFace(ccd_pt_t *pt, ccd_pt_edge_t *e1,
ccd_pt_edge_t *e2,
ccd_pt_edge_t *e3);
/**
* Deletes vertex from polytope.
* Returns 0 on success, -1 otherwise.
*/
_ccd_inline int ccdPtDelVertex(ccd_pt_t *pt, ccd_pt_vertex_t *);
_ccd_inline int ccdPtDelEdge(ccd_pt_t *pt, ccd_pt_edge_t *);
_ccd_inline int ccdPtDelFace(ccd_pt_t *pt, ccd_pt_face_t *);
/**
* Recompute distances from origin for all elements in pt.
*/
CCD_EXPORT void ccdPtRecomputeDistances(ccd_pt_t *pt);
/**
* Returns nearest element to origin.
*/
CCD_EXPORT ccd_pt_el_t *ccdPtNearest(ccd_pt_t *pt);
CCD_EXPORT void ccdPtDumpSVT(ccd_pt_t *pt, const char *fn);
CCD_EXPORT void ccdPtDumpSVT2(ccd_pt_t *pt, FILE *);
/**** INLINES ****/
_ccd_inline ccd_pt_vertex_t *ccdPtAddVertexCoords(ccd_pt_t *pt,
ccd_real_t x, ccd_real_t y, ccd_real_t z)
{
ccd_support_t s;
ccdVec3Set(&s.v, x, y, z);
return ccdPtAddVertex(pt, &s);
}
_ccd_inline int ccdPtDelVertex(ccd_pt_t *pt, ccd_pt_vertex_t *v)
{
// test if any edge is connected to this vertex
if (!ccdListEmpty(&v->edges))
return -1;
// delete vertex from main list
ccdListDel(&v->list);
if ((void *)pt->nearest == (void *)v){
pt->nearest = NULL;
}
free(v);
return 0;
}
_ccd_inline int ccdPtDelEdge(ccd_pt_t *pt, ccd_pt_edge_t *e)
{
// text if any face is connected to this edge (faces[] is always
// aligned to lower indices)
if (e->faces[0] != NULL)
return -1;
// disconnect edge from lists of edges in vertex struct
ccdListDel(&e->vertex_list[0]);
ccdListDel(&e->vertex_list[1]);
// disconnect edge from main list
ccdListDel(&e->list);
if ((void *)pt->nearest == (void *)e){
pt->nearest = NULL;
}
free(e);
return 0;
}
_ccd_inline int ccdPtDelFace(ccd_pt_t *pt, ccd_pt_face_t *f)
{
ccd_pt_edge_t *e;
size_t i;
// remove face from edges' recerence lists
for (i = 0; i < 3; i++){
e = f->edge[i];
if (e->faces[0] == f){
e->faces[0] = e->faces[1];
}
e->faces[1] = NULL;
}
// remove face from list of all faces
ccdListDel(&f->list);
if ((void *)pt->nearest == (void *)f){
pt->nearest = NULL;
}
free(f);
return 0;
}
_ccd_inline void ccdPtFaceVec3(const ccd_pt_face_t *face,
ccd_vec3_t **a,
ccd_vec3_t **b,
ccd_vec3_t **c)
{
*a = &face->edge[0]->vertex[0]->v.v;
*b = &face->edge[0]->vertex[1]->v.v;
if (face->edge[1]->vertex[0] != face->edge[0]->vertex[0]
&& face->edge[1]->vertex[0] != face->edge[0]->vertex[1]){
*c = &face->edge[1]->vertex[0]->v.v;
}else{
*c = &face->edge[1]->vertex[1]->v.v;
}
}
_ccd_inline void ccdPtFaceVertices(const ccd_pt_face_t *face,
ccd_pt_vertex_t **a,
ccd_pt_vertex_t **b,
ccd_pt_vertex_t **c)
{
*a = face->edge[0]->vertex[0];
*b = face->edge[0]->vertex[1];
if (face->edge[1]->vertex[0] != face->edge[0]->vertex[0]
&& face->edge[1]->vertex[0] != face->edge[0]->vertex[1]){
*c = face->edge[1]->vertex[0];
}else{
*c = face->edge[1]->vertex[1];
}
}
_ccd_inline void ccdPtFaceEdges(const ccd_pt_face_t *f,
ccd_pt_edge_t **a,
ccd_pt_edge_t **b,
ccd_pt_edge_t **c)
{
*a = f->edge[0];
*b = f->edge[1];
*c = f->edge[2];
}
_ccd_inline void ccdPtEdgeVec3(const ccd_pt_edge_t *e,
ccd_vec3_t **a,
ccd_vec3_t **b)
{
*a = &e->vertex[0]->v.v;
*b = &e->vertex[1]->v.v;
}
_ccd_inline void ccdPtEdgeVertices(const ccd_pt_edge_t *e,
ccd_pt_vertex_t **a,
ccd_pt_vertex_t **b)
{
*a = e->vertex[0];
*b = e->vertex[1];
}
_ccd_inline void ccdPtEdgeFaces(const ccd_pt_edge_t *e,
ccd_pt_face_t **f1,
ccd_pt_face_t **f2)
{
*f1 = e->faces[0];
*f2 = e->faces[1];
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_POLYTOPE_H__ */

104
3rdparty/libccd/src/simplex.h vendored Normal file
View File

@ -0,0 +1,104 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_SIMPLEX_H__
#define __CCD_SIMPLEX_H__
#include <ccd/compiler.h>
#include "support.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _ccd_simplex_t {
ccd_support_t ps[4];
int last; //!< index of last added point
};
typedef struct _ccd_simplex_t ccd_simplex_t;
_ccd_inline void ccdSimplexInit(ccd_simplex_t *s);
_ccd_inline int ccdSimplexSize(const ccd_simplex_t *s);
_ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s);
_ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s, int idx);
_ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx);
_ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v);
_ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_support_t *a);
_ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size);
_ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2);
/**** INLINES ****/
_ccd_inline void ccdSimplexInit(ccd_simplex_t *s)
{
s->last = -1;
}
_ccd_inline int ccdSimplexSize(const ccd_simplex_t *s)
{
return s->last + 1;
}
_ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s)
{
return ccdSimplexPoint(s, s->last);
}
_ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s, int idx)
{
// here is no check on boundaries
return &s->ps[idx];
}
_ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx)
{
return &s->ps[idx];
}
_ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v)
{
// here is no check on boundaries in sake of speed
++s->last;
ccdSupportCopy(s->ps + s->last, v);
}
_ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_support_t *a)
{
ccdSupportCopy(s->ps + pos, a);
}
_ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size)
{
s->last = size - 1;
}
_ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2)
{
ccd_support_t supp;
ccdSupportCopy(&supp, &s->ps[pos1]);
ccdSupportCopy(&s->ps[pos1], &s->ps[pos2]);
ccdSupportCopy(&s->ps[pos2], &supp);
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_SIMPLEX_H__ */

34
3rdparty/libccd/src/support.c vendored Normal file
View File

@ -0,0 +1,34 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#include "support.h"
void __ccdSupport(const void *obj1, const void *obj2,
const ccd_vec3_t *_dir, const ccd_t *ccd,
ccd_support_t *supp)
{
ccd_vec3_t dir;
ccdVec3Copy(&dir, _dir);
ccd->support1(obj1, &dir, &supp->v1);
ccdVec3Scale(&dir, -CCD_ONE);
ccd->support2(obj2, &dir, &supp->v2);
ccdVec3Sub2(&supp->v, &supp->v1, &supp->v2);
}

55
3rdparty/libccd/src/support.h vendored Normal file
View File

@ -0,0 +1,55 @@
/***
* libccd
* ---------------------------------
* Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of libccd.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __CCD_SUPPORT_H__
#define __CCD_SUPPORT_H__
#include <ccd/ccd.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _ccd_support_t {
ccd_vec3_t v; //!< Support point in minkowski sum
ccd_vec3_t v1; //!< Support point in obj1
ccd_vec3_t v2; //!< Support point in obj2
};
typedef struct _ccd_support_t ccd_support_t;
_ccd_inline void ccdSupportCopy(ccd_support_t *, const ccd_support_t *s);
/**
* Computes support point of obj1 and obj2 in direction dir.
* Support point is returned via supp.
*/
CCD_EXPORT void __ccdSupport(const void *obj1, const void *obj2,
const ccd_vec3_t *dir, const ccd_t *ccd,
ccd_support_t *supp);
/**** INLINES ****/
_ccd_inline void ccdSupportCopy(ccd_support_t *d, const ccd_support_t *s)
{
*d = *s;
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_SUPPORT_H__ */

View File

@ -0,0 +1,6 @@
regressions/tmp.*
bench-out/*
*.o
test
bench
bench2

View File

@ -0,0 +1,53 @@
add_subdirectory(cu)
set(MAIN_SOURCES
main.c
common.c
common.h
support.c
support.h
vec3.c
vec3.h
polytope.c
polytope.h
boxbox.c
boxbox.h
spheresphere.c
spheresphere.h
cylcyl.c
cylcyl.h
boxcyl.c
boxcyl.h
mpr_boxbox.c
mpr_boxbox.h
mpr_cylcyl.c
mpr_cylcyl.h
mpr_boxcyl.c
mpr_boxcyl.h
support.c
support.h)
add_executable(main ${MAIN_SOURCES})
target_link_libraries(main ccd cu)
add_test(NAME main COMMAND main)
if(NOT APPLE)
set(BENCH_SOURCES
bench.c
support.c
support.h)
add_executable(bench ${BENCH_SOURCES})
target_link_libraries(bench ccd cu)
add_test(NAME bench COMMAND bench)
set(BENCH2_SOURCES
bench2.c
support.c
support.h)
add_executable(bench2 ${BENCH2_SOURCES})
target_link_libraries(bench2 ccd cu)
add_test(NAME bench2 COMMAND bench2)
endif()

61
3rdparty/libccd/src/testsuites/Makefile vendored Normal file
View File

@ -0,0 +1,61 @@
# force some options
DEBUG = yes
-include ../Makefile.include
CFLAGS += -I./ -I../ -Icu/
LDFLAGS += -L./ -Lcu/ -lcu -lrt -lm -L../ -lccd
CHECK_REG=cu/check-regressions
CHECK_TS ?=
OBJS = common.o support.o vec3.o polytope.o boxbox.o spheresphere.o \
cylcyl.o boxcyl.o mpr_boxbox.o mpr_cylcyl.o mpr_boxcyl.o
BENCH_OBJS = bench-boxbox.o
all: test bench bench2
test: cu $(OBJS) main.c
$(CC) $(CFLAGS) -o $@ main.c $(OBJS) $(LDFLAGS)
bench: cu bench.c support.o
$(CC) $(CFLAGS) -o $@ bench.c support.o $(LDFLAGS)
bench2: cu bench2.c support.o
$(CC) $(CFLAGS) -o $@ bench2.c support.o $(LDFLAGS)
%.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
check: all
@echo ""
@echo "----------------------------------------";
./test $(CHECK_TS)
@echo "----------------------------------------";
@echo "Checking regressions:";
$(PYTHON) $(CHECK_REG) regressions
@echo ""
check-valgrind: all
valgrind -q --leak-check=full --show-reachable=yes --trace-children=yes \
--error-limit=no \
./test $(CHECK_TS)
check-valgrind-gen-suppressions: all
valgrind -q --leak-check=full --show-reachable=yes --trace-children=yes \
--gen-suppressions=all --log-file=out --error-limit=no \
./test $(CHECK_TS)
cu:
$(MAKE) ENABLE_TIMER=yes -C cu/
clean:
rm -f *.o
rm -f objs/*.o
rm -f test bench bench2
rm -f tmp.*
rm -f regressions/tmp.*
.PHONY: all clean check check-valgrind cu

View File

@ -0,0 +1,28 @@
SUBDIRS = cu
AM_CPPFLAGS = -I $(srcdir)/.. -I $(builddir)/.. -I $(srcdir)/cu
LDADD = $(builddir)/cu/libcu.la $(builddir)/../libccd.la
check_PROGRAMS = test bench bench2
test_SOURCES = main.c \
common.c common.h \
support.c support.h \
vec3.c vec3.h \
polytope.c polytope.h \
boxbox.c boxbox.h \
spheresphere.c spheresphere.h \
cylcyl.c cylcyl.h \
boxcyl.c boxcyl.h \
mpr_boxbox.c mpr_boxbox.h \
mpr_cylcyl.c mpr_cylcyl.h \
mpr_boxcyl.c mpr_boxcyl.h
bench_SOURCES = bench.c \
support.c support.h
bench2_SOURCES = bench2.c \
support.c support.h

256
3rdparty/libccd/src/testsuites/bench.c vendored Normal file
View File

@ -0,0 +1,256 @@
#define CU_ENABLE_TIMER
#include <cu/cu.h>
#include <stdio.h>
#include <stdlib.h>
#include <ccd/ccd.h>
#include "support.h"
TEST_SUITES {
TEST_SUITES_CLOSURE
};
static int bench_num = 1;
static size_t cycles = 10000;
static void runBench(const void *o1, const void *o2, const ccd_t *ccd)
{
ccd_real_t depth;
ccd_vec3_t dir, pos;
size_t i;
const struct timespec *timer;
cuTimerStart();
for (i = 0; i < cycles; i++){
ccdGJKPenetration(o1, o2, ccd, &depth, &dir, &pos);
}
timer = cuTimerStop();
fprintf(stdout, "%02d: %ld %ld\n", bench_num,
(long)timer->tv_sec, (long)timer->tv_nsec);
fflush(stdout);
bench_num++;
}
static void boxbox(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
ccd_vec3_t axis;
ccd_quat_t rot;
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
bench_num = 1;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0., 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 1., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = 0.2; box2.y = 0.5; box2.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 0., 0.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -1.3, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
fprintf(stdout, "\n----\n\n");
}
void cylcyl(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_CYL(cyl1);
CCD_CYL(cyl2);
ccd_vec3_t axis;
cyl1.radius = 0.35;
cyl1.height = 0.5;
cyl2.radius = 0.5;
cyl2.height = 1.;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&cyl1.pos, 0.3, 0.1, 0.1);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0., 0., 0.);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, -0.2, 0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0.567, 1.2, 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, -4.567, 1.2, 0.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
fprintf(stdout, "\n----\n\n");
}
void boxcyl(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
ccd_vec3_t axis;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0., 0.);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
fprintf(stdout, "\n----\n\n");
}
int main(int argc, char *argv[])
{
if (argc > 1){
cycles = atol(argv[1]);
}
fprintf(stdout, "Cycles: %u\n", (unsigned int)cycles);
fprintf(stdout, "\n");
boxbox();
cylcyl();
boxcyl();
return 0;
}

262
3rdparty/libccd/src/testsuites/bench2.c vendored Normal file
View File

@ -0,0 +1,262 @@
#define CU_ENABLE_TIMER
#include <cu/cu.h>
#include <stdio.h>
#include <stdlib.h>
#include <ccd/ccd.h>
#include "support.h"
TEST_SUITES {
TEST_SUITES_CLOSURE
};
static int bench_num = 1;
static size_t cycles = 10000;
static void runBench(const void *o1, const void *o2, const ccd_t *ccd)
{
ccd_real_t depth;
ccd_vec3_t dir, pos;
size_t i;
const struct timespec *timer;
cuTimerStart();
for (i = 0; i < cycles; i++){
ccdMPRPenetration(o1, o2, ccd, &depth, &dir, &pos);
}
timer = cuTimerStop();
fprintf(stdout, "%02d: %ld %ld\n", bench_num,
(long)timer->tv_sec, (long)timer->tv_nsec);
fflush(stdout);
bench_num++;
}
static void boxbox(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
ccd_vec3_t axis;
ccd_quat_t rot;
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
bench_num = 1;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0., 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 1., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = 0.2; box2.y = 0.5; box2.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 0., 0.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -1.3, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
fprintf(stdout, "\n----\n\n");
}
void cylcyl(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_CYL(cyl1);
CCD_CYL(cyl2);
ccd_vec3_t axis;
cyl1.radius = 0.35;
cyl1.height = 0.5;
cyl2.radius = 0.5;
cyl2.height = 1.;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&cyl1.pos, 0.3, 0.1, 0.1);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0., 0., 0.);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, -0.2, 0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0.567, 1.2, 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, -4.567, 1.2, 0.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
fprintf(stdout, "\n----\n\n");
}
void boxcyl(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
ccd_vec3_t axis;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0., 0.);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
fprintf(stdout, "\n----\n\n");
}
int main(int argc, char *argv[])
{
if (argc > 1){
cycles = atol(argv[1]);
}
fprintf(stdout, "Cycles: %u\n", (unsigned int)cycles);
fprintf(stdout, "\n");
boxbox();
cylcyl();
boxcyl();
return 0;
}

466
3rdparty/libccd/src/testsuites/boxbox.c vendored Normal file
View File

@ -0,0 +1,466 @@
#include <stdio.h>
#include <cu/cu.h>
#include <ccd/ccd.h>
#include "support.h"
#include "../dbg.h"
#include "common.h"
TEST(boxboxSetUp)
{
}
TEST(boxboxTearDown)
{
}
TEST(boxboxAlignedX)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
//ccd.max_iterations = 20;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
box1.x = 0.1;
box1.y = 0.2;
box1.z = 0.1;
box2.x = 0.2;
box2.y = 0.1;
box2.z = 0.2;
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.01;
}
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., -0.1, 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
}
TEST(boxboxAlignedY)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, 0., -5., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[1] += 0.1;
}
}
TEST(boxboxAlignedZ)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, 0., 0., -5.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[2] += 0.1;
}
}
TEST(boxboxRot)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t axis;
ccd_real_t angle;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., 0.5, 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 33 || i > 67){
assertFalse(res);
}else if (i != 33 && i != 67){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
box1.x = 1;
box1.y = 1;
box1.z = 1;
box2.x = 1;
box2.y = 1;
box2.z = 1;
ccdVec3Set(&box1.pos, -1.01, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
ccdVec3Set(&axis, 0., 1., 0.);
angle = 0.;
for (i = 0; i < 30; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i != 0 && i != 10 && i != 20){
assertTrue(res);
}else{
assertFalse(res);
}
angle += M_PI / 20.;
ccdQuatSetAngleAxis(&box1.quat, angle, &axis);
}
}
static void pConf(ccd_box_t *box1, ccd_box_t *box2, const ccd_vec3_t *v)
{
fprintf(stdout, "# box1.pos: [%lf %lf %lf]\n",
ccdVec3X(&box1->pos), ccdVec3Y(&box1->pos), ccdVec3Z(&box1->pos));
fprintf(stdout, "# box1->quat: [%lf %lf %lf %lf]\n",
box1->quat.q[0], box1->quat.q[1], box1->quat.q[2], box1->quat.q[3]);
fprintf(stdout, "# box2->pos: [%lf %lf %lf]\n",
ccdVec3X(&box2->pos), ccdVec3Y(&box2->pos), ccdVec3Z(&box2->pos));
fprintf(stdout, "# box2->quat: [%lf %lf %lf %lf]\n",
box2->quat.q[0], box2->quat.q[1], box2->quat.q[2], box2->quat.q[3]);
fprintf(stdout, "# sep: [%lf %lf %lf]\n",
ccdVec3X(v), ccdVec3Y(v), ccdVec3Z(v));
fprintf(stdout, "#\n");
}
TEST(boxboxSeparate)
{
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t sep, expsep, expsep2, axis;
fprintf(stderr, "\n\n\n---- boxboxSeparate ----\n\n\n");
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.2);
res = ccdGJKIntersect(&box1, &box2, &ccd);
assertTrue(res);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0.25, 0., 0.);
assertTrue(ccdVec3Eq(&sep, &expsep));
ccdVec3Scale(&sep, -1.);
ccdVec3Add(&box1.pos, &sep);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., 0.);
assertTrue(ccdVec3Eq(&sep, &expsep));
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., -0.25);
assertTrue(ccdVec3Eq(&sep, &expsep));
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0., 0., 0.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., 1.);
ccdVec3Set(&expsep2, 0., 0., -1.);
assertTrue(ccdVec3Eq(&sep, &expsep) || ccdVec3Eq(&sep, &expsep2));
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
pConf(&box1, &box2, &sep);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
pConf(&box1, &box2, &sep);
}
#define TOSVT() \
svtObjPen(&box1, &box2, stdout, "Pen 1", depth, &dir, &pos); \
ccdVec3Scale(&dir, depth); \
ccdVec3Add(&box2.pos, &dir); \
svtObjPen(&box1, &box2, stdout, "Pen 1", depth, &dir, &pos)
TEST(boxboxPenetration)
{
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t axis;
ccd_quat_t rot;
ccd_real_t depth;
ccd_vec3_t dir, pos;
fprintf(stderr, "\n\n\n---- boxboxPenetration ----\n\n\n");
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&box2.pos, 0.1, 0., 0.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
//TOSVT();
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 2");
//TOSVT(); <<<
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0.1, 0., 0.1);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 3");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 4");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 5");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&box2.pos, 0.1, 0., 0.);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 6");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 1., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 7");
//TOSVT(); <<<
box1.x = box1.y = box1.z = 1.;
box2.x = 0.2; box2.y = 0.5; box2.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 0., 0.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -1.3, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 8");
//TOSVT();
}

32
3rdparty/libccd/src/testsuites/boxbox.h vendored Normal file
View File

@ -0,0 +1,32 @@
#ifndef BOX_BOX
#define BOX_BOX
#include <cu/cu.h>
TEST(boxboxSetUp);
TEST(boxboxTearDown);
TEST(boxboxAlignedX);
TEST(boxboxAlignedY);
TEST(boxboxAlignedZ);
TEST(boxboxRot);
TEST(boxboxSeparate);
TEST(boxboxPenetration);
TEST_SUITE(TSBoxBox) {
TEST_ADD(boxboxSetUp),
TEST_ADD(boxboxAlignedX),
TEST_ADD(boxboxAlignedY),
TEST_ADD(boxboxAlignedZ),
TEST_ADD(boxboxRot),
TEST_ADD(boxboxSeparate),
TEST_ADD(boxboxPenetration),
TEST_ADD(boxboxTearDown),
TEST_SUITE_CLOSURE
};
#endif

162
3rdparty/libccd/src/testsuites/boxcyl.c vendored Normal file
View File

@ -0,0 +1,162 @@
#include <cu/cu.h>
#include <ccd/ccd.h>
#include "common.h"
#include "support.h"
#define TOSVT() \
svtObjPen(&box, &cyl, stdout, "Pen 1", depth, &dir, &pos); \
ccdVec3Scale(&dir, depth); \
ccdVec3Add(&cyl.pos, &dir); \
svtObjPen(&box, &cyl, stdout, "Pen 1", depth, &dir, &pos)
TEST(boxcylIntersect)
{
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
int res;
ccd_vec3_t axis;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&cyl.pos, 0.1, 0., 0.);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0., 0.);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
}
TEST(boxcylPenEPA)
{
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
int res;
ccd_vec3_t axis;
ccd_real_t depth;
ccd_vec3_t dir, pos;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&cyl.pos, 0.1, 0., 0.);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
//TOSVT();
ccdVec3Set(&cyl.pos, .6, 0., 0.);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 2");
//TOSVT(); <<<
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 3");
//TOSVT();
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 4");
//TOSVT();
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 5");
//TOSVT();
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 6");
//TOSVT();
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 7");
//TOSVT();
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 8");
//TOSVT();
}

16
3rdparty/libccd/src/testsuites/boxcyl.h vendored Normal file
View File

@ -0,0 +1,16 @@
#ifndef TEST_BOXCYL_H
#define TEST_BOXCYL_H
#include <cu/cu.h>
TEST(boxcylIntersect);
TEST(boxcylPenEPA);
TEST_SUITE(TSBoxCyl){
TEST_ADD(boxcylIntersect),
TEST_ADD(boxcylPenEPA),
TEST_SUITE_CLOSURE
};
#endif

174
3rdparty/libccd/src/testsuites/common.c vendored Normal file
View File

@ -0,0 +1,174 @@
#include <ccd/vec3.h>
#include <ccd/quat.h>
#include "common.h"
#include "support.h"
static void svtCyl(ccd_cyl_t *c, FILE *out, const char *color, const char *name)
{
ccd_vec3_t v[32];
ccd_quat_t rot;
ccd_vec3_t axis, vpos, vpos2;
ccd_real_t angle, x, y;
int i;
ccdVec3Set(&axis, 0., 0., 1.);
ccdVec3Set(&vpos, 0., c->radius, 0.);
angle = 0.;
for (i = 0; i < 16; i++){
angle = (ccd_real_t)i * (2. * M_PI / 16.);
ccdQuatSetAngleAxis(&rot, angle, &axis);
ccdVec3Copy(&vpos2, &vpos);
ccdQuatRotVec(&vpos2, &rot);
x = ccdVec3X(&vpos2);
y = ccdVec3Y(&vpos2);
ccdVec3Set(&v[i], x, y, c->height / 2.);
ccdVec3Set(&v[i + 16], x, y, -c->height / 2.);
}
for (i = 0; i < 32; i++){
ccdQuatRotVec(&v[i], &c->quat);
ccdVec3Add(&v[i], &c->pos);
}
fprintf(out, "-----\n");
if (name)
fprintf(out, "Name: %s\n", name);
fprintf(out, "Face color: %s\n", color);
fprintf(out, "Edge color: %s\n", color);
fprintf(out, "Point color: %s\n", color);
fprintf(out, "Points:\n");
for (i = 0; i < 32; i++){
fprintf(out, "%lf %lf %lf\n", ccdVec3X(&v[i]), ccdVec3Y(&v[i]), ccdVec3Z(&v[i]));
}
fprintf(out, "Edges:\n");
fprintf(out, "0 16\n");
fprintf(out, "0 31\n");
for (i = 1; i < 16; i++){
fprintf(out, "0 %d\n", i);
fprintf(out, "16 %d\n", i + 16);
if (i != 0){
fprintf(out, "%d %d\n", i - 1, i);
fprintf(out, "%d %d\n", i + 16 - 1, i + 16);
}
fprintf(out, "%d %d\n", i, i + 16);
fprintf(out, "%d %d\n", i, i + 16 - 1);
}
fprintf(out, "Faces:\n");
for (i = 2; i < 16; i++){
fprintf(out, "0 %d %d\n", i, i -1);
fprintf(out, "16 %d %d\n", i + 16, i + 16 -1);
}
fprintf(out, "0 16 31\n");
fprintf(out, "0 31 15\n");
for (i = 1; i < 16; i++){
fprintf(out, "%d %d %d\n", i, i + 16, i + 16 - 1);
fprintf(out, "%d %d %d\n", i, i + 16 - 1, i - 1);
}
fprintf(out, "-----\n");
}
static void svtBox(ccd_box_t *b, FILE *out, const char *color, const char *name)
{
ccd_vec3_t v[8];
size_t i;
ccdVec3Set(&v[0], b->x * 0.5, b->y * 0.5, b->z * 0.5);
ccdVec3Set(&v[1], b->x * 0.5, b->y * -0.5, b->z * 0.5);
ccdVec3Set(&v[2], b->x * 0.5, b->y * 0.5, b->z * -0.5);
ccdVec3Set(&v[3], b->x * 0.5, b->y * -0.5, b->z * -0.5);
ccdVec3Set(&v[4], b->x * -0.5, b->y * 0.5, b->z * 0.5);
ccdVec3Set(&v[5], b->x * -0.5, b->y * -0.5, b->z * 0.5);
ccdVec3Set(&v[6], b->x * -0.5, b->y * 0.5, b->z * -0.5);
ccdVec3Set(&v[7], b->x * -0.5, b->y * -0.5, b->z * -0.5);
for (i = 0; i < 8; i++){
ccdQuatRotVec(&v[i], &b->quat);
ccdVec3Add(&v[i], &b->pos);
}
fprintf(out, "-----\n");
if (name)
fprintf(out, "Name: %s\n", name);
fprintf(out, "Face color: %s\n", color);
fprintf(out, "Edge color: %s\n", color);
fprintf(out, "Point color: %s\n", color);
fprintf(out, "Points:\n");
for (i = 0; i < 8; i++){
fprintf(out, "%lf %lf %lf\n", ccdVec3X(&v[i]), ccdVec3Y(&v[i]), ccdVec3Z(&v[i]));
}
fprintf(out, "Edges:\n");
fprintf(out, "0 1\n 0 2\n2 3\n3 1\n1 2\n6 2\n1 7\n1 5\n");
fprintf(out, "5 0\n0 4\n4 2\n6 4\n6 5\n5 7\n6 7\n7 2\n7 3\n4 5\n");
fprintf(out, "Faces:\n");
fprintf(out, "0 2 1\n1 2 3\n6 2 4\n4 2 0\n4 0 5\n5 0 1\n");
fprintf(out, "5 1 7\n7 1 3\n6 4 5\n6 5 7\n2 6 7\n2 7 3\n");
fprintf(out, "-----\n");
}
void svtObj(void *_o, FILE *out, const char *color, const char *name)
{
ccd_obj_t *o = (ccd_obj_t *)_o;
if (o->type == CCD_OBJ_CYL){
svtCyl((ccd_cyl_t *)o, out, color, name);
}else if (o->type == CCD_OBJ_BOX){
svtBox((ccd_box_t *)o, out, color, name);
}
}
void svtObjPen(void *o1, void *o2,
FILE *out, const char *name,
ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos)
{
ccd_vec3_t sep;
char oname[500];
ccdVec3Copy(&sep, dir);
ccdVec3Scale(&sep, depth);
ccdVec3Add(&sep, pos);
fprintf(out, "------\n");
if (name)
fprintf(out, "Name: %s\n", name);
fprintf(out, "Point color: 0.1 0.1 0.9\n");
fprintf(out, "Points:\n%lf %lf %lf\n", ccdVec3X(pos), ccdVec3Y(pos), ccdVec3Z(pos));
fprintf(out, "------\n");
fprintf(out, "Point color: 0.1 0.9 0.9\n");
fprintf(out, "Edge color: 0.1 0.9 0.9\n");
fprintf(out, "Points:\n%lf %lf %lf\n", ccdVec3X(pos), ccdVec3Y(pos), ccdVec3Z(pos));
fprintf(out, "%lf %lf %lf\n", ccdVec3X(&sep), ccdVec3Y(&sep), ccdVec3Z(&sep));
fprintf(out, "Edges: 0 1\n");
oname[0] = 0x0;
if (name)
sprintf(oname, "%s o1", name);
svtObj(o1, out, "0.9 0.1 0.1", oname);
oname[0] = 0x0;
if (name)
sprintf(oname, "%s o1", name);
svtObj(o2, out, "0.1 0.9 0.1", oname);
}
void recPen(ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos,
FILE *out, const char *note)
{
if (!note)
note = "";
fprintf(out, "# %s: depth: %lf\n", note, depth);
fprintf(out, "# %s: dir: [%lf %lf %lf]\n", note, ccdVec3X(dir), ccdVec3Y(dir), ccdVec3Z(dir));
fprintf(out, "# %s: pos: [%lf %lf %lf]\n", note, ccdVec3X(pos), ccdVec3Y(pos), ccdVec3Z(pos));
fprintf(out, "#\n");
}

14
3rdparty/libccd/src/testsuites/common.h vendored Normal file
View File

@ -0,0 +1,14 @@
#ifndef TEST_COMMON
#define TEST_COMMON
#include <stdio.h>
#include <ccd/vec3.h>
void svtObj(void *o, FILE *out, const char *color, const char *name);
void svtObjPen(void *o1, void *o2,
FILE *out, const char *name,
ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos);
void recPen(ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos,
FILE *out, const char *note);
#endif

View File

View File

@ -0,0 +1,6 @@
*~
*.o
*.a
tmp.*
test

View File

@ -0,0 +1,17 @@
set(CU_SOURCES
cu.c
cu.h)
add_library(cu STATIC ${CU_SOURCES})
if(NOT APPLE)
target_compile_definitions(cu PUBLIC CU_ENABLE_TIMER)
find_library(LIBRT_LIBRARY NAMES rt)
if(NOT LIBRT_LIBRARY)
message(FATAL_ERROR "Could NOT find required library librt")
endif()
target_link_libraries(cu "${LIBRT_LIBRARY}")
endif()
get_filename_component(CU_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY)
target_include_directories(cu PUBLIC "${CU_INCLUDE_DIR}")

View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@ -0,0 +1,49 @@
CC ?= gcc
CFLAGS = -g -Wall -pedantic
ENABLE_TIMER ?= no
ifeq '$(ENABLE_TIMER)' 'yes'
CFLAGS += -DCU_ENABLE_TIMER
endif
TARGETS = libcu.a
TEST_OBJS = test.o test2.o
all: $(TARGETS)
libcu.a: cu.o
ar cr $@ $^
ranlib $@
cu.o: cu.c cu.h
$(CC) $(CFLAGS) -c -o $@ $<
test: $(TEST_OBJS) libcu.a
$(CC) $(CFLAGS) -o $@ $(TEST_OBJS) -L./ -lcu
test-segfault: test-segfault.c libcu.a
$(CC) $(CFLAGS) -o $@ $^ -L./ -lcu
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
check: test test-segfault
mkdir -p regressions
touch regressions/testSuiteName{,2}.{out,err}
touch regressions/testSuiteTest2.{out,err}
-./test
-cd regressions && ../check-regressions
@echo ""
@echo "======= SEGFAULT: ========="
@echo ""
-./test-segfault
clean:
rm -f *.o
rm -f test
rm -f test-segfault
rm -f $(TARGETS)
rm -f tmp.*
rm -rf regressions
.PHONY: all clean check

View File

@ -0,0 +1,6 @@
AM_CPPFLAGS = -DCU_ENABLE_TIMER
check_LTLIBRARIES = libcu.la
libcu_la_SOURCES = cu.c cu.h

View File

@ -0,0 +1,413 @@
#!/usr/bin/python
##
# CU - C unit testing framework
# ---------------------------------
# Copyright (c)2007,2008 Daniel Fiser <danfis@danfis.cz>
#
#
# This file is part of CU.
#
# CU is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version.
#
# CU is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from subprocess import Popen, PIPE
import os
import re
import sys
import math
from getopt import gnu_getopt, GetoptError
EPS = 0.6
BASE_DIR = "."
MAX_DIFF_LINES = 20
EXACT = False
PROGRESS_ON = True
MSG_BASE = ""
class Hunk:
""" This class represents one hunk from diff. """
def __init__(self):
self.added = []
self.deleted = []
self.lines = []
# to identify lines with floating point numbers
self.re_is_num = re.compile("^.*[0-9].*$")
# pattern to match floating point number
self.num_pattern = r"-?(?:(?:[0-9]+(?:\.[0-9]*)?)|(?:\.[0-9]+))(?:[eE]-?[0-9]+)?"
self.re_num = re.compile(self.num_pattern)
def numLines(self):
return len(self.lines)
def numLinesAdded(self):
return len(self.added)
def numLinesDeleted(self):
return len(self.deleted)
def addLineAdded(self, line):
self.added.append(line)
def addLineDeleted(self, line):
self.deleted.append(line)
def addLine(self, line):
self.lines.append(line)
def getLines(self):
return self.lines
def getLinesAdded(self):
return self.added
def getLinesDeleted(self):
return self.deleted
def __eq(self, num1, num2):
""" Returns True if num1 equals to num2 with respect to EPS
(defined above) """
return math.fabs(num1 - num2) < EPS
def checkFloats(self):
""" This method try to check if only difference between added and
deleted lines of this hunk is different precission of floating
point numbers
"""
# If number of added and deleted lines differs, then there is more
# differences that precission of floating point numbers
if self.numLinesAdded() != self.numLinesDeleted():
return False
for i in xrange(0, self.numLinesAdded()):
# if any line does not contain number - return False because
# there must be more differences than in numbers
if not self.re_is_num.match(self.added[i]) \
or not self.re_is_num.match(self.deleted[i]):
return False
line1 = self.added[i]
line2 = self.deleted[i]
# Extract all floating point numbers from each line
nums1 = self.re_num.findall(line1)
nums2 = self.re_num.findall(line2)
# and remove all empty strings
nums1 = filter(lambda x: len(x) > 0, nums1)
nums2 = filter(lambda x: len(x) > 0, nums2)
# if length of list nums1 does not equal to length of nums2
# return False
if len(nums1) != len(nums2):
return False
# iterate trough all numbers
for j in xrange(0, len(nums1)):
# if numbers do not equal to each other return False
if not self.__eq(float(nums1[j]), float(nums2[j])):
return False
# compare the rest of lines
line1 = self.re_num.sub("", line1)
line2 = self.re_num.sub("", line2)
if line1 != line2:
return False
# If it does not fail anywhere, added and deleted lines must be
# same
return True
class Diff:
""" Represents whole diff. """
def __init__(self):
self.hunks = []
self.lines = 0
self.omitted_lines = 0
def addHunk(self, hunk):
self.hunks.append(hunk)
self.lines += hunk.numLines()
def numLines(self):
return self.lines
def numOmittedLines(self):
return self.omitted_lines
def getHunks(self):
return self.hunks
def numHunks(self):
return len(self.hunks)
def checkFloats(self):
""" Will call method checkFloats on each hunk """
hks = self.hunks[:]
self.hunks = []
self.lines = 0
for h in hks:
if not h.checkFloats():
self.hunks.append(h)
self.lines += h.numLines()
else:
self.omitted_lines += h.numLines()
class Parser:
def __init__(self, fin):
self.fin = fin
self.line = ""
self.diff = Diff()
self.cur_hunk = None
# to recognize beginning of hunk:
self.re_hunk = re.compile(r"^[0-9]*(,[0-9]*){0,1}[a-zA-Z]?[0-9]*(,[0-9]*){0,1}$")
self.re_added = re.compile(r"^> (.*)$")
self.re_deleted = re.compile(r"^< (.*)$")
def __readNextLine(self):
self.line = self.fin.readline()
if len(self.line) == 0:
return False
return True
def parse(self):
global PROGRESS_ON
global MSG_BASE
num_lines = 0
while self.__readNextLine():
# beggining of hunk
if self.re_hunk.match(self.line):
if self.cur_hunk is not None:
self.diff.addHunk(self.cur_hunk)
self.cur_hunk = Hunk()
self.cur_hunk.addLine(self.line)
# line added
match = self.re_added.match(self.line)
if match is not None:
self.cur_hunk.addLine(self.line)
self.cur_hunk.addLineAdded(match.group(1))
# line deleted
match = self.re_deleted.match(self.line)
if match is not None:
self.cur_hunk.addLine(self.line)
self.cur_hunk.addLineDeleted(match.group(1))
num_lines += 1
if PROGRESS_ON and num_lines % 50 == 0:
print MSG_BASE, "[ %08d ]" % num_lines, "\r",
sys.stdout.flush()
# last push to list of hunks
if self.cur_hunk is not None:
self.diff.addHunk(self.cur_hunk)
if PROGRESS_ON:
print MSG_BASE, " ", "\r",
sys.stdout.flush()
def getDiff(self):
return self.diff
def regressionFilesInDir():
""" Returns sorted list of pairs of filenames where first name in pair
is tmp. file and second corresponding file with saved regressions.
"""
re_tmp_out_file = re.compile(r"tmp\.(.*\.out)")
re_tmp_err_file = re.compile(r"tmp\.(.*\.err)")
files = []
all_files = os.listdir(".")
all_files.sort()
for file in all_files:
res = re_tmp_out_file.match(file)
if res is not None:
fname = res.group(1)
tmp = [file, ""]
for file2 in all_files:
if file2 == fname:
tmp = [file, file2,]
break
files.append(tmp)
res = re_tmp_err_file.match(file)
if res is not None:
fname = res.group(1)
tmp = [file, ""]
for file2 in all_files:
if file2 == fname:
tmp = [file, file2,]
break
files.append(tmp)
return files
def MSG(str = "", wait = False):
if wait:
print str,
else:
print str
def MSGOK(prestr = "", str = "", poststr = ""):
print prestr, "\033[0;32m" + str + "\033[0;0m", poststr
def MSGFAIL(prestr = "", str = "", poststr = ""):
print prestr, "\033[0;31m" + str + "\033[0;0m", poststr
def MSGINFO(prestr = "", str = "", poststr = ""):
print prestr, "\033[0;33m" + str + "\033[0;0m", poststr
def dumpLines(lines, prefix = "", wait = False, max_lines = -1):
line_num = 0
if wait:
for line in lines:
print prefix, line,
line_num += 1
if max_lines >= 0 and line_num > max_lines:
break
else:
for line in lines:
print prefix, line
line_num += 1
if max_lines >= 0 and line_num > max_lines:
break
def main(files):
global MSG_BASE
# As first compute length of columns
len1 = 0
len2 = 0
for filenames in files:
if len(filenames[0]) > len1:
len1 = len(filenames[0])
if len(filenames[1]) > len2:
len2 = len(filenames[1])
for filenames in files:
if len(filenames[1]) == 0:
MSGFAIL("", "===", "Can't compare %s %s, bacause %s does not exist!" % \
(filenames[0], filenames[0][4:], filenames[0][4:]))
continue
cmd = ["diff", filenames[0], filenames[1]]
MSG_BASE = "Comparing %s and %s" % \
(filenames[0].ljust(len1) ,filenames[1].ljust(len2))
if not PROGRESS_ON:
print MSG_BASE,
sys.stdout.flush()
pipe = Popen(cmd, stdout=PIPE)
parser = Parser(pipe.stdout)
parser.parse()
diff = parser.getDiff()
if not EXACT:
diff.checkFloats()
if PROGRESS_ON:
print MSG_BASE,
if diff.numHunks() == 0:
MSGOK(" [", "OK", "]")
if diff.numOmittedLines() > 0:
MSGINFO(" -->", str(diff.numOmittedLines()) + " lines from diff omitted")
else:
MSGFAIL(" [", "FAILED", "]")
if diff.numOmittedLines() > 0:
MSGINFO(" -->", str(diff.numOmittedLines()) + " lines from diff omitted")
MSGINFO(" -->", "Diff has " + str(diff.numLines()) + " lines")
if diff.numLines() <= MAX_DIFF_LINES:
MSGINFO(" -->", "Diff:")
for h in diff.getHunks():
dumpLines(h.getLines(), " |", True)
else:
MSGINFO(" -->", "Printing only first " + str(MAX_DIFF_LINES) + " lines:")
lines = []
for h in diff.getHunks():
lines += h.getLines()
if len(lines) > MAX_DIFF_LINES:
break;
dumpLines(lines, " |", True, MAX_DIFF_LINES)
def usage():
print "Usage: " + sys.argv[0] + " [ OPTIONS ] [ directory, [ directory, [ ... ] ] ]"
print ""
print " OPTIONS:"
print " --help / -h none Print this help"
print " --exact / -e none Switch do exact comparasion of files"
print " --not-exact / -n none Switch do non exact comparasion of files (default behaviour)"
print " --max-diff-lines int Maximum of lines of diff which can be printed (default " + str(MAX_DIFF_LINES) + ")"
print " --eps float Precision of floating point numbers (epsilon) (default " + str(EPS) + ")"
print " --no-progress none Turn off progress bar"
print " --progress none Turn on progress bar (default)"
print ""
print " This program is able to compare files with regressions generated by CU testsuites."
print " You can specify directories which are to be searched for regression files."
print " In non exact copmarasion mode (which is default), this program tries to compare"
print " floating point numbers in files with respect to specified precision (see --eps) and"
print " those lines which differ only in precission of floating point numbers are omitted."
print ""
sys.exit(-1)
# Init:
# Set up base dir
BASE_DIR = os.getcwd()
# Parse command line options:
optlist, args = gnu_getopt(sys.argv[1:],
"hen",
["help", "max-diff-lines=", "eps=", \
"exact", "not-exact", \
"no-progress", "progress"])
for opt in optlist:
if opt[0] == "--help" or opt[0] == "-h":
usage()
if opt[0] == "--exact" or opt[0] == "-e":
EXACT = True
if opt[0] == "--not-exact" or opt[0] == "-n":
EXACT = False
if opt[0] == "--max-diff-lines":
MAX_DIFF_LINES = int(opt[1])
if opt[0] == "--eps":
EPS = float(opt[1])
if opt[0] == "--no-progress":
PROGRESS_ON = False
if opt[0] == "--progress":
PROGRESS_ON = True
if len(args) == 0:
files = regressionFilesInDir()
main(files)
else:
for dir in args:
os.chdir(BASE_DIR)
MSGINFO()
MSGINFO("", "Processing directory '" + dir + "':")
MSGINFO()
try:
os.chdir(dir)
except:
MSGFAIL(" -->", "Directory '" + dir + "' does not exist.")
files = regressionFilesInDir()
main(files)
sys.exit(0)

387
3rdparty/libccd/src/testsuites/cu/cu.c vendored Normal file
View File

@ -0,0 +1,387 @@
/***
* CU - C unit testing framework
* ---------------------------------
* Copyright (c)2007,2008,2009 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of CU.
*
* CU is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* CU is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include "cu.h"
/** Declared here, because I didn't find header file where it is declared */
char *strsignal(int sig);
const char *cu_current_test;
const char *cu_current_test_suite;
int cu_success_test_suites = 0;
int cu_fail_test_suites = 0;
int cu_success_tests = 0;
int cu_fail_tests = 0;
int cu_success_checks = 0;
int cu_fail_checks = 0;
char cu_out_prefix[CU_OUT_PREFIX_LENGTH+1] = "";
/* globally used file descriptor for reading/writing messages */
int fd;
/* indicate if test was failed */
int test_failed;
/* codes of messages */
#define CHECK_FAILED '0'
#define CHECK_SUCCEED '1'
#define TEST_FAILED '2'
#define TEST_SUCCEED '3'
#define TEST_SUITE_FAILED '4'
#define TEST_SUITE_SUCCEED '5'
#define END '6'
#define TEST_NAME '7'
/* predefined messages */
#define MSG_CHECK_SUCCEED write(fd, "1\n", 2)
#define MSG_TEST_FAILED write(fd, "2\n", 2)
#define MSG_TEST_SUCCEED write(fd, "3\n", 2)
#define MSG_TEST_SUITE_FAILED write(fd, "4\n", 2)
#define MSG_TEST_SUITE_SUCCEED write(fd, "5\n", 2)
#define MSG_END write(fd, "6\n", 2)
/* length of buffers */
#define BUF_LEN 1000
#define MSGBUF_LEN 300
static void redirect_out_err(const char *testName);
static void close_out_err(void);
static void run_test_suite(const char *ts_name, cu_test_suite_t *ts);
static void receive_messages(void);
static void cu_run_fork(const char *ts_name, cu_test_suite_t *test_suite);
static void cu_print_results(void);
void cu_run(int argc, char *argv[])
{
cu_test_suites_t *tss;
int i;
char found = 0;
if (argc > 1){
for (i=1; i < argc; i++){
tss = cu_test_suites;
while (tss->name != NULL && tss->test_suite != NULL){
if (strcmp(argv[i], tss->name) == 0){
found = 1;
cu_run_fork(tss->name, tss->test_suite);
break;
}
tss++;
}
if (tss->name == NULL || tss->test_suite == NULL){
fprintf(stderr, "ERROR: Could not find test suite '%s'\n", argv[i]);
}
}
if (found == 1)
cu_print_results();
}else{
tss = cu_test_suites;
while (tss->name != NULL && tss->test_suite != NULL){
cu_run_fork(tss->name, tss->test_suite);
tss++;
}
cu_print_results();
}
}
static void cu_run_fork(const char *ts_name, cu_test_suite_t *ts)
{
int pipefd[2];
int pid;
int status;
if (pipe(pipefd) == -1){
perror("Pipe error");
exit(-1);
}
fprintf(stdout, " -> %s [IN PROGESS]\n", ts_name);
fflush(stdout);
pid = fork();
if (pid < 0){
perror("Fork error");
exit(-1);
}
if (pid == 0){
/* close read end of pipe */
close(pipefd[0]);
fd = pipefd[1];
/* run testsuite, messages go to fd */
run_test_suite(ts_name, ts);
MSG_END;
close(fd);
/* stop process where running testsuite */
exit(0);
}else{
/* close write end of pipe */
close(pipefd[1]);
fd = pipefd[0];
/* receive and interpret all messages */
receive_messages();
/* wait for children */
wait(&status);
if (!WIFEXITED(status)){ /* if child process ends up abnormaly */
if (WIFSIGNALED(status)){
fprintf(stdout, "Test suite was terminated by signal %d (%s).\n",
WTERMSIG(status), strsignal(WTERMSIG(status)));
}else{
fprintf(stdout, "Test suite terminated abnormaly!\n");
}
/* mark this test suite as failed, because was terminated
* prematurely */
cu_fail_test_suites++;
}
close(fd);
fprintf(stdout, " -> %s [DONE]\n\n", ts_name);
fflush(stdout);
}
}
static void run_test_suite(const char *ts_name, cu_test_suite_t *ts)
{
int test_suite_failed = 0;
char buffer[MSGBUF_LEN];
int len;
/* set up current test suite name for later messaging... */
cu_current_test_suite = ts_name;
/* redirect stdout and stderr */
redirect_out_err(cu_current_test_suite);
while (ts->name != NULL && ts->func != NULL){
test_failed = 0;
/* set up name of test for later messaging */
cu_current_test = ts->name;
/* send message what test is currently running */
len = snprintf(buffer, MSGBUF_LEN, "%c --> Running %s...\n",
TEST_NAME, cu_current_test);
write(fd, buffer, len);
/* run test */
(*(ts->func))();
if (test_failed){
MSG_TEST_FAILED;
test_suite_failed = 1;
}else{
MSG_TEST_SUCCEED;
}
ts++; /* next test in test suite */
}
if (test_suite_failed){
MSG_TEST_SUITE_FAILED;
}else{
MSG_TEST_SUITE_SUCCEED;
}
/* close redirected stdout and stderr */
close_out_err();
}
static void receive_messages(void)
{
char buf[BUF_LEN]; /* buffer */
int buf_len; /* how many chars stored in buf */
char bufout[MSGBUF_LEN]; /* buffer which can be printed out */
int bufout_len;
int state = 0; /* 0 - waiting for code, 1 - copy msg to stdout */
int i;
int end = 0; /* end of messages? */
bufout_len = 0;
while((buf_len = read(fd, buf, BUF_LEN)) > 0 && !end){
for (i=0; i < buf_len; i++){
/* Prepare message for printing out */
if (state == 1 || state == 2){
if (bufout_len < MSGBUF_LEN)
bufout[bufout_len++] = buf[i];
}
/* reset state on '\n' in msg */
if (buf[i] == '\n'){
/* copy messages out */
if (state == 1)
write(1, bufout, bufout_len);
if (state == 2)
write(2, bufout, bufout_len);
state = 0;
bufout_len = 0;
continue;
}
if (state == 0){
if (buf[i] == CHECK_FAILED){
cu_fail_checks++;
state = 2;
}else if (buf[i] == TEST_NAME){
state = 1;
}else if (buf[i] == CHECK_SUCCEED){
cu_success_checks++;
}else if (buf[i] == TEST_FAILED){
cu_fail_tests++;
}else if (buf[i] == TEST_SUCCEED){
cu_success_tests++;
}else if (buf[i] == TEST_SUITE_FAILED){
cu_fail_test_suites++;
}else if (buf[i] == TEST_SUITE_SUCCEED){
cu_success_test_suites++;
}else if (buf[i] == END){
end = 1;
break;
}
}
}
}
}
void cu_success_assertation(void)
{
MSG_CHECK_SUCCEED;
}
void cu_fail_assertation(const char *file, int line, const char *msg)
{
char buf[MSGBUF_LEN];
int len;
len = snprintf(buf, MSGBUF_LEN, "%c%s:%d (%s::%s) :: %s\n",
CHECK_FAILED,
file, line, cu_current_test_suite, cu_current_test, msg);
write(fd, buf, len);
/* enable test_failed flag */
test_failed = 1;
}
static void cu_print_results(void)
{
fprintf(stdout, "\n");
fprintf(stdout, "==================================================\n");
fprintf(stdout, "| | failed | succeed | total |\n");
fprintf(stdout, "|------------------------------------------------|\n");
fprintf(stdout, "| assertations: | %6d | %7d | %5d |\n",
cu_fail_checks, cu_success_checks,
cu_success_checks+cu_fail_checks);
fprintf(stdout, "| tests: | %6d | %7d | %5d |\n",
cu_fail_tests, cu_success_tests,
cu_success_tests+cu_fail_tests);
fprintf(stdout, "| tests suites: | %6d | %7d | %5d |\n",
cu_fail_test_suites, cu_success_test_suites,
cu_success_test_suites+cu_fail_test_suites);
fprintf(stdout, "==================================================\n");
}
void cu_set_out_prefix(const char *str)
{
strncpy(cu_out_prefix, str, CU_OUT_PREFIX_LENGTH);
}
static void redirect_out_err(const char *test_name)
{
char buf[100];
snprintf(buf, 99, "%stmp.%s.out", cu_out_prefix, test_name);
if (freopen(buf, "w", stdout) == NULL){
perror("Redirecting of stdout failed");
exit(-1);
}
snprintf(buf, 99, "%stmp.%s.err", cu_out_prefix, test_name);
if (freopen(buf, "w", stderr) == NULL){
perror("Redirecting of stderr failed");
exit(-1);
}
}
static void close_out_err(void)
{
fclose(stdout);
fclose(stderr);
}
#ifdef CU_ENABLE_TIMER
/* global variables for timer functions */
struct timespec __cu_timer;
static struct timespec __cu_timer_start, __cu_timer_stop;
const struct timespec *cuTimer(void)
{
return &__cu_timer;
}
void cuTimerStart(void)
{
clock_gettime(CLOCK_MONOTONIC, &__cu_timer_start);
}
const struct timespec *cuTimerStop(void)
{
clock_gettime(CLOCK_MONOTONIC, &__cu_timer_stop);
/* store into t difference between time_start and time_end */
if (__cu_timer_stop.tv_nsec > __cu_timer_start.tv_nsec){
__cu_timer.tv_nsec = __cu_timer_stop.tv_nsec - __cu_timer_start.tv_nsec;
__cu_timer.tv_sec = __cu_timer_stop.tv_sec - __cu_timer_start.tv_sec;
}else{
__cu_timer.tv_nsec = __cu_timer_stop.tv_nsec + 1000000000L - __cu_timer_start.tv_nsec;
__cu_timer.tv_sec = __cu_timer_stop.tv_sec - 1 - __cu_timer_start.tv_sec;
}
return &__cu_timer;
}
#endif /* CU_ENABLE_TIMER */

164
3rdparty/libccd/src/testsuites/cu/cu.h vendored Normal file
View File

@ -0,0 +1,164 @@
/***
* CU - C unit testing framework
* ---------------------------------
* Copyright (c)2007,2008,2009 Daniel Fiser <danfis@danfis.cz>
*
*
* This file is part of CU.
*
* CU is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* CU is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CU_H_
#define _CU_H_
#ifdef CU_ENABLE_TIMER
# include <time.h>
#endif /* CU_ENABLE_TIMER */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/***** PUBLIC API *****/
/**
* Define test
*/
#define TEST(name) \
void name(void)
/**
* Define testsuite
*/
#define TEST_SUITE(name) \
cu_test_suite_t test_suite_##name[] =
/**
* Must be on the end of list of tests.
*/
#define TEST_SUITE_CLOSURE \
{ NULL, NULL }
#define TEST_SUITES \
cu_test_suites_t cu_test_suites[] =
#define TEST_SUITES_CLOSURE \
{ NULL, NULL }
#define TEST_SUITE_ADD(name) \
{ #name, test_suite_##name }
/**
* Add test to testsuite
*/
#define TEST_ADD(name) \
{ #name, name }
#define CU_RUN(argc, argv) \
cu_run(argc, argv)
/**
* Set prefix for files printed out. Must contain trailing /.
*/
#define CU_SET_OUT_PREFIX(str) \
cu_set_out_prefix(str)
/**
* Assertations
* Assertations with suffix 'M' (e.g. assertTrueM) is variation of macro
* where is possible to specify error message.
*/
#define assertTrueM(a, message) \
if (a){ \
cu_success_assertation(); \
}else{ \
cu_fail_assertation(__FILE__, __LINE__, message); \
}
#define assertTrue(a) \
assertTrueM((a), #a " is not true")
#define assertFalseM(a, message) \
assertTrueM(!(a), message)
#define assertFalse(a) \
assertFalseM((a), #a " is not false")
#define assertEqualsM(a,b,message) \
assertTrueM((a) == (b), message)
#define assertEquals(a,b) \
assertEqualsM((a), (b), #a " not equals " #b)
#define assertNotEqualsM(a,b,message) \
assertTrueM((a) != (b), message)
#define assertNotEquals(a,b) \
assertNotEqualsM((a), (b), #a " equals " #b)
/***** PUBLIC API END *****/
#include <unistd.h>
#define CU_MAX_NAME_LENGTH 30
typedef void (*cu_test_func_t)(void);
typedef struct _cu_test_suite_t {
const char *name;
cu_test_func_t func;
} cu_test_suite_t;
typedef struct _cu_test_suites_t {
const char *name;
cu_test_suite_t *test_suite;
} cu_test_suites_t;
extern cu_test_suites_t cu_test_suites[];
extern const char *cu_current_test;
extern const char *cu_current_test_suite;
extern int cu_success_test_suites;
extern int cu_fail_test_suites;
extern int cu_success_tests;
extern int cu_fail_tests;
extern int cu_success_checks;
extern int cu_fail_checks;
#define CU_OUT_PREFIX_LENGTH 30
extern char cu_out_prefix[CU_OUT_PREFIX_LENGTH+1];
void cu_run(int argc, char *argv[]);
void cu_success_assertation(void);
void cu_fail_assertation(const char *file, int line, const char *msg);
void cu_set_out_prefix(const char *str);
/** Timer **/
#ifdef CU_ENABLE_TIMER
extern struct timespec __cu_timer;
/**
* Returns value of timer. (as timespec struct)
*/
const struct timespec *cuTimer(void);
/**
* Starts timer.
*/
void cuTimerStart(void);
/**
* Stops timer and record elapsed time from last call of cuTimerStart().
* Returns current value of timer.
*/
const struct timespec *cuTimerStop(void);
#endif /* CU_ENABLE_TIMER */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

17
3rdparty/libccd/src/testsuites/cu/latest.sh vendored Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
repo=http://git.danfis.cz/cu.git
files="COPYING \
COPYING.LESSER \
cu.h \
cu.c \
Makefile \
check-regressions \
.gitignore \
"
rm -rf cu
git clone $repo
for file in $files; do
mv cu/"$file" .
done;
rm -rf cu

180
3rdparty/libccd/src/testsuites/cylcyl.c vendored Normal file
View File

@ -0,0 +1,180 @@
#include <stdio.h>
#include <cu/cu.h>
#include <ccd/ccd.h>
#include "support.h"
#include "common.h"
TEST(cylcylSetUp)
{
}
TEST(cylcylTearDown)
{
}
TEST(cylcylAlignedX)
{
ccd_t ccd;
CCD_CYL(c1);
CCD_CYL(c2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
c1.radius = 0.35;
c1.height = 0.5;
c2.radius = 0.5;
c2.height = 1.;
ccdVec3Set(&c1.pos, -5., 0., 0.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&c1, &c2, &ccd);
if (i < 42 || i > 58){
assertFalse(res);
}else{
assertTrue(res);
}
c1.pos.v[0] += 0.1;
}
}
TEST(cylcylAlignedY)
{
ccd_t ccd;
CCD_CYL(c1);
CCD_CYL(c2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
c1.radius = 0.35;
c1.height = 0.5;
c2.radius = 0.5;
c2.height = 1.;
ccdVec3Set(&c1.pos, 0., -5., 0.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&c1, &c2, &ccd);
if (i < 42 || i > 58){
assertFalse(res);
}else{
assertTrue(res);
}
c1.pos.v[1] += 0.1;
}
}
TEST(cylcylAlignedZ)
{
ccd_t ccd;
CCD_CYL(c1);
CCD_CYL(c2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
c1.radius = 0.35;
c1.height = 0.5;
c2.radius = 0.5;
c2.height = 1.;
ccdVec3Set(&c1.pos, 0., 0., -5.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&c1, &c2, &ccd);
if (i < 43 || i > 57){
assertFalse(res);
}else{
assertTrue(res);
}
c1.pos.v[2] += 0.1;
}
}
#define TOSVT() \
svtObjPen(&cyl1, &cyl2, stdout, "Pen 1", depth, &dir, &pos); \
ccdVec3Scale(&dir, depth); \
ccdVec3Add(&cyl2.pos, &dir); \
svtObjPen(&cyl1, &cyl2, stdout, "Pen 1", depth, &dir, &pos)
TEST(cylcylPenetrationEPA)
{
ccd_t ccd;
CCD_CYL(cyl1);
CCD_CYL(cyl2);
int res;
ccd_vec3_t axis;
ccd_real_t depth;
ccd_vec3_t dir, pos;
fprintf(stderr, "\n\n\n---- cylcylPenetration ----\n\n\n");
cyl1.radius = 0.35;
cyl1.height = 0.5;
cyl2.radius = 0.5;
cyl2.height = 1.;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&cyl2.pos, 0., 0., 0.3);
res = ccdGJKPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
//TOSVT();
ccdVec3Set(&cyl1.pos, 0.3, 0.1, 0.1);
res = ccdGJKPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 2");
//TOSVT(); <<<
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0., 0., 0.);
res = ccdGJKPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 3");
//TOSVT();
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, -0.2, 0.7, 0.2);
res = ccdGJKPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 4");
//TOSVT();
ccdVec3Set(&axis, 0.567, 1.2, 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
res = ccdGJKPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 5");
//TOSVT();
ccdVec3Set(&axis, -4.567, 1.2, 0.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
res = ccdGJKPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 6");
//TOSVT();
}

29
3rdparty/libccd/src/testsuites/cylcyl.h vendored Normal file
View File

@ -0,0 +1,29 @@
#ifndef CYL_CYL
#define CYL_CYL
#include <cu/cu.h>
TEST(cylcylSetUp);
TEST(cylcylTearDown);
TEST(cylcylAlignedX);
TEST(cylcylAlignedY);
TEST(cylcylAlignedZ);
TEST(cylcylPenetrationEPA);
TEST_SUITE(TSCylCyl) {
TEST_ADD(cylcylSetUp),
TEST_ADD(cylcylAlignedX),
TEST_ADD(cylcylAlignedY),
TEST_ADD(cylcylAlignedZ),
TEST_ADD(cylcylPenetrationEPA),
TEST_ADD(cylcylTearDown),
TEST_SUITE_CLOSURE
};
#endif

32
3rdparty/libccd/src/testsuites/main.c vendored Normal file
View File

@ -0,0 +1,32 @@
#include "vec3.h"
#include "polytope.h"
#include "boxbox.h"
#include "spheresphere.h"
#include "cylcyl.h"
#include "boxcyl.h"
#include "mpr_boxbox.h"
#include "mpr_cylcyl.h"
#include "mpr_boxcyl.h"
TEST_SUITES {
TEST_SUITE_ADD(TSVec3),
TEST_SUITE_ADD(TSPt),
TEST_SUITE_ADD(TSBoxBox),
TEST_SUITE_ADD(TSSphereSphere),
TEST_SUITE_ADD(TSCylCyl),
TEST_SUITE_ADD(TSBoxCyl),
TEST_SUITE_ADD(TSMPRBoxBox),
TEST_SUITE_ADD(TSMPRCylCyl),
TEST_SUITE_ADD(TSMPRBoxCyl),
TEST_SUITES_CLOSURE
};
int main(int argc, char *argv[])
{
CU_SET_OUT_PREFIX("regressions/");
CU_RUN(argc, argv);
return 0;
}

View File

@ -0,0 +1,502 @@
#include <stdio.h>
#include <cu/cu.h>
#include <ccd/ccd.h>
#include <ccd/vec3.h>
#include "../dbg.h"
#include "support.h"
#include "common.h"
TEST(mprBoxboxAlignedX)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
box1.x = 0.1;
box1.y = 0.2;
box1.z = 0.1;
box2.x = 0.2;
box2.y = 0.1;
box2.z = 0.2;
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.01;
}
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., -0.1, 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
}
TEST(mprBoxboxAlignedY)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, 0., -5., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[1] += 0.1;
}
}
TEST(mprBoxboxAlignedZ)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, 0., 0., -5.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[2] += 0.1;
}
}
TEST(mprBoxboxRot)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t axis;
ccd_real_t angle;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., 0.5, 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&box1, &box2, &ccd);
if (i < 33 || i > 67){
assertFalse(res);
}else if (i != 33 && i != 67){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
box1.x = 1;
box1.y = 1;
box1.z = 1;
box2.x = 1;
box2.y = 1;
box2.z = 1;
ccdVec3Set(&box1.pos, -1.01, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
ccdVec3Set(&axis, 0., 1., 0.);
angle = 0.;
for (i = 0; i < 30; i++){
res = ccdMPRIntersect(&box1, &box2, &ccd);
if (i != 0 && i != 10 && i != 20){
assertTrue(res);
}else{
assertFalse(res);
}
angle += M_PI / 20.;
ccdQuatSetAngleAxis(&box1.quat, angle, &axis);
}
}
static void pConf(ccd_box_t *box1, ccd_box_t *box2, const ccd_vec3_t *v)
{
fprintf(stdout, "# box1.pos: [%lf %lf %lf]\n",
ccdVec3X(&box1->pos), ccdVec3Y(&box1->pos), ccdVec3Z(&box1->pos));
fprintf(stdout, "# box1->quat: [%lf %lf %lf %lf]\n",
box1->quat.q[0], box1->quat.q[1], box1->quat.q[2], box1->quat.q[3]);
fprintf(stdout, "# box2->pos: [%lf %lf %lf]\n",
ccdVec3X(&box2->pos), ccdVec3Y(&box2->pos), ccdVec3Z(&box2->pos));
fprintf(stdout, "# box2->quat: [%lf %lf %lf %lf]\n",
box2->quat.q[0], box2->quat.q[1], box2->quat.q[2], box2->quat.q[3]);
fprintf(stdout, "# sep: [%lf %lf %lf]\n",
ccdVec3X(v), ccdVec3Y(v), ccdVec3Z(v));
fprintf(stdout, "#\n");
}
TEST(mprBoxboxSeparate)
{
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t sep, expsep, expsep2, axis;
fprintf(stderr, "\n\n\n---- boxboxSeparate ----\n\n\n");
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.2);
res = ccdMPRIntersect(&box1, &box2, &ccd);
assertTrue(res);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0.25, 0., 0.);
assertTrue(ccdVec3Eq(&sep, &expsep));
ccdVec3Scale(&sep, -1.);
ccdVec3Add(&box1.pos, &sep);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., 0.);
assertTrue(ccdVec3Eq(&sep, &expsep));
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., -0.25);
assertTrue(ccdVec3Eq(&sep, &expsep));
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0., 0., 0.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., 1.);
ccdVec3Set(&expsep2, 0., 0., -1.);
assertTrue(ccdVec3Eq(&sep, &expsep) || ccdVec3Eq(&sep, &expsep2));
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
pConf(&box1, &box2, &sep);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
pConf(&box1, &box2, &sep);
}
#define TOSVT() \
svtObjPen(&box1, &box2, stdout, "Pen 1", depth, &dir, &pos); \
ccdVec3Scale(&dir, depth); \
ccdVec3Add(&box2.pos, &dir); \
svtObjPen(&box1, &box2, stdout, "Pen 1", depth, &dir, &pos)
TEST(mprBoxboxPenetration)
{
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t axis;
ccd_quat_t rot;
ccd_real_t depth;
ccd_vec3_t dir, pos;
fprintf(stderr, "\n\n\n---- boxboxPenetration ----\n\n\n");
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
/*
ccdVec3Set(&box2.pos, 0., 0., 0.);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
TOSVT();
*/
ccdVec3Set(&box2.pos, 0.1, 0., 0.);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
//TOSVT();
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 2");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0.1, 0., 0.1);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 3");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 4");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 5");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&box2.pos, 0.1, 0., 0.);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 6");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 1., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 7");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = 0.2; box2.y = 0.5; box2.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 0., 0.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -1.3, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 8");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5; box2.y = 0.5; box2.z = .5;
ccdVec3Set(&box1.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdVec3Set(&box2.pos, 0., 0.73, 0.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 9");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5; box2.y = 0.5; box2.z = .5;
ccdVec3Set(&box1.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdVec3Set(&box2.pos, 0.3, 0.738, 0.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
res = ccdMPRPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 10");
//TOSVT();
}

View File

@ -0,0 +1,26 @@
#ifndef MPR_BOX_BOX
#define MPR_BOX_BOX
#include <cu/cu.h>
TEST(mprBoxboxAlignedX);
TEST(mprBoxboxAlignedY);
TEST(mprBoxboxAlignedZ);
TEST(mprBoxboxRot);
TEST(mprBoxboxSeparate);
TEST(mprBoxboxPenetration);
TEST_SUITE(TSMPRBoxBox) {
TEST_ADD(mprBoxboxAlignedX),
TEST_ADD(mprBoxboxAlignedY),
TEST_ADD(mprBoxboxAlignedZ),
TEST_ADD(mprBoxboxRot),
TEST_ADD(mprBoxboxSeparate),
TEST_ADD(mprBoxboxPenetration),
TEST_SUITE_CLOSURE
};
#endif

View File

@ -0,0 +1,165 @@
#include <cu/cu.h>
#include <ccd/ccd.h>
#include "common.h"
#include "support.h"
#define TOSVT() \
svtObjPen(&box, &cyl, stdout, "Pen 1", depth, &dir, &pos); \
ccdVec3Scale(&dir, depth); \
ccdVec3Add(&cyl.pos, &dir); \
svtObjPen(&box, &cyl, stdout, "Pen 1", depth, &dir, &pos)
TEST(mprBoxcylIntersect)
{
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
int res;
ccd_vec3_t axis;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
ccdVec3Set(&cyl.pos, 0.1, 0., 0.);
res = ccdMPRIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0., 0.);
res = ccdMPRIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
res = ccdMPRIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdMPRIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdMPRIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
res = ccdMPRIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
res = ccdMPRIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
res = ccdMPRIntersect(&box, &cyl, &ccd);
assertTrue(res);
}
TEST(mprBoxcylPen)
{
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
int res;
ccd_vec3_t axis;
ccd_real_t depth;
ccd_vec3_t dir, pos;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
ccdVec3Set(&cyl.pos, 0.1, 0., 0.);
res = ccdMPRPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
//TOSVT();
ccdVec3Set(&cyl.pos, .6, 0., 0.);
res = ccdMPRPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 2");
//TOSVT();
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
res = ccdMPRPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 3");
//TOSVT();
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdMPRPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 4");
//TOSVT();
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdMPRPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 5");
//TOSVT();
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
res = ccdMPRPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 6");
//TOSVT();
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
res = ccdMPRPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 7");
//TOSVT();
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
res = ccdMPRPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 8");
//TOSVT();
}

View File

@ -0,0 +1,16 @@
#ifndef MPR_TEST_BOXCYL_H
#define MPR_TEST_BOXCYL_H
#include <cu/cu.h>
TEST(mprBoxcylIntersect);
TEST(mprBoxcylPen);
TEST_SUITE(TSMPRBoxCyl){
TEST_ADD(mprBoxcylIntersect),
TEST_ADD(mprBoxcylPen),
TEST_SUITE_CLOSURE
};
#endif

View File

@ -0,0 +1,179 @@
#include <stdio.h>
#include <cu/cu.h>
#include <ccd/ccd.h>
#include "support.h"
#include "common.h"
TEST(mprCylcylAlignedX)
{
ccd_t ccd;
CCD_CYL(c1);
CCD_CYL(c2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
c1.radius = 0.35;
c1.height = 0.5;
c2.radius = 0.5;
c2.height = 1.;
ccdVec3Set(&c1.pos, -5., 0., 0.);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&c1, &c2, &ccd);
if (i < 42 || i > 58){
assertFalse(res);
}else{
assertTrue(res);
}
c1.pos.v[0] += 0.1;
}
}
TEST(mprCylcylAlignedY)
{
ccd_t ccd;
CCD_CYL(c1);
CCD_CYL(c2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
c1.radius = 0.35;
c1.height = 0.5;
c2.radius = 0.5;
c2.height = 1.;
ccdVec3Set(&c1.pos, 0., -5., 0.);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&c1, &c2, &ccd);
if (i < 42 || i > 58){
assertFalse(res);
}else{
assertTrue(res);
}
c1.pos.v[1] += 0.1;
}
}
TEST(mprCylcylAlignedZ)
{
ccd_t ccd;
CCD_CYL(c1);
CCD_CYL(c2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
c1.radius = 0.35;
c1.height = 0.5;
c2.radius = 0.5;
c2.height = 1.;
ccdVec3Set(&c1.pos, 0., 0., -5.);
for (i = 0; i < 100; i++){
res = ccdMPRIntersect(&c1, &c2, &ccd);
if (i < 43 || i > 57){
assertFalse(res);
}else{
assertTrue(res);
}
c1.pos.v[2] += 0.1;
}
}
#define TOSVT() \
svtObjPen(&cyl1, &cyl2, stdout, "Pen 1", depth, &dir, &pos); \
ccdVec3Scale(&dir, depth); \
ccdVec3Add(&cyl2.pos, &dir); \
svtObjPen(&cyl1, &cyl2, stdout, "Pen 1", depth, &dir, &pos)
TEST(mprCylcylPenetration)
{
ccd_t ccd;
CCD_CYL(cyl1);
CCD_CYL(cyl2);
int res;
ccd_vec3_t axis;
ccd_real_t depth;
ccd_vec3_t dir, pos;
fprintf(stderr, "\n\n\n---- mprCylcylPenetration ----\n\n\n");
cyl1.radius = 0.35;
cyl1.height = 0.5;
cyl2.radius = 0.5;
cyl2.height = 1.;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
ccdVec3Set(&cyl2.pos, 0., 0., 0.3);
res = ccdMPRPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
//TOSVT();
ccdVec3Set(&cyl1.pos, 0.3, 0.1, 0.1);
res = ccdMPRPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 2");
//TOSVT();
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0., 0., 0.);
res = ccdMPRPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 3");
//TOSVT();
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, -0.2, 0.7, 0.2);
res = ccdMPRPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 4");
//TOSVT();
ccdVec3Set(&axis, 0.567, 1.2, 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
res = ccdMPRPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 5");
//TOSVT();
ccdVec3Set(&axis, -4.567, 1.2, 0.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
res = ccdMPRPenetration(&cyl1, &cyl2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 6");
//TOSVT();
}

View File

@ -0,0 +1,23 @@
#ifndef MPR_CYL_CYL
#define MPR_CYL_CYL
#include <cu/cu.h>
TEST(mprCylcylAlignedX);
TEST(mprCylcylAlignedY);
TEST(mprCylcylAlignedZ);
TEST(mprCylcylPenetration);
TEST_SUITE(TSMPRCylCyl) {
TEST_ADD(mprCylcylAlignedX),
TEST_ADD(mprCylcylAlignedY),
TEST_ADD(mprCylcylAlignedZ),
TEST_ADD(mprCylcylPenetration),
TEST_SUITE_CLOSURE
};
#endif

View File

@ -0,0 +1,396 @@
//#undef NDEBUG
#include <cu/cu.h>
#include "../polytope.h"
#include "../dbg.h"
TEST(ptSetUp)
{
}
TEST(ptTearDown)
{
}
TEST(ptCreate1)
{
ccd_pt_t pt;
ccd_pt_vertex_t *v[3];
ccd_pt_edge_t *e[3];
ccd_pt_face_t *f;
ccd_vec3_t u;
int res, i;
DBG2("------");
ccdPtInit(&pt);
ccdPtDestroy(&pt);
ccdPtInit(&pt);
ccdVec3Set(&u, -1., -1., 0.);
v[0] = ccdPtAddVertexCoords(&pt, -1., -1., 0.);
assertTrue(ccdVec3Eq(&u, &v[0]->v.v));
ccdVec3Set(&u, 1., 0., 0.);
v[1] = ccdPtAddVertexCoords(&pt, 1., 0., 0.);
assertTrue(ccdVec3Eq(&u, &v[1]->v.v));
ccdVec3Set(&u, 0., 0., 1.);
v[2] = ccdPtAddVertexCoords(&pt, 0., 0., 1.);
assertTrue(ccdVec3Eq(&u, &v[2]->v.v));
for (i = 0; i < 3; i++){
assertTrue(ccdEq(v[i]->dist, ccdVec3Len2(&v[i]->v.v)));
}
e[0] = ccdPtAddEdge(&pt, v[0], v[1]);
e[1] = ccdPtAddEdge(&pt, v[1], v[2]);
e[2] = ccdPtAddEdge(&pt, v[2], v[0]);
for (i = 0; i < 3; i++){
DBG("e[%d]->dist: %lf", i, e[i]->dist);
DBG_VEC3(&e[i]->witness, " ->witness: ");
}
f = ccdPtAddFace(&pt, e[0], e[1], e[2]);
DBG("f->dist: %lf", f->dist);
DBG_VEC3(&f->witness, " ->witness: ");
for (i = 0; i < 3; i++){
res = ccdPtDelVertex(&pt, v[i]);
assertFalse(res == 0);
res = ccdPtDelEdge(&pt, e[i]);
assertFalse(res == 0);
}
ccdPtDelFace(&pt, f);
for (i = 0; i < 3; i++){
res = ccdPtDelVertex(&pt, v[i]);
assertFalse(res == 0);
}
for (i = 0; i < 3; i++){
res = ccdPtDelEdge(&pt, e[i]);
assertTrue(res == 0);
}
for (i = 0; i < 3; i++){
res = ccdPtDelVertex(&pt, v[i]);
assertTrue(res == 0);
}
v[0] = ccdPtAddVertexCoords(&pt, -1., -1., 0.);
v[1] = ccdPtAddVertexCoords(&pt, 1., 0., 0.);
v[2] = ccdPtAddVertexCoords(&pt, 0., 0., 1.);
e[0] = ccdPtAddEdge(&pt, v[0], v[1]);
e[1] = ccdPtAddEdge(&pt, v[1], v[2]);
e[2] = ccdPtAddEdge(&pt, v[2], v[0]);
f = ccdPtAddFace(&pt, e[0], e[1], e[2]);
ccdPtDestroy(&pt);
}
TEST(ptCreate2)
{
ccd_pt_t pt;
ccd_pt_vertex_t *v[4];
ccd_pt_edge_t *e[6];
ccd_pt_face_t *f[4];
ccd_vec3_t u;
int res, i;
DBG2("------");
ccdPtInit(&pt);
ccdVec3Set(&u, -1., -1., 0.);
v[0] = ccdPtAddVertexCoords(&pt, -1., -1., 0.);
assertTrue(ccdVec3Eq(&u, &v[0]->v.v));
ccdVec3Set(&u, 1., 0., 0.);
v[1] = ccdPtAddVertexCoords(&pt, 1., 0., 0.);
assertTrue(ccdVec3Eq(&u, &v[1]->v.v));
ccdVec3Set(&u, 0., 0., 1.);
v[2] = ccdPtAddVertexCoords(&pt, 0., 0., 1.);
assertTrue(ccdVec3Eq(&u, &v[2]->v.v));
ccdVec3Set(&u, 0., 1., 0.);
v[3] = ccdPtAddVertexCoords(&pt, 0., 1., 0.);
assertTrue(ccdVec3Eq(&u, &v[3]->v.v));
for (i = 0; i < 4; i++){
assertTrue(ccdEq(v[i]->dist, ccdVec3Len2(&v[i]->v.v)));
}
for (i = 0; i < 4; i++){
DBG("v[%d]->dist: %lf", i, v[i]->dist);
DBG_VEC3(&v[i]->witness, " ->witness: ");
}
e[0] = ccdPtAddEdge(&pt, v[0], v[1]);
e[1] = ccdPtAddEdge(&pt, v[1], v[2]);
e[2] = ccdPtAddEdge(&pt, v[2], v[0]);
e[3] = ccdPtAddEdge(&pt, v[3], v[0]);
e[4] = ccdPtAddEdge(&pt, v[3], v[1]);
e[5] = ccdPtAddEdge(&pt, v[3], v[2]);
for (i = 0; i < 6; i++){
DBG("e[%d]->dist: %lf", i, e[i]->dist);
DBG_VEC3(&e[i]->witness, " ->witness: ");
}
f[0] = ccdPtAddFace(&pt, e[0], e[1], e[2]);
f[1] = ccdPtAddFace(&pt, e[3], e[4], e[0]);
f[2] = ccdPtAddFace(&pt, e[4], e[5], e[1]);
f[3] = ccdPtAddFace(&pt, e[5], e[3], e[2]);
for (i = 0; i < 4; i++){
DBG("f[%d]->dist: %lf", i, f[i]->dist);
DBG_VEC3(&f[i]->witness, " ->witness: ");
}
for (i = 0; i < 4; i++){
res = ccdPtDelVertex(&pt, v[i]);
assertFalse(res == 0);
}
for (i = 0; i < 6; i++){
res = ccdPtDelEdge(&pt, e[i]);
assertFalse(res == 0);
}
res = ccdPtDelFace(&pt, f[0]);
for (i = 0; i < 6; i++){
res = ccdPtDelEdge(&pt, e[i]);
assertFalse(res == 0);
}
res = ccdPtDelFace(&pt, f[1]);
assertTrue(ccdPtDelEdge(&pt, e[0]) == 0);
assertFalse(ccdPtDelEdge(&pt, e[1]) == 0);
assertFalse(ccdPtDelEdge(&pt, e[2]) == 0);
assertFalse(ccdPtDelEdge(&pt, e[3]) == 0);
assertFalse(ccdPtDelEdge(&pt, e[4]) == 0);
assertFalse(ccdPtDelEdge(&pt, e[5]) == 0);
for (i = 0; i < 4; i++){
res = ccdPtDelVertex(&pt, v[i]);
assertFalse(res == 0);
}
res = ccdPtDelFace(&pt, f[2]);
assertTrue(ccdPtDelEdge(&pt, e[1]) == 0);
assertTrue(ccdPtDelEdge(&pt, e[4]) == 0);
assertFalse(ccdPtDelEdge(&pt, e[2]) == 0);
assertFalse(ccdPtDelEdge(&pt, e[3]) == 0);
assertFalse(ccdPtDelEdge(&pt, e[5]) == 0);
assertTrue(ccdPtDelVertex(&pt, v[1]) == 0);
assertFalse(ccdPtDelVertex(&pt, v[0]) == 0);
assertFalse(ccdPtDelVertex(&pt, v[2]) == 0);
assertFalse(ccdPtDelVertex(&pt, v[3]) == 0);
res = ccdPtDelFace(&pt, f[3]);
assertTrue(ccdPtDelEdge(&pt, e[2]) == 0);
assertTrue(ccdPtDelEdge(&pt, e[3]) == 0);
assertTrue(ccdPtDelEdge(&pt, e[5]) == 0);
assertTrue(ccdPtDelVertex(&pt, v[0]) == 0);
assertTrue(ccdPtDelVertex(&pt, v[2]) == 0);
assertTrue(ccdPtDelVertex(&pt, v[3]) == 0);
v[0] = ccdPtAddVertexCoords(&pt, -1., -1., 0.);
v[1] = ccdPtAddVertexCoords(&pt, 1., 0., 0.);
v[2] = ccdPtAddVertexCoords(&pt, 0., 0., 1.);
v[3] = ccdPtAddVertexCoords(&pt, 0., 1., 0.);
e[0] = ccdPtAddEdge(&pt, v[0], v[1]);
e[1] = ccdPtAddEdge(&pt, v[1], v[2]);
e[2] = ccdPtAddEdge(&pt, v[2], v[0]);
e[3] = ccdPtAddEdge(&pt, v[3], v[0]);
e[4] = ccdPtAddEdge(&pt, v[3], v[1]);
e[5] = ccdPtAddEdge(&pt, v[3], v[2]);
f[0] = ccdPtAddFace(&pt, e[0], e[1], e[2]);
f[1] = ccdPtAddFace(&pt, e[3], e[4], e[0]);
f[2] = ccdPtAddFace(&pt, e[4], e[5], e[1]);
f[3] = ccdPtAddFace(&pt, e[5], e[3], e[2]);
ccdPtDestroy(&pt);
}
TEST(ptNearest)
{
ccd_pt_t pt;
ccd_pt_vertex_t *v[4];
ccd_pt_edge_t *e[6];
ccd_pt_face_t *f[4];
ccd_pt_el_t *nearest;
DBG2("------");
ccdPtInit(&pt);
v[0] = ccdPtAddVertexCoords(&pt, -1., -1., 0.);
v[1] = ccdPtAddVertexCoords(&pt, 1., 0., 0.);
v[2] = ccdPtAddVertexCoords(&pt, 0., 0., 1.);
v[3] = ccdPtAddVertexCoords(&pt, 0., 1., 0.);
e[0] = ccdPtAddEdge(&pt, v[0], v[1]);
e[1] = ccdPtAddEdge(&pt, v[1], v[2]);
e[2] = ccdPtAddEdge(&pt, v[2], v[0]);
e[3] = ccdPtAddEdge(&pt, v[3], v[0]);
e[4] = ccdPtAddEdge(&pt, v[3], v[1]);
e[5] = ccdPtAddEdge(&pt, v[3], v[2]);
f[0] = ccdPtAddFace(&pt, e[0], e[1], e[2]);
f[1] = ccdPtAddFace(&pt, e[3], e[4], e[0]);
f[2] = ccdPtAddFace(&pt, e[4], e[5], e[1]);
f[3] = ccdPtAddFace(&pt, e[5], e[3], e[2]);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_FACE);
assertEquals(nearest, (ccd_pt_el_t *)f[1]);
assertTrue(ccdPtDelFace(&pt, f[1]) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_FACE);
assertTrue(nearest == (ccd_pt_el_t *)f[0]
|| nearest == (ccd_pt_el_t *)f[3]);
assertTrue(ccdPtDelFace(&pt, (ccd_pt_face_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_FACE);
assertTrue(nearest == (ccd_pt_el_t *)f[0]
|| nearest == (ccd_pt_el_t *)f[3]);
assertTrue(ccdPtDelFace(&pt, (ccd_pt_face_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_EDGE);
assertTrue(nearest == (ccd_pt_el_t *)e[0]
|| nearest == (ccd_pt_el_t *)e[3]);
assertTrue(ccdPtDelEdge(&pt, (ccd_pt_edge_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_EDGE);
assertTrue(nearest == (ccd_pt_el_t *)e[0]
|| nearest == (ccd_pt_el_t *)e[3]);
assertTrue(ccdPtDelEdge(&pt, (ccd_pt_edge_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_FACE);
assertEquals(nearest, (ccd_pt_el_t *)f[2]);
assertTrue(ccdPtDelFace(&pt, f[2]) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_EDGE);
assertTrue(nearest == (ccd_pt_el_t *)e[1]
|| nearest == (ccd_pt_el_t *)e[4]
|| nearest == (ccd_pt_el_t *)e[5]);
assertTrue(ccdPtDelEdge(&pt, (ccd_pt_edge_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_EDGE);
assertTrue(nearest == (ccd_pt_el_t *)e[1]
|| nearest == (ccd_pt_el_t *)e[4]
|| nearest == (ccd_pt_el_t *)e[5]);
assertTrue(ccdPtDelEdge(&pt, (ccd_pt_edge_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_EDGE);
assertTrue(nearest == (ccd_pt_el_t *)e[1]
|| nearest == (ccd_pt_el_t *)e[4]
|| nearest == (ccd_pt_el_t *)e[5]);
assertTrue(ccdPtDelEdge(&pt, (ccd_pt_edge_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_EDGE);
assertTrue(nearest == (ccd_pt_el_t *)e[2]);
assertTrue(ccdPtDelEdge(&pt, (ccd_pt_edge_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_VERTEX);
assertTrue(nearest == (ccd_pt_el_t *)v[1]
|| nearest == (ccd_pt_el_t *)v[2]
|| nearest == (ccd_pt_el_t *)v[3]);
assertTrue(ccdPtDelVertex(&pt, (ccd_pt_vertex_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_VERTEX);
assertTrue(nearest == (ccd_pt_el_t *)v[1]
|| nearest == (ccd_pt_el_t *)v[2]
|| nearest == (ccd_pt_el_t *)v[3]);
assertTrue(ccdPtDelVertex(&pt, (ccd_pt_vertex_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_VERTEX);
assertTrue(nearest == (ccd_pt_el_t *)v[1]
|| nearest == (ccd_pt_el_t *)v[2]
|| nearest == (ccd_pt_el_t *)v[3]);
assertTrue(ccdPtDelVertex(&pt, (ccd_pt_vertex_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
//DBG("nearest->type: %d", nearest->type);
//DBG(" ->dist: %lf", nearest->dist);
//DBG_VEC3(&nearest->witness, " ->witness: ");
assertEquals(nearest->type, CCD_PT_VERTEX);
assertTrue(nearest == (ccd_pt_el_t *)v[0]);
assertTrue(ccdPtDelVertex(&pt, (ccd_pt_vertex_t *)nearest) == 0);
nearest = ccdPtNearest(&pt);
assertTrue(nearest == NULL);
ccdPtDestroy(&pt);
}

View File

@ -0,0 +1,24 @@
#ifndef TEST_POLYTOPE_H
#define TEST_POLYTOPE_H
#include <cu/cu.h>
TEST(ptSetUp);
TEST(ptTearDown);
TEST(ptCreate1);
TEST(ptCreate2);
TEST(ptNearest);
TEST_SUITE(TSPt) {
TEST_ADD(ptSetUp),
TEST_ADD(ptCreate1),
TEST_ADD(ptCreate2),
TEST_ADD(ptNearest),
TEST_ADD(ptTearDown),
TEST_SUITE_CLOSURE
};
#endif

View File

View File

@ -0,0 +1,12 @@
---- boxboxSeparate ----
---- boxboxPenetration ----

View File

@ -0,0 +1,44 @@
# box1.pos: [-0.500000 0.000000 0.000000]
# box1->quat: [0.000000 0.000000 0.382683 0.923880]
# box2->pos: [0.000000 0.000000 0.000000]
# box2->quat: [0.000000 0.000000 0.000000 1.000000]
# sep: [0.707107 0.000000 0.000000]
#
# box1.pos: [-0.500000 0.100000 0.400000]
# box1->quat: [0.000000 0.270598 0.270598 0.923880]
# box2->pos: [0.000000 0.000000 0.000000]
# box2->quat: [0.000000 0.000000 0.000000 1.000000]
# sep: [0.633939 0.000000 -0.371353]
#
# Pen 1: depth: 0.650000
# Pen 1: dir: [1.000000 0.000000 0.000000]
# Pen 1: pos: [0.096875 0.000000 0.000000]
#
# Pen 2: depth: 0.250000
# Pen 2: dir: [-0.000000 0.000000 -1.000000]
# Pen 2: pos: [-0.058333 0.250000 0.583333]
#
# Pen 3: depth: 0.900000
# Pen 3: dir: [0.000000 0.000000 -1.000000]
# Pen 3: pos: [0.111506 0.000000 0.050000]
#
# Pen 4: depth: 0.607107
# Pen 4: dir: [1.000000 0.000000 0.000000]
# Pen 4: pos: [-0.153585 0.000000 0.000000]
#
# Pen 5: depth: 0.429289
# Pen 5: dir: [0.707107 -0.707107 0.000000]
# Pen 5: pos: [-0.167157 0.379289 0.000000]
#
# Pen 6: depth: 0.648412
# Pen 6: dir: [0.862856 0.000000 -0.505449]
# Pen 6: pos: [-0.148223 0.055362 0.319638]
#
# Pen 7: depth: 0.622622
# Pen 7: dir: [1.000000 0.000000 -0.000000]
# Pen 7: pos: [-0.095997 0.063593 0.067678]
#
# Pen 8: depth: 0.053553
# Pen 8: dir: [1.000000 0.000000 0.000000]
# Pen 8: pos: [-0.523223 -0.073223 0.020711]
#

View File

@ -0,0 +1,32 @@
# Pen 1: depth: 0.549996
# Pen 1: dir: [0.999992 -0.003902 0.000000]
# Pen 1: pos: [0.020284 0.000000 0.000000]
#
# Pen 2: depth: 0.050000
# Pen 2: dir: [0.999992 -0.003902 0.000000]
# Pen 2: pos: [0.253480 0.000000 0.025000]
#
# Pen 3: depth: 0.030994
# Pen 3: dir: [0.950248 0.311493 0.000000]
# Pen 3: pos: [0.246546 0.420744 0.000000]
#
# Pen 4: depth: 0.033436
# Pen 4: dir: [0.976101 0.217308 0.001900]
# Pen 4: pos: [0.243648 0.480401 0.450000]
#
# Pen 5: depth: 0.142160
# Pen 5: dir: [0.968442 0.249235 0.001146]
# Pen 5: pos: [0.190887 0.421462 0.605496]
#
# Pen 6: depth: 0.179282
# Pen 6: dir: [0.999995 0.001057 0.002913]
# Pen 6: pos: [0.176026 0.036944 0.488189]
#
# Pen 7: depth: 0.750000
# Pen 7: dir: [-0.853795 -0.143509 -0.500438]
# Pen 7: pos: [0.572744 0.014828 0.562324]
#
# Pen 8: depth: 0.142666
# Pen 8: dir: [-0.475515 -0.841074 0.257839]
# Pen 8: pos: [0.824886 0.230213 0.463136]
#

View File

@ -0,0 +1,6 @@
---- cylcylPenetration ----

View File

@ -0,0 +1,24 @@
# Pen 1: depth: 0.750000
# Pen 1: dir: [0.000000 0.000000 1.000000]
# Pen 1: pos: [0.004079 -0.012238 0.009615]
#
# Pen 2: depth: 0.531931
# Pen 2: dir: [-0.926428 -0.376463 -0.002666]
# Pen 2: pos: [0.218566 0.072232 0.025000]
#
# Pen 3: depth: 0.645740
# Pen 3: dir: [-0.500000 -0.146447 -0.853553]
# Pen 3: pos: [0.177594 0.070484 0.186987]
#
# Pen 4: depth: 0.104445
# Pen 4: dir: [-0.482095 0.866317 0.130685]
# Pen 4: pos: [0.123724 0.348390 0.269312]
#
# Pen 5: depth: 0.093082
# Pen 5: dir: [0.034600 -0.999228 -0.018627]
# Pen 5: pos: [0.311257 -0.203923 -0.064270]
#
# Pen 6: depth: 0.198749
# Pen 6: dir: [0.411370 -0.911372 0.013223]
# Pen 6: pos: [0.405836 -0.130066 0.121441]
#

View File

@ -0,0 +1,12 @@
---- boxboxSeparate ----
---- boxboxPenetration ----

View File

@ -0,0 +1,52 @@
# box1.pos: [-0.500000 0.000000 0.000000]
# box1->quat: [0.000000 0.000000 0.382683 0.923880]
# box2->pos: [0.000000 0.000000 0.000000]
# box2->quat: [0.000000 0.000000 0.000000 1.000000]
# sep: [0.707107 0.000000 0.000000]
#
# box1.pos: [-0.500000 0.100000 0.400000]
# box1->quat: [0.000000 0.270598 0.270598 0.923880]
# box2->pos: [0.000000 0.000000 0.000000]
# box2->quat: [0.000000 0.000000 0.000000 1.000000]
# sep: [0.633939 0.000000 -0.371353]
#
# Pen 1: depth: 0.650000
# Pen 1: dir: [1.000000 0.000000 0.000000]
# Pen 1: pos: [0.175000 0.000000 0.000000]
#
# Pen 2: depth: 0.250000
# Pen 2: dir: [-0.000000 0.000000 -1.000000]
# Pen 2: pos: [-0.033333 0.250000 0.600000]
#
# Pen 3: depth: 0.900000
# Pen 3: dir: [0.000000 0.000000 -1.000000]
# Pen 3: pos: [0.100000 0.000000 0.050000]
#
# Pen 4: depth: 0.607107
# Pen 4: dir: [1.000000 0.000000 0.000000]
# Pen 4: pos: [-0.096447 0.000000 0.000000]
#
# Pen 5: depth: 0.429289
# Pen 5: dir: [0.707107 -0.707107 0.000000]
# Pen 5: pos: [-0.222183 0.322183 0.000000]
#
# Pen 6: depth: 0.648412
# Pen 6: dir: [0.862856 0.000000 -0.505449]
# Pen 6: pos: [-0.163060 0.012676 0.263060]
#
# Pen 7: depth: 0.622928
# Pen 7: dir: [0.999509 0.028016 -0.014008]
# Pen 7: pos: [-0.145374 0.170833 0.176732]
#
# Pen 8: depth: 0.053553
# Pen 8: dir: [1.000000 0.000000 0.000000]
# Pen 8: pos: [-0.480217 -0.140652 0.000000]
#
# Pen 9: depth: 0.020000
# Pen 9: dir: [0.000000 1.000000 0.000000]
# Pen 9: pos: [0.000000 0.490000 0.000000]
#
# Pen 10: depth: 0.012000
# Pen 10: dir: [-0.000000 1.000000 0.000000]
# Pen 10: pos: [0.200000 0.492000 0.000000]
#

View File

@ -0,0 +1,32 @@
# Pen 1: depth: 0.550000
# Pen 1: dir: [1.000000 0.000000 0.000000]
# Pen 1: pos: [-0.025000 0.000000 0.000000]
#
# Pen 2: depth: 0.050000
# Pen 2: dir: [1.000000 0.000000 0.000000]
# Pen 2: pos: [0.225000 0.000000 0.000000]
#
# Pen 3: depth: 0.038532
# Pen 3: dir: [0.788956 0.614450 0.000000]
# Pen 3: pos: [0.238587 0.477175 0.000000]
#
# Pen 4: depth: 0.038654
# Pen 4: dir: [0.779134 0.626832 -0.005696]
# Pen 4: pos: [0.238603 0.477206 0.340909]
#
# Pen 5: depth: 0.166653
# Pen 5: dir: [0.734126 0.679013 -0.000000]
# Pen 5: pos: [0.208320 0.416640 0.595113]
#
# Pen 6: depth: 0.180673
# Pen 6: dir: [1.000000 0.000003 -0.000000]
# Pen 6: pos: [0.192142 0.009404 0.479162]
#
# Pen 7: depth: 1.321922
# Pen 7: dir: [-0.897996 -0.063457 0.435403]
# Pen 7: pos: [0.531929 -0.046446 0.867546]
#
# Pen 8: depth: 0.142813
# Pen 8: dir: [-0.476782 -0.840534 0.257259]
# Pen 8: pos: [0.776128 0.285646 0.436629]
#

View File

@ -0,0 +1,6 @@
---- mprCylcylPenetration ----

View File

@ -0,0 +1,24 @@
# Pen 1: depth: 0.450000
# Pen 1: dir: [0.000000 0.000000 1.000000]
# Pen 1: pos: [0.000000 0.000000 0.025000]
#
# Pen 2: depth: 0.533732
# Pen 2: dir: [-0.952492 -0.304562 0.000000]
# Pen 2: pos: [0.176471 0.058824 0.166667]
#
# Pen 3: depth: 0.720933
# Pen 3: dir: [-0.947406 -0.320033 0.000085]
# Pen 3: pos: [0.198747 0.066309 0.050800]
#
# Pen 4: depth: 0.106076
# Pen 4: dir: [-0.524820 0.835278 0.163936]
# Pen 4: pos: [0.138692 0.362418 0.320024]
#
# Pen 5: depth: 0.103863
# Pen 5: dir: [0.291494 -0.956567 -0.003314]
# Pen 5: pos: [0.337721 -0.209314 -0.094587]
#
# Pen 6: depth: 0.202625
# Pen 6: dir: [0.347225 -0.937782 -0.000000]
# Pen 6: pos: [0.399554 -0.164780 0.199941]
#

View File

@ -0,0 +1,39 @@
ptCreate1 :: ------
ptCreate1 :: e[0]->dist: 0.200000
ptCreate1 :: ->witness: [0.200000 -0.400000 0.000000]
ptCreate1 :: e[1]->dist: 0.500000
ptCreate1 :: ->witness: [0.500000 0.000000 0.500000]
ptCreate1 :: e[2]->dist: 0.666667
ptCreate1 :: ->witness: [-0.333333 -0.333333 0.666667]
ptCreate1 :: f->dist: 0.166667
ptCreate1 :: ->witness: [0.166667 -0.333333 0.166667]
ptCreate2 :: ------
ptCreate2 :: v[0]->dist: 2.000000
ptCreate2 :: ->witness: [-1.000000 -1.000000 0.000000]
ptCreate2 :: v[1]->dist: 1.000000
ptCreate2 :: ->witness: [1.000000 0.000000 0.000000]
ptCreate2 :: v[2]->dist: 1.000000
ptCreate2 :: ->witness: [0.000000 0.000000 1.000000]
ptCreate2 :: v[3]->dist: 1.000000
ptCreate2 :: ->witness: [0.000000 1.000000 0.000000]
ptCreate2 :: e[0]->dist: 0.200000
ptCreate2 :: ->witness: [0.200000 -0.400000 0.000000]
ptCreate2 :: e[1]->dist: 0.500000
ptCreate2 :: ->witness: [0.500000 0.000000 0.500000]
ptCreate2 :: e[2]->dist: 0.666667
ptCreate2 :: ->witness: [-0.333333 -0.333333 0.666667]
ptCreate2 :: e[3]->dist: 0.200000
ptCreate2 :: ->witness: [-0.400000 0.200000 0.000000]
ptCreate2 :: e[4]->dist: 0.500000
ptCreate2 :: ->witness: [0.500000 0.500000 0.000000]
ptCreate2 :: e[5]->dist: 0.500000
ptCreate2 :: ->witness: [0.000000 0.500000 0.500000]
ptCreate2 :: f[0]->dist: 0.166667
ptCreate2 :: ->witness: [0.166667 -0.333333 0.166667]
ptCreate2 :: f[1]->dist: 0.000000
ptCreate2 :: ->witness: [0.000000 0.000000 0.000000]
ptCreate2 :: f[2]->dist: 0.333333
ptCreate2 :: ->witness: [0.333333 0.333333 0.333333]
ptCreate2 :: f[3]->dist: 0.166667
ptCreate2 :: ->witness: [-0.333333 0.166667 0.166667]
ptNearest :: ------

View File

View File

View File

View File

@ -0,0 +1,99 @@
#include <stdio.h>
#include <cu/cu.h>
#include <ccd/ccd.h>
#include "support.h"
TEST(spheresphereSetUp)
{
}
TEST(spheresphereTearDown)
{
}
TEST(spheresphereAlignedX)
{
ccd_t ccd;
CCD_SPHERE(s1);
CCD_SPHERE(s2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
s1.radius = 0.35;
s2.radius = .5;
ccdVec3Set(&s1.pos, -5., 0., 0.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&s1, &s2, &ccd);
if (i < 42 || i > 58){
assertFalse(res);
}else{
assertTrue(res);
}
s1.pos.v[0] += 0.1;
}
}
TEST(spheresphereAlignedY)
{
ccd_t ccd;
CCD_SPHERE(s1);
CCD_SPHERE(s2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
s1.radius = 0.35;
s2.radius = .5;
ccdVec3Set(&s1.pos, 0., -5., 0.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&s1, &s2, &ccd);
if (i < 42 || i > 58){
assertFalse(res);
}else{
assertTrue(res);
}
s1.pos.v[1] += 0.1;
}
}
TEST(spheresphereAlignedZ)
{
ccd_t ccd;
CCD_SPHERE(s1);
CCD_SPHERE(s2);
size_t i;
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
s1.radius = 0.35;
s2.radius = .5;
ccdVec3Set(&s1.pos, 0., 0., -5.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&s1, &s2, &ccd);
if (i < 42 || i > 58){
assertFalse(res);
}else{
assertTrue(res);
}
s1.pos.v[2] += 0.1;
}
}

View File

@ -0,0 +1,24 @@
#ifndef SPHERE_SPHERE
#define SPHERE_SPHERE
#include <cu/cu.h>
TEST(spheresphereSetUp);
TEST(spheresphereTearDown);
TEST(spheresphereAlignedX);
TEST(spheresphereAlignedY);
TEST(spheresphereAlignedZ);
TEST_SUITE(TSSphereSphere) {
TEST_ADD(spheresphereSetUp),
TEST_ADD(spheresphereAlignedX),
TEST_ADD(spheresphereAlignedY),
TEST_ADD(spheresphereAlignedZ),
TEST_ADD(spheresphereTearDown),
TEST_SUITE_CLOSURE
};
#endif

Some files were not shown because too many files have changed in this diff Show More