From f93abbab774287a5953ef7ab5e0fa2e59cbf9e17 Mon Sep 17 00:00:00 2001 From: Murat Yilmaz Date: Thu, 25 Oct 2018 20:08:04 +0200 Subject: [PATCH 1/3] Add swift package manager support for static chipmunk c library --- Package.swift | 13 +++++++++++++ include/CChipmunk2D.h | 35 +++++++++++++++++++++++++++++++++++ include/module.modulemap | 5 +++++ 3 files changed, 53 insertions(+) create mode 100644 Package.swift create mode 100644 include/CChipmunk2D.h create mode 100644 include/module.modulemap diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..1c6fa0ae --- /dev/null +++ b/Package.swift @@ -0,0 +1,13 @@ +// swift-tools-version:4.2 + +import PackageDescription + +let package = Package( + name: "CChipmunk2D", + products: [ + .library(name: "CChipmunk2D", type: .static, targets: ["CChipmunk2D"]) + ], + targets: [ + .target(name: "CChipmunk2D", path: ".", sources: ["src"], publicHeadersPath: "include") + ] +) \ No newline at end of file diff --git a/include/CChipmunk2D.h b/include/CChipmunk2D.h new file mode 100644 index 00000000..4f8cd129 --- /dev/null +++ b/include/CChipmunk2D.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2018 Murat Yilmaz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef CCHIPMUNK_2D_H +#define CCHIPMUNK_2D_H + +#include "chipmunk/chipmunk.h" +#include "chipmunk/chipmunk_ffi.h" +#include "chipmunk/chipmunk_private.h" +#include "chipmunk/chipmunk_structs.h" +#include "chipmunk/chipmunk_unsafe.h" +#include "chipmunk/cpHastySpace.h" +#include "chipmunk/cpMarch.h" +#include "chipmunk/cpPolyline.h" +#include "chipmunk/cpRobust.h" + +#endif \ No newline at end of file diff --git a/include/module.modulemap b/include/module.modulemap new file mode 100644 index 00000000..6b73aefc --- /dev/null +++ b/include/module.modulemap @@ -0,0 +1,5 @@ +module CChipmunk2D { + umbrella header "CChipmunk2D.h" + link "CChipmunk2D" + export * +} From 62a9d8dae1c2604ad28d80e723fc05824879f5e2 Mon Sep 17 00:00:00 2001 From: Murat Yilmaz Date: Sat, 27 Oct 2018 21:26:47 +0200 Subject: [PATCH 2/3] Add cpPolylineGetVertex function for vertex array access to support usage in Swift --- include/chipmunk/cpPolyline.h | 2 ++ src/cpPolyline.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/chipmunk/cpPolyline.h b/include/chipmunk/cpPolyline.h index 4e878f0c..afc4e890 100644 --- a/include/chipmunk/cpPolyline.h +++ b/include/chipmunk/cpPolyline.h @@ -30,6 +30,8 @@ CP_EXPORT cpPolyline *cpPolylineSimplifyVertexes(cpPolyline *line, cpFloat tol); /// Get the convex hull of a polyline as a looped polyline. CP_EXPORT cpPolyline *cpPolylineToConvexHull(cpPolyline *line, cpFloat tol); +/// Get vertex of polyline at given index. +CP_EXPORT cpVect cpPolylineGetVertex(cpPolyline* line, int index); /// Polyline sets are collections of polylines, generally built by cpMarchSoft() or cpMarchHard(). typedef struct cpPolylineSet { diff --git a/src/cpPolyline.c b/src/cpPolyline.c index 5b375348..ec52890e 100644 --- a/src/cpPolyline.c +++ b/src/cpPolyline.c @@ -385,6 +385,13 @@ cpPolylineToConvexHull(cpPolyline *line, cpFloat tol) return cpPolylineShrink(hull); } +//MARK: Subscription Functions +cpVect +cpPolylineGetVertex(cpPolyline* line, int index) +{ + return line->verts[index]; +} + //MARK: Approximate Concave Decompostition struct Notch { From 2664cbe0c857027805bc071499231bf6a2bcb126 Mon Sep 17 00:00:00 2001 From: Murat Yilmaz Date: Sat, 27 Oct 2018 22:02:49 +0200 Subject: [PATCH 3/3] Add cpPolylineGetVertices to support acces to verts member in Swift --- include/chipmunk/cpPolyline.h | 3 +++ src/cpPolyline.c | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/chipmunk/cpPolyline.h b/include/chipmunk/cpPolyline.h index afc4e890..78117670 100644 --- a/include/chipmunk/cpPolyline.h +++ b/include/chipmunk/cpPolyline.h @@ -33,6 +33,9 @@ CP_EXPORT cpPolyline *cpPolylineToConvexHull(cpPolyline *line, cpFloat tol); /// Get vertex of polyline at given index. CP_EXPORT cpVect cpPolylineGetVertex(cpPolyline* line, int index); +/// Get pointer to vertices of polyline. +CP_EXPORT cpVect *cpPolylineGetVertices(cpPolyline* line); + /// Polyline sets are collections of polylines, generally built by cpMarchSoft() or cpMarchHard(). typedef struct cpPolylineSet { int count, capacity; diff --git a/src/cpPolyline.c b/src/cpPolyline.c index ec52890e..8b9e2b5a 100644 --- a/src/cpPolyline.c +++ b/src/cpPolyline.c @@ -385,13 +385,20 @@ cpPolylineToConvexHull(cpPolyline *line, cpFloat tol) return cpPolylineShrink(hull); } -//MARK: Subscription Functions +//MARK: Member Access Functions + cpVect cpPolylineGetVertex(cpPolyline* line, int index) { return line->verts[index]; } +cpVect * +cpPolylineGetVertices(cpPolyline* line) +{ + return &line->verts[0]; +} + //MARK: Approximate Concave Decompostition struct Notch {