From bb5b5d44dd3939b2b45ff2679338ce40d302a033 Mon Sep 17 00:00:00 2001 From: Mattia Montanari Date: Sun, 2 Apr 2023 12:07:12 +0200 Subject: [PATCH] For Mono, use single precision - note that this does not work in unity --- .github/workflows/github-opengjk-examples.yml | 5 ++- examples/cs/main.cs | 40 +++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.github/workflows/github-opengjk-examples.yml b/.github/workflows/github-opengjk-examples.yml index 32336b5..2ce325c 100644 --- a/.github/workflows/github-opengjk-examples.yml +++ b/.github/workflows/github-opengjk-examples.yml @@ -30,8 +30,9 @@ jobs: uses: actions/checkout@v3 - run: apt-get update && apt-get install gcc cmake -y - run: cmake -E make_directory build - - run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MONO=ON .. - - run: cmake --build build + # Using single precision + - run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MONO=ON -DSINGLE_PRECISION=ON .. + - run: cmake --build build --target opengjk_ce - run: cmake -E chdir build make install - run: cd examples/cs/ && mcs -out:main.exe main.cs && mono main.exe diff --git a/examples/cs/main.cs b/examples/cs/main.cs index 5cb1023..6a12053 100644 --- a/examples/cs/main.cs +++ b/examples/cs/main.cs @@ -32,34 +32,34 @@ using System; using System.Runtime.InteropServices; -public class Tester +public class Tester { #if UNIX [DllImport("libopengjk_ce.so", EntryPoint="csFunction", CallingConvention = CallingConvention.StdCall)] #else [DllImport("libopengjk_ce", EntryPoint = "csFunction", CallingConvention = CallingConvention.StdCall)] #endif - - static extern double compute_minimum_distance(int na, double [,] ia, int nb, double [,] ib); - public static void Main(string[] args) - { - double dist; - // Define array A with coordinates - int nCoordsA = 9; - var inCoordsA = new double[3,9] { {0.0 , 2.3 , 8.1 , 4.3 ,2.5 , 7.1 , 1.0 , 3.3 , 6.0} , { 5.5 , 1.0 , 4.0 , 5.0 ,1.0, 1.0, 1.5, 0.5 , 1.4} ,{ 0.0 , -2.0, 2.4, 2.2, 2.3 , 2.4 , 0.3 , 0.3 , 0.2} }; + static extern float compute_minimum_distance(int na, float[,] ia, int nb, float[,] ib); - // Define array B with coordinates - int nCoordsB = 9; - var inCoordsB = new double[3,9] { {-0.0 , -2.3 , -8.1 , -4.3 ,-2.5 , -7.1 , -1.0 , -3.3 , -6.0} , { -5.5 , -1.0 ,- 4.0 ,- 5.0 ,-1.0, -1.0, -1.5, -0.5 , -1.4} ,{ -0.0 , 2.0, -2.4, -2.2, -2.3 , -2.4 , -0.3 , -0.3 , -0.2} }; + public static void Main(string[] args) + { + float dist; + // Define array A with coordinates + int nCoordsA = 9; + var inCoordsA = new float[3, 9] { { 0.0, 2.3, 8.1, 4.3, 2.5, 7.1, 1.0, 3.3, 6.0 }, { 5.5, 1.0, 4.0, 5.0, 1.0, 1.0, 1.5, 0.5, 1.4 }, { 0.0, -2.0, 2.4, 2.2, 2.3, 2.4, 0.3, 0.3, 0.2 } }; - // Invoke GJK to compute distance - dist = compute_minimum_distance( nCoordsA, inCoordsA, nCoordsB, inCoordsB ); - - // Output results - var s = string.Format("{0:0.##}", dist); - var message = string.Format("The distance between {0} is {1}","A and B",s); - Console.WriteLine(message); + // Define array B with coordinates + int nCoordsB = 9; + var inCoordsB = new float[3, 9] { { -0.0, -2.3, -8.1, -4.3, -2.5, -7.1, -1.0, -3.3, -6.0 }, { -5.5, -1.0, -4.0, -5.0, -1.0, -1.0, -1.5, -0.5, -1.4 }, { -0.0, 2.0, -2.4, -2.2, -2.3, -2.4, -0.3, -0.3, -0.2 } }; - } + // Invoke GJK to compute distance + dist = compute_minimum_distance(nCoordsA, inCoordsA, nCoordsB, inCoordsB); + + // Output results + var s = string.Format("{0:0.##}", dist); + var message = string.Format("The distance between {0} is {1}", "A and B", s); + Console.WriteLine(message); + + } }