pax_global_header 0000666 0000000 0000000 00000000064 14074277577 0014536 g ustar 00root root 0000000 0000000 52 comment=baec470ec51f334f6bc5b275ddb946083970aac5
pynest2d-4.13-beta/ 0000775 0000000 0000000 00000000000 14074277577 0014146 5 ustar 00root root 0000000 0000000 pynest2d-4.13-beta/CMakeLists.txt 0000664 0000000 0000000 00000004612 14074277577 0016711 0 ustar 00root root 0000000 0000000 # Copyright (c) 2020 Ultimaker B.V.
# pynest2d is released under the terms of the LGPLv3 or higher.
project(pynest2d)
cmake_minimum_required(VERSION 3.6) # Lowest version it's been tested with.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Requirements.
# FIXME: Remove the code for CMake <3.12 once we have switched over completely.
# FindPython3 is a new module since CMake 3.12. It deprecates FindPythonInterp and FindPythonLibs.
if(${CMAKE_VERSION} VERSION_LESS 3.12)
# FIXME: Use FindPython3 to find Python, new in CMake 3.12.
# However currently on our CI server it finds the wrong Python version and then doesn't find the headers.
find_package(PythonInterp 3.5 REQUIRED)
find_package(PythonLibs 3.5 REQUIRED)
else()
# Use FindPython3 for CMake >=3.12
find_package(Python3 3.5 REQUIRED COMPONENTS Interpreter Development)
endif()
find_package(SIP REQUIRED) # To create Python bindings.
find_package(libnest2d REQUIRED) # The library we're creating bindings for.
find_package(Clipper REQUIRED) # Dependency of libnest2d.
find_package(NLopt REQUIRED) # Dependency of libnest2d.
find_package(Boost REQUIRED) # Dependency of libnest2d.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLIBNEST2D_GEOMETRIES_clipper -DLIBNEST2D_OPTIMIZERS_nlopt -DLIBNEST2D_THREADING_std") # Tell libnest2d to use Clipper and NLopt, and standard threads.
# Some build options.
set(CMAKE_CXX_STANDARD 17)
if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
if(UNIX)
# Want to be able to move symbols from the Clipper library.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif()
if(NOT DEFINED LIB_SUFFIX)
set(LIB_SUFFIX "")
endif()
# Building and linking.
set(SIP_EXTRA_FILES_DEPEND
src/BottomLeftConfig.sip
src/Box.sip
src/Circle.sip
src/DJDHeuristicConfig.sip
src/Item.sip
src/ItemGroup.sip
src/NfpConfig.sip
src/Point.sip
src/Rectangle.sip
src/String.sip
)
set(SIP_EXTRA_OPTIONS -g -n PyQt5.sip) # Always release the GIL before calling C++ methods. -n PyQt5.sip is required to not get the PyCapsule error
include_directories(src/ ${SIP_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS} ${CLIPPER_INCLUDE_DIRS} ${NLopt_INCLUDE_DIRS} ${LIBNEST2D_INCLUDE_DIRS})
add_sip_python_module(pynest2d src/Pynest2D.sip ${CLIPPER_LIBRARIES} ${NLopt_LIBRARIES})
pynest2d-4.13-beta/LICENSE 0000664 0000000 0000000 00000016723 14074277577 0015164 0 ustar 00root root 0000000 0000000 GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
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. pynest2d-4.13-beta/README.md 0000664 0000000 0000000 00000005125 14074277577 0015430 0 ustar 00root root 0000000 0000000 Introduction and Scope
====
This repository contains CPython bindings for [libnest2d](https://github.com/tamasmeszaros/libnest2d) (though note that we may use as of yet unmerged work done on [our own fork of libnest2d, here](https://github.com/Ultimaker/libnest2d) whenever convenient), a library to pack 2D polygons into a small space. Libnest2d implements the 2D bin packing problem.
The objective of this repository is to allow libnest2d to be called from Python using Numpy. There is a [competing solution](https://github.com/markfink/nest2D) to provide Python bindings to this end. However this solution is licensed under AGPL. Since [Cura](https://github.com/Ultimaker/Cura) uses an LGPL license, it could not use that solution. This implementation is also too limited for Cura's purposes, so a new bindings project was set up that allows more configuration of the nesting algorithm.
Usage
====
This is an example of how you can use these Python bindings to arrange multiple shapes in a volume.
```python
>>> from pynest2d import *
>>> bin = Box(1000, 1000) # A bounding volume in which the items must be arranged, a 1000x1000 square centered around 0.
>>> i1 = Item([Point(0, 0), Point(100, 100), Point(50, 100)]) # Long thin triangle.
>>> i2 = Item([Point(0, 0), Point(100, 0), Point(100, 100), Point(0, 100)]) # Square.
>>> i3 = Item([Point(0, 0), Point(100, 0), Point(50, 100)]) # Equilateral triangle.
>>> num_bins = nest([i1, i2, i3], bin) # The actual arranging!
>>> num_bins # How many bins are required to add all objects.
1
>>> transformed_i1 = i1.transformedShape() # The original item is unchanged, but the transformed shape is.
>>> print(transformed_i1.toString())
Contour {
18 96
117 46
117 -4
18 96
}
>>> transformed_i.vertex(0).x()
18
>>> transformed_i.vertex(0).y()
96
>>> i1.rotation()
4.71238898038469
```
For full documentation, see [libnest2d](https://github.com/tamasmeszaros/libnest2d). These bindings stay close to the original function signatures.
Building
====
This library has a couple of dependencies that need to be installed prior to building:
* [libnest2d](https://github.com/Ultimaker/libnest2d), the library for which this library offers CPython bindings, and its dependencies:
* [Clipper](http://www.angusj.com/delphi/clipper.php), a polygon clipping library.
* [NLopt](https://nlopt.readthedocs.io/en/latest/), a library to solve non-linear optimization problems.
* [Boost](https://www.boost.org/), the headers only.
* [Sip](https://www.riverbankcomputing.com/software/sip/download), an application to generate Python bindings more easily.
pynest2d-4.13-beta/cmake/ 0000775 0000000 0000000 00000000000 14074277577 0015226 5 ustar 00root root 0000000 0000000 pynest2d-4.13-beta/cmake/COPYING-CMAKE-SCRIPTS 0000664 0000000 0000000 00000002457 14074277577 0020234 0 ustar 00root root 0000000 0000000 Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
pynest2d-4.13-beta/cmake/FindClipper.cmake 0000664 0000000 0000000 00000005623 14074277577 0020435 0 ustar 00root root 0000000 0000000 #Find Clipper library (http://www.angusj.com/delphi/clipper.php).
#The following variables are set
#
#CLIPPER_FOUND
#CLIPPER_INCLUDE_DIRS
#CLIPPER_LIBRARIES
#
#It searches the environment variable $CLIPPER_PATH automatically.
unset(CLIPPER_FOUND CACHE)
unset(CLIPPER_INCLUDE_DIRS CACHE)
unset(CLIPPER_LIBRARIES CACHE)
unset(CLIPPER_LIBRARIES_RELEASE CACHE)
unset(CLIPPER_LIBRARIES_DEBUG CACHE)
if($ EQUAL "debug")
set(CLIPPER_BUILD_TYPE DEBUG)
else()
set(CLIPPER_BUILD_TYPE RELEASE)
endif()
find_path(CLIPPER_INCLUDE_DIRS clipper.hpp
$ENV{CLIPPER_PATH}
$ENV{CLIPPER_PATH}/cpp/
$ENV{CLIPPER_PATH}/include/
$ENV{CLIPPER_PATH}/include/polyclipping/
${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/
${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/polyclipping/
${CMAKE_PREFIX_PATH}/include/polyclipping
${CMAKE_PREFIX_PATH}/include/
/opt/local/include/
/opt/local/include/polyclipping/
/usr/local/include/
/usr/local/include/polyclipping/
/usr/include
/usr/include/polyclipping/
)
set(LIB_SEARCHDIRS
$ENV{CLIPPER_PATH}
$ENV{CLIPPER_PATH}/cpp/
$ENV{CLIPPER_PATH}/cpp/build/
$ENV{CLIPPER_PATH}/lib/
$ENV{CLIPPER_PATH}/lib/polyclipping/
${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/
${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/polyclipping/
${CMAKE_PREFIX_PATH}/lib/
${CMAKE_PREFIX_PATH}/lib/polyclipping/
/opt/local/lib/
/opt/local/lib/polyclipping/
/usr/local/lib/
/usr/local/lib/polyclipping/
/usr/lib/polyclipping
)
set(_deb_postfix "d")
find_library(CLIPPER_LIBRARIES_RELEASE polyclipping ${LIB_SEARCHDIRS})
find_library(CLIPPER_LIBRARIES_DEBUG polyclipping${_deb_postfix} ${LIB_SEARCHDIRS})
if(CLIPPER_LIBRARIES_${CLIPPER_BUILD_TYPE})
set(CLIPPER_LIBRARIES "${CLIPPER_LIBRARIES_${CLIPPER_BUILD_TYPE}}")
else()
set(CLIPPER_LIBRARIES "${CLIPPER_LIBRARIES_RELEASE}")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Clipper
"Clipper library cannot be found. Consider set CLIPPER_PATH environment variable"
CLIPPER_INCLUDE_DIRS
CLIPPER_LIBRARIES
)
mark_as_advanced(CLIPPER_INCLUDE_DIRS CLIPPER_LIBRARIES)
if(CLIPPER_FOUND)
add_library(Clipper::Clipper UNKNOWN IMPORTED)
set_target_properties(Clipper::Clipper PROPERTIES IMPORTED_LOCATION ${CLIPPER_LIBRARIES})
set_target_properties(Clipper::Clipper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CLIPPER_INCLUDE_DIRS})
if(CLIPPER_LIBRARIES_RELEASE AND CLIPPER_LIBRARIES_DEBUG)
set_target_properties(Clipper::Clipper PROPERTIES
IMPORTED_LOCATION_DEBUG ${CLIPPER_LIBRARIES_DEBUG}
IMPORTED_LOCATION_RELWITHDEBINFO ${CLIPPER_LIBRARIES_RELEASE}
IMPORTED_LOCATION_RELEASE ${CLIPPER_LIBRARIES_RELEASE}
IMPORTED_LOCATION_MINSIZEREL ${CLIPPER_LIBRARIES_RELEASE}
)
endif()
endif()
pynest2d-4.13-beta/cmake/FindNLopt.cmake 0000664 0000000 0000000 00000004571 14074277577 0020074 0 ustar 00root root 0000000 0000000 #Find NLopt library.
#The following variables are set
#
#NLopt_FOUND
#NLopt_INCLUDE_DIRS
#NLopt_LIBRARIES
#
#It searches the environment variable $NLopt_PATH automatically.
unset(NLopt_FOUND CACHE)
unset(NLopt_INCLUDE_DIRS CACHE)
unset(NLopt_LIBRARIES CACHE)
unset(NLopt_LIBRARIES_RELEASE CACHE)
unset(NLopt_LIBRARIES_DEBUG CACHE)
if($ EQUAL "debug")
set(NLopt_BUILD_TYPE DEBUG)
else()
set(NLopt_BUILD_TYPE RELEASE)
endif()
find_path(NLopt_INCLUDE_DIRS nlopt.hpp
$ENV{NLopt_PATH}
$ENV{NLopt_PATH}/cpp/
$ENV{NLopt_PATH}/include/
${CMAKE_PREFIX_PATH}/include/nlopt
${CMAKE_PREFIX_PATH}/include/
/opt/local/include/
/opt/local/include/nlopt/
/usr/local/include/
/usr/local/include/nlopt/
/usr/include
/usr/include/nlopt/
)
set(LIB_SEARCHDIRS
$ENV{NLopt_PATH}
$ENV{NLopt_PATH}/cpp/
$ENV{NLopt_PATH}/cpp/build/
$ENV{NLopt_PATH}/lib/
$ENV{NLopt_PATH}/lib/nlopt/
${CMAKE_PREFIX_PATH}/lib/
${CMAKE_PREFIX_PATH}/lib/nlopt/
/opt/local/lib/
/opt/local/lib/nlopt/
/usr/local/lib/
/usr/local/lib/nlopt/
/usr/lib/nlopt
)
set(_deb_postfix "d")
find_library(NLopt_LIBRARIES_RELEASE nlopt ${LIB_SEARCHDIRS})
find_library(NLopt_LIBRARIES_DEBUG nlopt${_deb_postfix} ${LIB_SEARCHDIRS})
if(NLopt_LIBRARIES_${NLopt_BUILD_TYPE})
set(NLopt_LIBRARIES "${NLopt_LIBRARIES_${NLopt_BUILD_TYPE}}")
else()
set(NLopt_LIBRARIES "${NLopt_LIBRARIES_RELEASE}")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NLopt
"NLopt library cannot be found. Consider set NLopt_PATH environment variable"
NLopt_INCLUDE_DIRS
NLopt_LIBRARIES
)
mark_as_advanced(NLopt_INCLUDE_DIRS NLopt_LIBRARIES)
if(NLopt_FOUND)
add_library(NLopt::nlopt UNKNOWN IMPORTED)
set_target_properties(NLopt::nlopt PROPERTIES IMPORTED_LOCATION ${NLopt_LIBRARIES})
set_target_properties(NLopt::nlopt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${NLopt_INCLUDE_DIRS})
if(NLopt_LIBRARIES_RELEASE AND NLopt_LIBRARIES_DEBUG)
set_target_properties(NLopt::nlopt PROPERTIES
IMPORTED_LOCATION_DEBUG ${NLopt_LIBRARIES_DEBUG}
IMPORTED_LOCATION_RELWITHDEBINFO ${NLopt_LIBRARIES_RELEASE}
IMPORTED_LOCATION_RELEASE ${NLopt_LIBRARIES_RELEASE}
IMPORTED_LOCATION_MINSIZEREL ${NLopt_LIBRARIES_RELEASE}
)
endif()
endif()
pynest2d-4.13-beta/cmake/FindSIP.cmake 0000664 0000000 0000000 00000006040 14074277577 0017464 0 ustar 00root root 0000000 0000000 #Find SIP
#~~~~~~~~
#
#SIP website: http://www.riverbankcomputing.co.uk/sip/index.php
#
#Find the installed version of SIP. FindSIP should be called after Python has
#been found.
#
#This file defines the following variables:
#
#SIP_VERSION - SIP version.
#SIP_EXECUTABLE - Path to the SIP executable.
#SIP_INCLUDE_DIRS - The SIP include directories.
#
#Copyright (c) 2007, Simon Edwards
#Redistribution and use is allowed according to the terms of the BSD license.
#For details see the accompanying COPYING-CMAKE-SCRIPTS file.
if(APPLE)
#Workaround for broken FindPythonLibs. It will always find Python 2.7 libs on OSX.
set(CMAKE_FIND_FRAMEWORK LAST)
endif()
#FIXME: Use the new FindPython3 module rather than these. New in CMake 3.12.
#However currently that breaks on our CI server, since the CI server finds the built-in Python3.6 and then doesn't find the headers.
find_package(PythonInterp 3.5 REQUIRED)
find_package(PythonLibs 3.5 REQUIRED)
#Define variables that are available in FindPython3, so there's no need to branch off in the later part.
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
set(Python3_LIBRARIES ${PYTHON_LIBRARIES})
execute_process(
COMMAND ${Python3_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(plat_specific = False, standard_lib = False))"
RESULT_VARIABLE _process_status
OUTPUT_VARIABLE _process_output
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(${_process_status} EQUAL 0)
string(STRIP ${_process_output} Python3_SITELIB)
else()
message(FATAL_ERROR "Failed to get Python3_SITELIB. Error: ${_process_output}")
endif()
execute_process(
COMMAND ${Python3_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(plat_specific = True, standard_lib = False))"
RESULT_VARIABLE _process_status
OUTPUT_VARIABLE _process_output
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(${_process_status} EQUAL 0)
string(STRIP ${_process_output} Python3_SITEARCH)
else()
message(FATAL_ERROR "Failed to get Python3_SITEARCH. Error: ${_process_output}")
endif()
get_filename_component(_python_binary_path ${Python3_EXECUTABLE} DIRECTORY)
find_program(SIP_EXECUTABLE sip
HINTS ${CMAKE_PREFIX_PATH}/bin ${CMAKE_INSTALL_PATH}/bin ${_python_binary_path} ${Python3_SITELIB}/PyQt5
)
find_path(SIP_INCLUDE_DIRS sip.h
HINTS ${CMAKE_PREFIX_PATH}/include ${CMAKE_INSTALL_PATH}/include ${Python3_INCLUDE_DIRS} ${Python3_SITELIB}/PyQt5
)
execute_process(
COMMAND ${Python3_EXECUTABLE} -c "import sip; print(sip.SIP_VERSION_STR)"
RESULT_VARIABLE _process_status
OUTPUT_VARIABLE _process_output
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(${_process_status} EQUAL 0)
string(STRIP ${_process_output} SIP_VERSION)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SIP REQUIRED_VARS SIP_EXECUTABLE SIP_INCLUDE_DIRS VERSION_VAR SIP_VERSION)
if(SIP_FOUND)
include(${CMAKE_CURRENT_LIST_DIR}/SIPMacros.cmake)
endif()
mark_as_advanced(SIP_EXECUTABLE SIP_INCLUDE_DIRS SIP_VERSION)
pynest2d-4.13-beta/cmake/Findlibnest2d.cmake 0000664 0000000 0000000 00000001717 14074277577 0020725 0 ustar 00root root 0000000 0000000 # Copyright (c) 2020 Ultimaker B.V.
# pynest2d is released under the terms of the LGPLv3 or higher.
# This script finds libnest2d on your computer.
#
# The output of this script is the following variables:
# - LIBNEST2D_INCLUDE_DIR: The include directory for libnest2d.
find_package(PkgConfig) # To easily find files on your computer.
# First try with packageconfig to get a beginning of an idea where to search.
pkg_check_modules(PC_LIBNEST2D QUIET libnest2d)
find_path(LIBNEST2D_INCLUDE_DIRS NAMES libnest2d/libnest2d.hpp HINTS
${PC_LIBNEST2D_INCLUDE_DIRS}
${PC_LIBNEST2D_INCLUDE_DIRS}/libnest2d
${CMAKE_PREFIX_PATH}/include/
${CMAKE_PREFIX_PATH}/include/libnest2d
/opt/local/include/
/opt/local/include/libnest2d/
/usr/local/include/
/usr/local/include/libnest2d/
/usr/include
/usr/include/libnest2d/
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBNEST2D DEFAULT_MSG
LIBNEST2D_INCLUDE_DIRS)
pynest2d-4.13-beta/cmake/SIPMacros.cmake 0000664 0000000 0000000 00000012246 14074277577 0020035 0 ustar 00root root 0000000 0000000 #Macros for SIP
#~~~~~~~~~~~~~~
#Copyright (c) 2007, Simon Edwards
#Redistribution and use is allowed according to the terms of the BSD license.
#For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
#SIP website: http://www.riverbankcomputing.co.uk/sip/index.php
#
#This file defines the following macros:
#
#ADD_SIP_PYTHON_MODULE (MODULE_NAME MODULE_SIP [library1, libaray2, ...])
# Specifies a SIP file to be built into a Python module and installed.
# MODULE_NAME is the name of Python module including any path name. (e.g.
# os.sys, Foo.bar etc). MODULE_SIP the path and filename of the .sip file to
# process and compile. libraryN are libraries that the Python module, which
# is typically a shared library, should be linked to. The built module will
# also be installed into Python's site-packages directory.
#
#The behaviour of the ADD_SIP_PYTHON_MODULE macro can be controlled by a number
#of variables:
#
#SIP_INCLUDE_DIRS - List of directories which SIP will scan through when looking
# for included .sip files. (Corresponds to the -I option for SIP.)
#
#SIP_TAGS - List of tags to define when running SIP. (Corresponds to the -t
# option for SIP.)
#
#SIP_CONCAT_PARTS - An integer which defines the number of parts the C++ code of
# each module should be split into. Defaults to 8. (Corresponds to the -j
# option for SIP.)
#
#SIP_DISABLE_FEATURES - List of feature names which should be disabled running
# SIP. (Corresponds to the -x option for SIP.)
#
#SIP_EXTRA_OPTIONS - Extra command line options which should be passed on to
# SIP.
set(SIP_INCLUDE_DIRS)
set(SIP_TAGS)
set(SIP_CONCAT_PARTS 8)
set(SIP_DISABLE_FEATURES)
set(SIP_EXTRA_OPTIONS)
macro(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP)
set(EXTRA_LINK_LIBRARIES ${ARGN})
string(REPLACE "." "/" _x ${MODULE_NAME})
get_filename_component(_parent_module_path ${_x} PATH)
get_filename_component(_child_module_name ${_x} NAME)
get_filename_component(_module_path ${MODULE_SIP} PATH)
get_filename_component(_abs_module_sip ${MODULE_SIP} ABSOLUTE)
#We give this target a long logical target name.
#(This is to avoid having the library name clash with any already install
#library names. If that happens then CMake dependency tracking gets
#confused.)
string(REPLACE "." "_" _logical_name ${MODULE_NAME})
set(_logical_name "python_module_${_logical_name}")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_module_path}) #Output goes in this dir.
set(_sip_includes)
foreach(_inc ${SIP_INCLUDES})
get_filename_component(_abs_inc ${_inc} ABSOLUTE)
list(APPEND _sip_includes -I ${_abs_inc})
endforeach(_inc)
set(_sip_tags)
foreach(_tag ${SIP_TAGS})
list(APPEND _sip_tags -t ${_tag})
endforeach(_tag)
set(_sip_x)
foreach(_x ${SIP_DISABLE_FEATURES})
list(APPEND _sip_x -x ${_x})
endforeach(_x ${SIP_DISABLE_FEATURES})
set(_message "-DMESSAGE=Generating CPP code for module ${MODULE_NAME}")
set(_sip_output_files)
foreach(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS})
if(${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS})
set(_sip_output_files ${_sip_output_files} ${CMAKE_CURRENT_BINARY_DIR}/${_module_path}/sip${_child_module_name}part${CONCAT_NUM}.cpp)
endif( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS})
endforeach(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS})
#Suppress warnings.
if(PEDANTIC)
if(MSVC)
#4996 deprecation warnings (bindings re-export deprecated methods).
#4701 potentially uninitialized variable used (sip generated code).
#4702 unreachable code (sip generated code).
add_definitions(/wd4996 /wd4701 /wd4702)
else(MSVC)
#Disable all warnings.
add_definitions(-w)
endif(MSVC)
endif(PEDANTIC)
add_custom_command(
OUTPUT ${_sip_output_files}
COMMAND ${CMAKE_COMMAND} -E echo ${message}
COMMAND ${CMAKE_COMMAND} -E touch ${_sip_output_files}
COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS} -j ${SIP_CONCAT_PARTS} -c ${CMAKE_CURRENT_BINARY_DIR}/${_module_path} ${_sip_includes} ${_abs_module_sip}
DEPENDS ${_abs_module_sip} ${SIP_EXTRA_FILES_DEPEND}
)
#Not sure if type MODULE could be uses anywhere, limit to Cygwin for now.
if(CYGWIN OR APPLE)
add_library(${_logical_name} MODULE ${_sip_output_files} ${SIP_EXTRA_SOURCE_FILES})
else(CYGWIN OR APPLE)
add_library(${_logical_name} SHARED ${_sip_output_files} ${SIP_EXTRA_SOURCE_FILES})
endif(CYGWIN OR APPLE)
if(NOT APPLE)
target_link_libraries(${_logical_name} ${Python3_LIBRARIES})
endif(NOT APPLE)
target_link_libraries(${_logical_name} ${EXTRA_LINK_LIBRARIES})
if(APPLE)
set_target_properties(${_logical_name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif(APPLE)
set_target_properties(${_logical_name} PROPERTIES PREFIX "" OUTPUT_NAME ${_child_module_name})
if(WIN32)
set_target_properties(${_logical_name} PROPERTIES SUFFIX ".pyd" IMPORT_PREFIX "_")
endif(WIN32)
install(TARGETS ${_logical_name} DESTINATION "${Python3_SITEARCH}/${_parent_module_path}")
endmacro(ADD_SIP_PYTHON_MODULE) pynest2d-4.13-beta/src/ 0000775 0000000 0000000 00000000000 14074277577 0014735 5 ustar 00root root 0000000 0000000 pynest2d-4.13-beta/src/BottomLeftConfig.sip 0000664 0000000 0000000 00000002233 14074277577 0020657 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
struct BottomLeftConfig
{
%Docstring "deindented"
Configuration class for the BLPlacer class.
With this you can configure some parameters on how the BLPlacer places
objects.
The following attributes can be set:
* min_obj_distance (default 0):
Minimum distance between objects. This seems to not be used by libnest2d
at the moment.
* epsilon (default 1):
Resolution of placement. The lower the epsilon, the more placements will
be attempted, resulting in better placement but longer computation time.
* allow_rotations (default False):
Whether the placer is allowed to rotate the items. This placer will only
attempt 90 degree rotations if this setting is set to True.
%End
%TypeHeaderCode
#include
using BottomLeftConfig = BLConfig; //Specialise the templated BLConfig class since SIP doesn't deal with templates.
%End
long min_obj_distance;
long epsilon;
bool allow_rotations;
}; pynest2d-4.13-beta/src/Box.sip 0000664 0000000 0000000 00000006562 14074277577 0016213 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
class Box
{
%Docstring "deindented"
A rectangular shape, to be used as a bin or to be placed in the scene.
%End
%TypeHeaderCode
#include
%End
public:
Box(Point center);
%Docstring "deindented"
Create a 0x0 box at the specified position.
It's intended that you adjust the size later.
:param center: The coordinates of the center of the box.
%End
Box(Point min, Point max);
%Docstring "deindented"
Create a box that spans between two points.
The ``max`` parameter MUST have greater X and Y coordinates than the
``min`` parameter. If this is not the case, the box will get a negative
width or height and madness will ensue.
The width and height of the box will automatically be determined from
the difference between these two points. The centre will be the average
of the two points.
:param min: The minimum coordinates of the box.
:param max: The maximum coordinates of the box.
%End
Box(long width, long height);
%Docstring "deindented"
Create a box with the specified dimensions.
The box will be centered on the 0,0 coordinate.
:param width: The width of the box.
:param height: The height of the box.
%End
Box(long width, long height, Point center);
%Docstring "deindented"
Create a box with the specified dimensions, centered in a specified
location.
:param width: The width of the box.
:param height: The height of the box.
:param center: The coordinates of the center of the box.
%End
static Box infinite(Point center);
%Docstring "deindented"
Create a box with theoretically infinite dimensions.
This is useful as a bin to place items in without necessarily bounding the
placement of these items at any limit.
The center of the box will be used if items are aligned by the placer to the
center of the bin.
:param center: The theoretical center of the box (to be treated as if it's
just a very big box rather than mathematically infinite).
:return: A box with theoretically infinite dimensions.
%End
Point minCorner();
%Docstring "deindented"
Returns the minimum coordinates that are still within the box.
:return: The minimum coordinates of the box.
%End
Point maxCorner();
%Docstring "deindented"
Returns the maximum coordinates that are still within the box.
:return: The maximum coordinates of the box.
%End
long width();
%Docstring "deindented"
Returns the width of the box, its span in the X direction.
:return: The width of the box.
%End
long height();
%Docstring "deindented"
Returns the height of the box, its span in the Y direction.
:return: The height of the box.
%End
long area();
%Docstring "deindented"
Returns the surface area of the box, i.e. the width times the height of
the box.
:return: The surface area of the box.
%End
Point center();
%Docstring "deindented"
Returns the center of the box, exactly in between the ``minCorner()``
and the ``maxCorner()``.
:return: The center of the box.
%End
}; pynest2d-4.13-beta/src/Circle.sip 0000664 0000000 0000000 00000002621 14074277577 0016654 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
class Circle
{
%Docstring
A circular shape, to be used as bin or to be placed in the scene.
%End
%TypeHeaderCode
#include
%End
public:
Circle();
%Docstring
Construct a circle centered at 0,0 with radius 0.
%End
Circle(Point center, double r);
%Docstring
Construct a circle centered at a specified location and with a specified
radius.
:param center: The position of the center of the circle.
:param r: The radius of the new circle.
%End
Point center();
%Docstring
Gives the center position of the circle.
:return: The center of the circle.
%End
void center(Point center);
%Docstring
Changes the center position of the circle.
:param center: The new center of the circle.
%End
double radius();
%Docstring
Gives the radius of the circle.
:return: The radius of the circle.
%End
void radius(double r);
%Docstring
Changes the radius of the circle.
:param r: The new radius for the circle.
%End
double area();
%Docstring
Computes the area of the circle.
The area is only a function of the radius: pi * r ** 2.
:return: The area of the circle.
%End
}; pynest2d-4.13-beta/src/DJDHeuristicConfig.sip 0000664 0000000 0000000 00000003667 14074277577 0021075 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
struct DJDHeuristicConfig
{
%Docstring
This structure contains configuration options for the DJD Heuristic of
selecting objects to place.
The following options are available:
* try_reverse_order (default True):
If true, the algorithm will try to place pairs and triplets in all
possible orders. It will have a hugely negative impact on performance.
* try_pairs (default True):
Whether to try pairs of items to pack. It will add a quadratic component
to the complexity.
* try_triplets (default False):
Whether to try groups of 3 items to pack. This could be very slow for
large numbers of items (>100) as it adds a cubic component to the complexity.
* initial_fill_proportion (default 1/3):
The initial fill proportion of the bin area that will be filled before
trying items one by one, or pairs or triplets.
The initial fill proportion suggested by Lopez-Camacho is one third of
the area of the bin.
* waste_increment (default 0.1):
How much is the acceptable waste incremented at each iteration.
* allow_parallel (default True):
Allow parallel jobs for filling multiple bins. This will decrease the
solution quality but can greatly boost up performance for large numbers
of items.
* force_parallel (default False):
Always use parallel processing if the items don't fit into one bin.
%End
%TypeHeaderCode
#include
using DJDHeuristicConfig = DJDHeuristic::Config; //Make an alias since SIP doesn't deal with namespaces.
%End
bool try_reverse_order;
bool try_pairs;
bool try_triplets;
double initial_fill_proportion;
double waste_increment;
double allow_parallel;
bool force_parallel;
}; pynest2d-4.13-beta/src/Item.sip 0000664 0000000 0000000 00000033257 14074277577 0016362 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
class Item
{
%Docstring
An item represents something that needs to be fit in the scene.
An item has a certain shape. For these Python bindings that shape will
always be a polygon.
After the nesting has taken place, the item will be transformed. The
transformation is encoded in a translation and a rotation. You may also
manually scale the item if necessary. The transformed shape can be
computed with the transformedShape() function. The original vertex
coordinates are not modified then. The item will also be placed in a
certain bin, which is normally the first bin unless the first bin is
packed completely full.
An item can be fixed in place with the markAsFixedInBin() function,
preventing the nester to move it. It only blocks other items
from being placed then.
%End
%TypeHeaderCode
#include
%End
public:
Item(PyObject* vertex_list);
%Docstring
Create a new item from a list of vertices.
Each vertex must be a Point instance.
:param vertex_list: A list of Points that form the vertices of the
polygonal shape of this item.
%End
%MethodCode
if(!PyList_Check(a0))
{
return NULL;
}
std::vector vertices;
const size_t size = PyList_GET_SIZE(a0);
vertices.reserve(size);
PyErr_Clear(); //To allow us to test if any Python errors occurred.
for(size_t i = 0; i < size; ++i)
{
PyObject* vertex = PyList_GET_ITEM(a0, i);
const long x = PyLong_AsLong(PyObject_CallMethod(vertex, "x", NULL));
const long y = PyLong_AsLong(PyObject_CallMethod(vertex, "y", NULL));
vertices.emplace_back(x, y);
if(PyErr_Occurred() != NULL) //Something broke. Need to clean up. Maybe the input is not proper Point instances.
{
return NULL;
}
}
sipCpp = new Item(vertices); //Makes a copy of the vertices!
%End
int binId();
%Docstring
The bin that this item is assigned to, or -1 if it's not (yet) assigned
to any bin.
The assigned bin is a version of the bin shape. If all objects fit in
one bin, their bin IDs will all be 0. If they don't fit, new bins will
be created and some objects will be put in the new bin.
:return: The currently assigned bin of this item.
%End
void binId(int idx);
%Docstring
Assign this item to a bin.
Assigning to a negative number effectively takes this object out of all
bins. Use -1 to unassign the item from all bins.
:param idx: The index of the bin to assign the item to.
%End
bool isFixed();
%Docstring
Whether this item is fixed in place, not able to be moved by the nester.
If the item is fixed, the nester is not allowed to move it and must
place other items around it.
:return: Whether the item is fixed in a certain bin.
%End
bool isDisallowedArea();
%Docstring
Whether this item is a disallowed area, not able to be moved by the
nester and not grouped together with other items.
If the item is a disallowed area, the nester is not allowed to move it
and not allowed to place other items in the same spot. Contrary to
simple fixed items, other items will not be packed nearby disallowed
areas by the optimization.
:return Whether the item is a disallowed area.
%End
void markAsFixedInBin(int binid);
%Docstring
Make this item a fixed item in a certain bin.
If the item is fixed, the nester is not allowed to move it and must
place other items around it in that bin.
This currently only works with the FirstFit selector (which is the
default).
:param binid: The bin in which this item is fixed.
%End
void markAsDisallowedAreaInBin(int binid);
%Docstring
Make this item a disallowed area in a certain bin.
If the item is a disallowed area, the nester is not allowed to move it
and not allowed to place other items in the same spot. Contrary to
simple fixed items, other items will not be packed nearby disallowed
areas by the optimization.
This currently only works with the FirstFit selector (which is the
default).
:param binid: The bin in which this item is a disallowed area.
%End
int priority();
%Docstring
Gives the current priority of selecting this item.
Items with greater priority (higher number) get selected first by the
selectors.
:return: The priority of selecting this item.
%End
void priority(int priority);
%Docstring
Sets the priority of selecting this item.
Items with greater priority (higher number) get selected first by the
selectors. This causes them to be placed in earlier bins and perhaps
more towards the point where the objects get aligned to (depending on
the placer).
The priority is not a guarantee. The selector may still select different
items first. It only serves as an intuitive way to steer which objects
are the most important to be placed.
:param priority: The priority to give to this item.
%End
std::string toString();
%Docstring
Give a string representation of this item.
This will give a list of all the vertices in the contour of the item.
:return: A string representation of the item.
%End
Point vertex(long idx);
%Docstring
Get a vertex from the contour of the item.
:param idx: The index of the vertex. Should not be vertexCount() or
higher.
:return: A point along the contour of the item.
%End
void setVertex(long idx, Point v);
%Docstring
Change a vertex on the contour of the item.
:param idx: The index of the vertex to change. Should not be
vertexCount() or higher.
:param v: The new coordinates of that vertex.
%End
double area();
%Docstring
Compute the surface area of the item.
This is a signed area. If the polygon has the wrong winding order, this
area will be negative.
:return: The surface area of the item.
%End
bool isContourConvex();
%Docstring
Compute whether the shape of this item is completely convex.
The result is cached, so it is safe to query convexity multiple times on
the same item as long as the item is not modified in between.
:return: True if the item is convex, or False otherwise.
%End
bool isHoleConvex(long holeindex);
%Docstring
For holes in the shape, return if the hole is convex.
:param holeindex: The index of the hole in the shape. Should be less
than holeCount().
:return: True if the specified hole is convex, or False if it's concave.
%End
bool areHolesConvex();
%Docstring
Returns whether all holes are convex.
This is the same as going through all holes and querying isHoleConvex()
for all of them.
:return: True if all holes in the shape are convex, or False if there is
at least one concave hole.
%End
long vertexCount();
%Docstring
Get the number of vertices in total in the shape of the item.
:return: The number of vertices in the contour.
%End
long holeCount();
%Docstring
Get the number of holes in the shape of the item.
:return: The number of holes in the shape.
%End
bool isInside(Point p);
%Docstring
Tests whether a point is contained in the shape of this item.
:param p: The point to test whether it's contained in this item.
:return: True if the point is inside the shape, or False if it's
outside.
%End
bool isInside(Item sh);
%Docstring
Tests whether a different item is engulfed wholly inside of this item.
:param sh: The item to test for whether it is inside of this item.
:return: True if the item is wholly engulfed in this item, or False if
it falls partially or completely outside of this item.
%End
bool isInside(Box box);
%Docstring
Tests whether the box falls completely inside of this item.
:param box: The box to test for being contained in this item.
:return: True if the box is wholly engulfed in this item, or False if it falls partially or completely outside of this item.
%End
bool isInside(Circle circle);
%Docstring
Tests whether the circle falls completely inside of this item.
:param circle: The circle to test for being contained in this item.
:return: True if the circle is wholly engulfed in this item, or False if it falls partially or completely outside of this item.
%End
Box boundingBox();
%Docstring
Return the smallest axis-aligned bounding box around this item.
:return: A bounding box around this item.
%End
Point referenceVertex();
%Docstring
Return a vertex that serves as a reference for this item's shape.
The vertex will always be the same if the vertices of the item are the
same, even if those vertices are in a different order or if a different
item has precisely the same vertices. This can be used for instance to
always start iteration in the same spot if the shape is the same.
:return: A vertex that serves as reference for the shape.
%End
Point rightmostTopVertex();
%Docstring
Returns the right-most vertex (highest X coordinate). Or if multiple
vertices are equally far right, the top-most one of those (highest Y
coordinate).
This works on the transformed shape.
:return: The highest of the right-most vertices.
%End
Point leftmostBottomVertex();
%Docstring
Returns the left-most vertex (lowest X coordinate). Or if multiple
vertices are equally far left, the bottom-most one of those (lowest Y
coordinate).
This works on the transformed shape.
:return: The lowest of the left-most vertices.
%End
void translate(Point delta);
%Docstring
Move the item relatively in a certain direction.
The vertices are not actually transformed in-place, but the
transformation of the item is changed. The moved vertices can be found
by calling transformedShape().
To arrive at the transformed shape of an item, the rotation is applied
first, then the translation. Translation is only afterwards, so first
translating the object and then rotating it will not cause the item to
rotate by the translation vector around 0. It will rotate around its
original 0 coordinate instead.
:param delta: The motion vector by which to move this item.
%End
Point translation();
%Docstring
Get the current translation of the item.
This gets changed by arranging the items in the bins.
:return: The current translation of the item.
%End
void rotate(double radians);
%Docstring
Rotate the item by a certain amount.
The vertices are not actually transformed in-place, but the
transformation of the item is changed. The moved vertices can be found
by calling transformedShape().
:param radians: The amount of rotation to apply, in radians. A positive
rotation will rotate the item counter-clockwise.
%End
double rotation();
%Docstring
Get the current amount of rotation applied to the model.
This gets changed by arranging the items in the bins.
:return: The current rotation of the model.
%End
void inflation(long distance);
%Docstring
Offset the shape by a certain amount. This will make the shape wider in
all directions, as if performing a Minkowski sum with a circle with the
specified distance as radius.
A negative distance will result in an inset of the original shape.
:param distance: The distance by which to offset the shape.
%End
long inflation();
%Docstring
Get the current amount of inflation from the original shape.
:return The current amount of inflation.
%End
Item transformedShape();
%Docstring
Create a new item that has the transformation of this item applied to
its vertices.
From the new item you can get the vertex coordinates to get the
polygonal coordinates of the transformed shape.
:return: A copy of this item, but with the transformation applied to its
vertices.
%End
void resetTransformation();
%Docstring
Remove all transformations on this item, reverting it to its original
state.
%End
static bool intersects(Item sh1, Item sh2);
%Docstring
Test whether two items intersect.
Two items intersect only if they have a non-zero area of overlap.
:param sh1: One of the items to test intersection with.
:param sh2: The other item to test intersection with.
:return: True if they intersect, or False if they are disjoint.
%End
static bool touches(Item sh1, Item sh2);
%Docstring
Test whether two items touch.
Touching items includes the edge case where two items touch only on a vertex or on an edge but don't necessarily have any positive area of overlap. They may also just touch on the contour of the shape.
If two items intersect, they also always touch.
%End
}; pynest2d-4.13-beta/src/ItemGroup.sip 0000664 0000000 0000000 00000004517 14074277577 0017374 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
%MappedType ItemGroup
{
%TypeHeaderCode
#include
#include
using ItemGroup = PlacementStrategyLike::ItemGroup; //Make an alias here since SIP doesn't namespace syntax nor template syntax.
%End
%ConvertFromTypeCode //From ItemGroup to Python list.
const long size = sipCpp->size();
if(size < 0)
{
return NULL;
}
PyObject* result_list = PyList_New(size);
if(!result_list)
{
return NULL;
}
for(size_t i = 0; i < size; ++i)
{
Item item = sipCpp->at(0);
PyObject* python_item = sipConvertFromInstance(&item, sipClass_Item, sipTransferObj);
if(!python_item)
{
Py_DECREF(result_list);
return NULL;
}
PyList_SET_ITEM(result_list, i, python_item);
}
return result_list;
%End
%ConvertToTypeCode //From Python list to ItemGroup.
PyObject* iterator = PyObject_GetIter(sipPy);
if(!sipIsErr) //We're only checking if it can be converted.
{
//Must be any iterable.
const bool iterable = (iterator != NULL);
Py_XDECREF(iterator);
return iterable;
}
ItemGroup* result = new ItemGroup();
PyObject* list_item;
while(list_item = PyIter_Next(iterator))
{
if(!sipCanConvertToInstance(list_item, sipClass_Item, SIP_NOT_NONE))
{
PyErr_Format(PyExc_TypeError, "Object in iterable cannot be converted to a libnest2d Item.");
*sipIsErr = 1;
break;
}
int state;
Item* item = reinterpret_cast- (sipConvertToInstance(list_item, sipClass_Item, 0, SIP_NOT_NONE, &state, sipIsErr));
if(!*sipIsErr)
{
result->push_back(*item);
}
sipReleaseInstance(item, sipClass_Item, state);
Py_DECREF(list_item);
}
Py_DECREF(iterator);
if(*sipIsErr)
{
delete result;
return 0;
}
*sipCppPtr = result;
return sipGetState(sipTransferObj);
%End
}; pynest2d-4.13-beta/src/NfpConfig.sip 0000664 0000000 0000000 00000004705 14074277577 0017331 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
struct NfpConfig
{
%Docstring
This is a configuration structure to configure the NfpPPlacer. It has
several attributes to configure how it places items.
The following options are available:
* alignment (default CENTER):
Where to align the resulting packed pile.
* starting_point (default CENTER):
Where to start placing items in the bin.
* rotations (default [0, 0.5 * pi, pi, 1.5 * pi]):
Rotations to try to place the object in. More rotations may cause the objects to be packed closer together, but also significantly increases computation time.
* accuracy (default 0.65):
How far to search for the best placement. 0.0 is not very accurate, but computes fast. 1.0 is the best accuracy, but takes a lot of computation power.
* explore_holes (default False):
Whether to allow placing items inside holes in other shapes. This functionality doesn't currently work in libnest2d.
* parallel (default True):
Whether to try different options in multiple threads in parallel.
%End
%TypeHeaderCode
#include
using NfpConfig = NfpPConfig; //Specialise the templated NfpPConfig class since SIP doesn't deal with templates.
%End
enum class Alignment
{
CENTER,
BOTTOM_LEFT,
BOTTOM_RIGHT,
TOP_LEFT,
TOP_RIGHT,
DONT_ALIGN
};
Alignment alignment;
Alignment starting_point;
std::vector rotations
{
%GetCode
sipPy = PyList_New(sipCpp->rotations.size());
for(size_t i = 0; i < sipCpp->rotations.size(); ++i)
{
PyList_SET_ITEM(sipPy, i, PyFloat_FromDouble(sipCpp->rotations[i]));
}
%End
%SetCode
if(!PyList_Check(sipPy))
{
sipErr = 1;
return 1;
}
sipCpp->rotations.clear();
PyErr_Clear();
size_t size = PyList_Size(sipPy);
sipCpp->rotations.reserve(size);
for(size_t i = 0; i < size; ++i)
{
sipCpp->rotations.push_back(PyFloat_AsDouble(PyList_GET_ITEM(sipPy, i)));
}
return 0;
%End
};
double accuracy;
bool explore_holes;
bool parallel;
}; pynest2d-4.13-beta/src/Point.sip 0000664 0000000 0000000 00000001634 14074277577 0016547 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
class Point
{
%Docstring
Represents a point in 2D space or a 2D vector.
%End
%TypeHeaderCode
#include
%End
public:
Point(long x, long y);
%Docstring
Construct a new point with the given coordinates.
:param x: The X coordinate of the new point.
:param y: The Y coordinate of the new point.
%End
long x();
%Docstring
Return the X coordinate of the point.
:return: The X coordinate of the point.
%End
%MethodCode
sipRes = sipCpp->X; //Use Clipper implementation.
%End
long y();
%Docstring
Return the Y coordinate of the point.
:return: The Y coordinate of the point.
%End
%MethodCode
sipRes = sipCpp->Y; //Use Clipper implementation.
%End
}; pynest2d-4.13-beta/src/Pynest2D.sip 0000664 0000000 0000000 00000011647 14074277577 0017133 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
%Module(name = pynest2d, call_super_init = True)
%Include BottomLeftConfig.sip
%Include Box.sip
%Include Circle.sip
%Include DJDHeuristicConfig.sip
%Include Item.sip
%Include ItemGroup.sip
%Include NfpConfig.sip
%Include Point.sip
%Include Rectangle.sip
%Include String.sip
%ModuleHeaderCode
#include //Use the Subplex local optimizer. Also imported by libnest2d.hpp but somehow this needs to be imported in correct order!
#include
namespace libnest2d{
namespace placers{}
}
using namespace libnest2d;
using namespace placers;
%End
/*!
* Convert ranges of Item objects to and from Python lists.
*/
%MappedType std::vector
-
{
%TypeHeaderCode
#include
#include
using ItemRange = std::pair::iterator, std::vector
- ::iterator>;
%End
%ConvertFromTypeCode //From std::vector
- to Python list.
const long size = sipCpp->size();
if(size < 0)
{
return NULL;
}
PyObject* result_list = PyList_New(size);
if(!result_list)
{
return NULL;
}
for(size_t i = 0; i < size; ++i)
{
Item* item = sipCpp->at(0);
PyObject* python_item = sipConvertFromInstance(item, sipClass_Item, sipTransferObj);
if(!python_item)
{
Py_DECREF(result_list);
return NULL;
}
PyList_SET_ITEM(result_list, i, python_item);
}
return result_list;
%End
%ConvertToTypeCode //From Python list to vector of Items.
PyObject* iterator = PyObject_GetIter(sipPy);
if(!sipIsErr) //We're only checking if it can be converted.
{
//Must be any iterable.
const bool iterable = (iterator != NULL);
Py_XDECREF(iterator);
return iterable;
}
std::vector
- * storage_vector = new std::vector
- ();
PyObject* list_item;
while(list_item = PyIter_Next(iterator))
{
if(!sipCanConvertToInstance(list_item, sipClass_Item, SIP_NOT_NONE))
{
PyErr_Format(PyExc_TypeError, "Object in iterable cannot be converted to a libnest2d Item.");
*sipIsErr = 1;
break;
}
int state;
Item* item = reinterpret_cast
- (sipConvertToInstance(list_item, sipClass_Item, 0, SIP_NOT_NONE, &state, sipIsErr));
if(!*sipIsErr)
{
storage_vector->push_back(item);
}
sipReleaseInstance(item, sipClass_Item, state);
Py_DECREF(list_item);
}
Py_DECREF(iterator);
if(*sipIsErr)
{
delete storage_vector;
return 0;
}
*sipCppPtr = storage_vector;
return sipGetState(sipTransferObj);
%End
};
long nest(std::vector
- items, Box bin, long distance = 1, NfpConfig config = NfpConfig());
%Docstring
Arrange a number of items in bins, packing them closely with the goal to
minimise the number of bins necessary to pack all given items.
This function uses the FirstFit selector and NfpPPlacer in its algorithms,
and Clipper as geometry back-end.
The result of the packing is stored in the transformation of the input
items. You can get the transformed items by calling transformedShape() on
each of the items, or by looking at their rotation and translation. Items
may also be placed on alternative bins if the first bin is not big enough to
fit all items.
:param items: An iterable of Item instances which are the items that need to
be placed in the bins.
:param bin: The shape in which to place these items.
:param distance: (Default 1.) The distance to hold between adjacent items in
the final pack result. Items will not get placed closer than this distance.
Must be at least 1 unit.
:param config: An NfpConfig instance that contains configuration options to
specialize how objects get placed. Defaults will be used if this is not
provided.
:return: The number of bins necessary to fit all items.
%End
%MethodCode
//Pre-process distance.
if(a2 <= 0)
{
a2 = 1; //Need to keep at least 1 unit of distance, or the nester breaks.
}
//Pre-process items.
std::vector
- to_arrange;
to_arrange.reserve(a0->size());
for(Item* item : *a0)
{
to_arrange.push_back(*item);
}
//Pre-process config.
NestConfig<> nest_config(*a3); //NestConfig wraps a placer and selector config. Only with the default selector there is no config, so just the placer then.
sipRes = nest(to_arrange, *a1, a2, nest_config);
for(size_t i = 0; i < a0->size(); ++i)
{
*(a0->at(i)) = to_arrange[i];
}
%End
pynest2d-4.13-beta/src/Rectangle.sip 0000664 0000000 0000000 00000025720 14074277577 0017364 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
class Rectangle
{
%Docstring
A rectangular item. This item can be placed in the bins and arranged
there. Some algorithms may work faster on rectangles than on arbitrary
polygons.
%End
%TypeHeaderCode
#include
%End
public:
Rectangle(long width, long height);
%Docstring
Construct a new rectangle with a specified width and height. The
bottom-left corner of the rectangle will be placed at the 0-coordinate.
:param width: The width of the new rectangle.
:param height: The height of the new rectangle.
%End
long width();
%Docstring
Get the width of this rectangle.
:return: The width of the rectangle.
%End
long height();
%Docstring
Get the height of this rectangle.
:return: The height of the rectangle.
%End
//Members inherited from Item.
int binId();
%Docstring
The bin that this item is assigned to, or -1 if it's not (yet) assigned
to any bin.
The assigned bin is a version of the bin shape. If all objects fit in
one bin, their bin IDs will all be 0. If they don't fit, new bins will
be created and some objects will be put in the new bin.
:return: The currently assigned bin of this item.
%End
void binId(int idx);
%Docstring
Assign this item to a bin.
Assigning to a negative number effectively takes this object out of all
bins. Use -1 to unassign the item from all bins.
:param idx: The index of the bin to assign the item to.
%End
bool isFixed();
%Docstring
Whether this item is fixed in place, not able to be moved by the nester.
If the item is fixed, the nester is not allowed to move it and must
place other items around it.
:return: Whether the item is fixed in a certain bin.
%End
void markAsFixedInBin(int binid);
%Docstring
Make this item a fixed item in a certain bin.
If the item is fixed, the nester is not allowed to move it and must
place other items around it in that bin.
This currently only works with the FirstFit selector (which is the
default).
:param binid: The bin in which this item is fixed.
%End
int priority();
%Docstring
Gives the current priority of selecting this item.
Items with greater priority (higher number) get selected first by the
selectors.
:return: The priority of selecting this item.
%End
void priority(int priority);
%Docstring
Sets the priority of selecting this item.
Items with greater priority (higher number) get selected first by the
selectors. This causes them to be placed in earlier bins and perhaps
more towards the point where the objects get aligned to (depending on
the placer).
The priority is not a guarantee. The selector may still select different
items first. It only serves as an intuitive way to steer which objects
are the most important to be placed.
:param priority: The priority to give to this item.
%End
std::string toString();
%Docstring
Give a string representation of this item.
This will give a list of all the vertices in the contour of the item.
:return: A string representation of the item.
%End
double area();
%Docstring
Compute the surface area of the item.
This is a signed area. If the polygon has the wrong winding order, this
area will be negative.
:return: The surface area of the item.
%End
bool isContourConvex();
%Docstring
Compute whether the shape of this item is completely convex.
The result is cached, so it is safe to query convexity multiple times on
the same item as long as the item is not modified in between.
:return: True if the item is convex, or False otherwise.
%End
bool isHoleConvex(long holeindex);
%Docstring
For holes in the shape, return if the hole is convex.
:param holeindex: The index of the hole in the shape. Should be less
than holeCount().
:return: True if the specified hole is convex, or False if it's concave.
%End
bool areHolesConvex();
%Docstring
Returns whether all holes are convex.
This is the same as going through all holes and querying isHoleConvex()
for all of them.
:return: True if all holes in the shape are convex, or False if there is
at least one concave hole.
%End
long vertexCount();
%Docstring
Get the number of vertices in total in the shape of the item.
:return: The number of vertices in the contour.
%End
long holeCount();
%Docstring
Get the number of holes in the shape of the item.
:return: The number of holes in the shape.
%End
bool isInside(Point p);
%Docstring
Tests whether a point is contained in the shape of this item.
:param p: The point to test whether it's contained in this item.
:return: True if the point is inside the shape, or False if it's
outside.
%End
bool isInside(Item sh);
%Docstring
Tests whether a different item is engulfed wholly inside of this item.
:param sh: The item to test for whether it is inside of this item.
:return: True if the item is wholly engulfed in this item, or False if
it falls partially or completely outside of this item.
%End
bool isInside(Box box);
%Docstring
Tests whether the box falls completely inside of this item.
:param box: The box to test for being contained in this item.
:return: True if the box is wholly engulfed in this item, or False if it falls partially or completely outside of this item.
%End
bool isInside(Circle circle);
%Docstring
Tests whether the circle falls completely inside of this item.
:param circle: The circle to test for being contained in this item.
:return: True if the circle is wholly engulfed in this item, or False if it falls partially or completely outside of this item.
%End
Box boundingBox();
%Docstring
Return the smallest axis-aligned bounding box around this item.
:return: A bounding box around this item.
%End
Point referenceVertex();
%Docstring
Return a vertex that serves as a reference for this item's shape.
The vertex will always be the same if the vertices of the item are the
same, even if those vertices are in a different order or if a different
item has precisely the same vertices. This can be used for instance to
always start iteration in the same spot if the shape is the same.
:return: A vertex that serves as reference for the shape.
%End
Point rightmostTopVertex();
%Docstring
Returns the right-most vertex (highest X coordinate). Or if multiple
vertices are equally far right, the top-most one of those (highest Y
coordinate).
This works on the transformed shape.
:return: The highest of the right-most vertices.
%End
Point leftmostBottomVertex();
%Docstring
Returns the left-most vertex (lowest X coordinate). Or if multiple
vertices are equally far left, the bottom-most one of those (lowest Y
coordinate).
This works on the transformed shape.
:return: The lowest of the left-most vertices.
%End
void translate(Point delta);
%Docstring
Move the item relatively in a certain direction.
The vertices are not actually transformed in-place, but the
transformation of the item is changed. The moved vertices can be found
by calling transformedShape().
To arrive at the transformed shape of an item, the rotation is applied
first, then the translation. Translation is only afterwards, so first
translating the object and then rotating it will not cause the item to
rotate by the translation vector around 0. It will rotate around its
original 0 coordinate instead.
:param delta: The motion vector by which to move this item.
%End
Point translation();
%Docstring
Get the current translation of the item.
This gets changed by arranging the items in the bins.
:return: The current translation of the item.
%End
void rotate(double radians);
%Docstring
Rotate the item by a certain amount.
The vertices are not actually transformed in-place, but the
transformation of the item is changed. The moved vertices can be found
by calling transformedShape().
:param radians: The amount of rotation to apply, in radians. A positive
rotation will rotate the item counter-clockwise.
%End
double rotation();
%Docstring
Get the current amount of rotation applied to the model.
This gets changed by arranging the items in the bins.
:return: The current rotation of the model.
%End
void inflation(long distance);
%Docstring
Offset the shape by a certain amount. This will make the shape wider in
all directions, as if performing a Minkowski sum with a circle with the
specified distance as radius.
A negative distance will result in an inset of the original shape.
:param distance: The distance by which to offset the shape.
%End
long inflation();
%Docstring
Get the current amount of inflation from the original shape.
:return The current amount of inflation.
%End
Item transformedShape();
%Docstring
Create a new item that has the transformation of this item applied to
its vertices.
From the new item you can get the vertex coordinates to get the
polygonal coordinates of the transformed shape.
:return: A copy of this item, but with the transformation applied to its
vertices.
%End
void resetTransformation();
%Docstring
Remove all transformations on this item, reverting it to its original
state.
%End
static bool intersects(Item sh1, Item sh2);
%Docstring
Test whether two items intersect.
Two items intersect only if they have a non-zero area of overlap.
:param sh1: One of the items to test intersection with.
:param sh2: The other item to test intersection with.
:return: True if they intersect, or False if they are disjoint.
%End
static bool touches(Item sh1, Item sh2);
%Docstring
Test whether two items touch.
Touching items includes the edge case where two items touch only on a vertex or on an edge but don't necessarily have any positive area of overlap. They may also just touch on the contour of the shape.
If two items intersect, they also always touch.
%End
}; pynest2d-4.13-beta/src/String.sip 0000664 0000000 0000000 00000003035 14074277577 0016721 0 ustar 00root root 0000000 0000000 //Copyright (c) 2020 Ultimaker B.V.
//pynest2d is released under the terms of the LGPLv3 or higher.
/*!
* Mapping std::string to Python str objects.
*
* Based on implementation of libSavitar.
*/
%MappedType std::string
{
%TypeHeaderCode
#include
%End
%ConvertFromTypeCode
PyObject* result = PyUnicode_DecodeUTF8(sipCpp->c_str(), sipCpp->length(), NULL);
if(!result)
{
result = PyBytes_FromString(sipCpp->c_str());
}
return result;
%End
%ConvertToTypeCode
if(!sipIsErr) //Just a request to check if we can convert.
{
return PyBytes_Check(sipPy) || PyUnicode_Check(sipPy); //We can convert from Python bytes and str.
}
if(sipPy == Py_None) //Convert None to empty string. Happens when we supply no parameter to the str() function.
{
*sipCppPtr = new std::string();
return 1;
}
else if(PyUnicode_Check(sipPy)) //Is a str.
{
PyObject* str = PyUnicode_AsEncodedString(sipPy, "UTF-8", ""); //Temporarily convert to Python str which has the AS_STRING function.
*sipCppPtr = new std::string(PyBytes_AS_STRING(str));
Py_DECREF(str); //Temporary object goes immediately out of scope.
return 1;
}
else if(PyBytes_Check(sipPy)) //Is a str.
{
*sipCppPtr = new std::string(PyBytes_AS_STRING(sipPy));
return 1;
}
else
{
return 0;
}
%End
};