Skip to content

Commit c13c04b

Browse files
authored
Merge pull request #1191 from compas-dev/bye-planarity
Replace planarity with networkx
2 parents 209201b + ff4b65d commit c13c04b

File tree

8 files changed

+64
-55
lines changed

8 files changed

+64
-55
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
* Changed `Network.is_planar` to rely on `NetworkX` instead `planarity` for planarity checking.
15+
* Removed `planarity` from requirements.
1416
* Fixed argument order at `compas.geometry.cone.circle`.
1517

1618
### Removed

docs/userguide/configuration/blender.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Alternatively, you can create a new environment and simply install entire COMPAS
177177

178178
.. code-block:: bash
179179
180-
conda create -n blender python=3.9 cython planarity --yes
180+
conda create -n blender python=3.9 cython --yes
181181
conda activate blender
182182
pip install compas
183183
python -m compas_blender.install

docs/userguide/installation.rst

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Create an environment named ``research`` and install COMPAS from the package cha
2121
2222
conda create -n research -c conda-forge compas
2323
24-
Activate the environment.
24+
Activate the environment.
2525

2626
.. code-block:: bash
2727
@@ -71,17 +71,6 @@ Install an editable version from local source.
7171
cd path/to/compas
7272
pip install -e .
7373
74-
By default, ``planarity`` is marked as an optional requirement for installation with ``pip`` on Windows.
75-
To include ``planarity``, add a conditional to the install command.
76-
77-
.. code-block:: bash
78-
79-
pip install compas[planarity]
80-
81-
.. code-block:: bash
82-
83-
pip install -e .[planarity]
84-
8574
8675
Update with conda
8776
=================
@@ -122,18 +111,6 @@ If you encounter a problem that is not described here,
122111
please file an issue using the `Issue Tracker <https://github.com/compas-dev/compas/issues>`_.
123112

124113

125-
Installing Planarity
126-
--------------------
127-
128-
The installation process with ``pip`` can fail while installing ``planarity``, because ``cython`` is not installed.
129-
If this is the case, install ``cython`` using ``pip`` (or ``conda``), before installing COMPAS.
130-
131-
.. code-block:: bash
132-
133-
pip install cython --install-option="--no-cython-compile"
134-
pip install compas
135-
136-
137114
Microsoft Visual C++ Build Tools
138115
--------------------------------
139116

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def read(*names, **kwargs):
6666
zip_safe=False,
6767
install_requires=requirements,
6868
python_requires=">=2.7",
69-
extras_require={"planarity": ["planarity"], "numba": ["numba"]},
69+
extras_require={"numba": ["numba"]},
7070
entry_points={"console_scripts": ["compas_rpc=compas.rpc.__main__:main"]},
7171
ext_modules=[],
7272
cmdclass={},

src/compas/datastructures/network/planarity.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def network_is_planar(network):
164164
Raises
165165
------
166166
ImportError
167-
If the planarity package is not installed.
167+
If the networkx package is not installed.
168168
169169
Notes
170170
-----
@@ -173,19 +173,15 @@ def network_is_planar(network):
173173
the plane exists, and, furthermore, that straight-line embedding in the plane
174174
exists.
175175
176-
Warnings
177-
--------
178-
This function uses the python binding of the *edge addition planarity suite*.
179-
It is available on Anaconda: https://anaconda.org/conda-forge/python-planarity.
180-
181176
"""
182177
try:
183-
import planarity
178+
import networkx as nx
184179
except ImportError:
185-
print("Planarity is not installed.")
180+
print("NetworkX is not installed.")
186181
raise
187182

188-
return planarity.is_planar(list(network.edges()))
183+
nxgraph = network.to_networkx()
184+
return nx.is_planar(nxgraph)
189185

190186

191187
def network_is_planar_embedding(network):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
v 0.0 0.0 0.0
2+
v 1.0 0.0 0.0
3+
v 1.0 1.0 0.0
4+
v 0.0 1.0 0.0
5+
v 0.5 0.5 1.0
6+
l 1 2
7+
l 2 3
8+
l 3 4
9+
l 4 1
10+
l 1 3
11+
l 2 4
12+
l 1 5
13+
l 2 5
14+
l 3 5
15+
l 4 5
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
v 0.0 0.0 0.0
2+
v 1.0 0.0 0.0
3+
v 1.0 1.0 0.0
4+
v 0.0 1.0 0.0
5+
l 1 2
6+
l 2 3
7+
l 3 4
8+
l 4 1
9+
l 1 3
10+
l 2 4

tests/compas/datastructures/test_network.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
import pytest
2-
import compas
31
import json
4-
from random import random, randint
2+
import os
3+
import random
4+
5+
import pytest
56

7+
import compas
68
from compas.datastructures import Network
79
from compas.geometry import Pointcloud
810

9-
1011
# ==============================================================================
1112
# Fixtures
1213
# ==============================================================================
1314

15+
BASE_FOLDER = os.path.dirname(__file__)
16+
17+
18+
@pytest.fixture
19+
def planar_network():
20+
return Network.from_obj(os.path.join(BASE_FOLDER, "fixtures", "planar.obj"))
21+
22+
23+
@pytest.fixture
24+
def non_planar_network():
25+
return Network.from_obj(os.path.join(BASE_FOLDER, "fixtures", "non-planar.obj"))
26+
1427

1528
@pytest.fixture
1629
def k5_network():
@@ -57,7 +70,7 @@ def test_network_from_obj(filepath):
5770

5871

5972
def test_network_from_pointcloud():
60-
cloud = Pointcloud.from_bounds(random(), random(), random(), randint(10, 100))
73+
cloud = Pointcloud.from_bounds(random.random(), random.random(), random.random(), random.randint(10, 100))
6174
network = Network.from_pointcloud(cloud=cloud, degree=3)
6275
assert network.number_of_nodes() == len(cloud)
6376
for node in network.nodes():
@@ -70,7 +83,7 @@ def test_network_from_pointcloud():
7083

7184

7285
def test_network_data():
73-
cloud = Pointcloud.from_bounds(random(), random(), random(), randint(10, 100))
86+
cloud = Pointcloud.from_bounds(random.random(), random.random(), random.random(), random.randint(10, 100))
7487
network = Network.from_pointcloud(cloud=cloud, degree=3)
7588
other = Network.from_data(json.loads(json.dumps(network.data)))
7689

@@ -123,24 +136,20 @@ def test_add_node():
123136
# ==============================================================================
124137

125138

126-
def test_non_planar(k5_network):
127-
try:
128-
import planarity # noqa: F401
129-
except ImportError:
139+
def test_non_planar(k5_network, non_planar_network):
140+
# On IronPython, we completely skip adding the is_planar method because it depends on c-extensions (networkx)
141+
if not hasattr(k5_network, "is_planar"):
130142
return
131143

132-
from compas.datastructures import network_is_planar
133-
134-
assert network_is_planar(k5_network) is not True
144+
assert k5_network.is_planar() is not True
145+
assert non_planar_network.is_planar() is not True
135146

136147

137-
def test_planar(k5_network):
138-
try:
139-
import planarity # noqa: F401
140-
except ImportError:
148+
def test_planar(k5_network, planar_network):
149+
# On IronPython, we completely skip adding the is_planar method because it depends on c-extensions (networkx)
150+
if not hasattr(k5_network, "is_planar"):
141151
return
142152

143-
from compas.datastructures import network_is_planar
144-
145153
k5_network.delete_edge(("a", "b")) # Delete (a, b) edge to make K5 planar
146-
assert network_is_planar(k5_network) is True
154+
assert k5_network.is_planar() is True
155+
assert planar_network.is_planar() is True

0 commit comments

Comments
 (0)