simplify opengl stroke creation
This commit is contained in:
parent
ee0e5a5f0a
commit
2d7cc52941
1 changed files with 5 additions and 11 deletions
|
@ -6,7 +6,7 @@ from typing import Optional, Union
|
||||||
import ModernGL
|
import ModernGL
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from shapely.geometry import CAP_STYLE, JOIN_STYLE, LinearRing, LineString, MultiLineString, MultiPolygon, Polygon
|
from shapely.geometry import CAP_STYLE, JOIN_STYLE, MultiPolygon, Polygon
|
||||||
from shapely.ops import unary_union
|
from shapely.ops import unary_union
|
||||||
from trimesh.creation import triangulate_polygon
|
from trimesh.creation import triangulate_polygon
|
||||||
|
|
||||||
|
@ -81,16 +81,10 @@ class OpenGLEngine(RenderEngine):
|
||||||
self.vertices.append(self._create_geometry(geometry, self.hex_to_rgb(fill.color)))
|
self.vertices.append(self._create_geometry(geometry, self.hex_to_rgb(fill.color)))
|
||||||
|
|
||||||
if stroke is not None and stroke.color.startswith('#'):
|
if stroke is not None and stroke.color.startswith('#'):
|
||||||
if isinstance(geometry, MultiLineString):
|
lines = tuple(chain(*(
|
||||||
lines = (geometry, )
|
((geom.exterior, *geom.interiors) if isinstance(geom, Polygon) else geom)
|
||||||
elif isinstance(geometry, (LinearRing, LineString)):
|
for geom in getattr(geometry, 'geoms', (geometry, ))
|
||||||
lines = (geometry, )
|
)))
|
||||||
elif isinstance(geometry, (Polygon, MultiPolygon)):
|
|
||||||
lines = tuple(chain(*((polygon.exterior, *polygon.interiors)
|
|
||||||
for polygon in assert_multipolygon(geometry))))
|
|
||||||
else:
|
|
||||||
raise ValueError('Unknown geometry for add_geometry!')
|
|
||||||
|
|
||||||
self.vertices.append(self._create_geometry(
|
self.vertices.append(self._create_geometry(
|
||||||
unary_union(lines).buffer(max(stroke.width, (stroke.min_px or 0) / self.scale)/2,
|
unary_union(lines).buffer(max(stroke.width, (stroke.min_px or 0) / self.scale)/2,
|
||||||
cap_style=CAP_STYLE.flat, join_style=JOIN_STYLE.mitre),
|
cap_style=CAP_STYLE.flat, join_style=JOIN_STYLE.mitre),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue