svg_model Package¶
svg_model
Package¶
-
svg_model.__init__.
compute_shape_centers
(df_shapes, shape_i_column, inplace=False)[source]¶ Compute the center point of each polygon shape, and the offset of each vertex to the corresponding polygon center point.
Parameters: - df_shapes (pandas.DataFrame) –
Table of polygon shape vertices (one row per vertex).
- Must have at least the following columns:
vertex_i
: The index of the vertex within the corresponding shape.x
: The x-coordinate of the vertex.y
: The y-coordinate of the vertex.
- shape_i_column (str or list, optional) – Table rows with the same value in the
shape_i_column
column are grouped together as a shape. - in_place (bool, optional) –
If
True
, center coordinate columns are added directly to the input frame.Otherwise, center coordinate columns are added to copy of the input frame.
Returns: - Input frame with the following additional columns:
x_center
/y_center
: Absolute coordinates of shape center.x_center_offset
/y_center_offset
:- Coordinates of each vertex coordinate relative to shape center.
Return type: pandas.DataFrame
- df_shapes (pandas.DataFrame) –
-
svg_model.__init__.
fit_points_in_bounding_box
(df_points, bounding_box, padding_fraction=0)[source]¶ Return data frame with
x
,y
columns scaled to fit points fromdf_points
to fillbounding_box
while maintaining aspect ratio.Parameters: - df_points (pandas.DataFrame) – A frame with at least the columns
x
andy
, containing one row per point. - bounding_box (pandas.Series) – A pandas.Series containing numeric width and height values.
- padding_fraction (float) – Fraction of padding to add around points.
Returns: Input frame with the points with
x
andy
values scaled to fillbounding_box
while maintaining aspect ratio.Return type: pandas.DataFrame
- df_points (pandas.DataFrame) – A frame with at least the columns
-
svg_model.__init__.
fit_points_in_bounding_box_params
(df_points, bounding_box, padding_fraction=0)[source]¶ Return offset and scale factor to scale
x
,y
columns ofdf_points
to fillbounding_box
while maintaining aspect ratio.Parameters: - df_points (pandas.DataFrame) – A frame with at least the columns
x
andy
, containing one row per point. - bounding_box (pandas.Series) – A pandas.Series containing numeric width and height values.
- padding_fraction (float) – Fraction of padding to add around points.
Returns: (offset, scale) – Offset translation and scale required to fit all points in
df_points
to fillbounding_box
while maintaining aspect ratio.offset
containsx
andy
values for the offset.Return type: (pandas.Series, float)
- df_points (pandas.DataFrame) – A frame with at least the columns
-
svg_model.__init__.
get_scaled_svg_frame
(svg_filepath, **kwargs)[source]¶ Note
Deprecated in
svg_model
0.5get_scaled_svg_frame()
was removed insvg_model
0.5, it is replaced bysvg_model.scale_points()
andsvg_model.compute_shape_centers()
.
-
svg_model.__init__.
remove_layer
(svg_source, layer_name)[source]¶ Remove layer(s) from SVG document.
Parameters: Returns: File-like object containing XML document with layer(s) removed.
Return type:
-
svg_model.__init__.
scale_points
(df_points, scale=3.5433070866141736, inplace=False)[source]¶ Translate points such that bounding box is anchored at (0, 0) and scale
x
andy
columns of input frame by specifiedscale
.Parameters: - df_points (pandas.DataFrame) –
Table of
x
/y
point positions.- Must have at least the following columns:
x
: x-coordinatey
: y-coordinate
- scale (float, optional) –
Factor to scale points by.
By default, scale to millimeters based on Inkscape default of 90 pixels-per-inch.
- scale – Factor to scale points by.
- in_place (bool, optional) –
If
True
, input frame will be modified.Otherwise, the scaled points are written to a new frame, leaving the input frame unmodified.
Returns: Input frame with the points translated such that bounding box is anchored at (0, 0) and
x
andy
values scaled by specifiedscale
.Return type: pandas.DataFrame
- df_points (pandas.DataFrame) –
-
svg_model.__init__.
scale_to_fit_a_in_b
(a_shape, b_shape)[source]¶ Return scale factor (scalar float) to fit a_shape into b_shape while maintaining aspect ratio.
Parameters: b_shape (a_shape,) – Input shapes containing numeric width and height values. Returns: Scale factor to fit a_shape
intob_shape
while maintaining aspect ratio.Return type: float
-
svg_model.__init__.
shape_path_points
(svg_path_d)[source]¶ Parameters: svg_path_d (str) – "d"
attribute of SVGpath
element.Returns: List of coordinates of points found in SVG path. Each point is represented by a dictionary with keys
x
andy
.Return type: list
-
svg_model.__init__.
svg_polygons_to_df
(svg_source, xpath='//svg:polygon', namespaces={'svg': 'http://www.w3.org/2000/svg', 'inkscape': 'http://www.inkscape.org/namespaces/inkscape'})[source]¶ Construct a data frame with one row per vertex for all shapes (e.g.,
svg:path
,svg:polygon
) insvg_source`
.Parameters: Returns: Frame with one row per vertex for all shapes in
svg_source
, with the following columns:path_id
: Theid
attribute of the corresponding shape.vertex_i
: The index of the vertex within the corresponding shape.x
: The x-coordinate of the vertex.y
: The y-coordinate of the vertex.
Return type: pandas.DataFrame
Note
Deprecated in
svg_model
0.5.post10svg_polygons_to_df()
will be removed insvg_model
1.0, it is replaced bysvg_shapes_to_df()
because the latter is more general and works withsvg:path
andsvg:polygon
elements.
-
svg_model.__init__.
svg_shapes_to_df
(svg_source, xpath='//svg:path | //svg:polygon', namespaces={'svg': 'http://www.w3.org/2000/svg', 'inkscape': 'http://www.inkscape.org/namespaces/inkscape'})[source]¶ Construct a data frame with one row per vertex for all shapes in
svg_source`
.Parameters: Returns: Frame with one row per vertex for all shapes in
svg_source
, with the following columns:vertex_i
: The index of the vertex within the corresponding shape.x
: The x-coordinate of the vertex.y
: The y-coordinate of the vertex.- other: attributes of the SVG shape element (e.g.,
id
,fill
, - etc.)
- other: attributes of the SVG shape element (e.g.,
Return type: pandas.DataFrame
body_group
Module¶
This is a New BSD License. http://www.opensource.org/licenses/bsd-license.php
Copyright (c) 2012, Christian Fobel (christian@fobel.net) All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Jonathan Hartley nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
color
Module¶
-
svg_model.color.
hex_color_to_rgba
(hex_color, normalize_to=255)[source]¶ Convert a hex-formatted number (i.e., “#RGB[A]” or “#RRGGBB[AA]”) to an RGBA tuple (i.e., (<r>, <g>, <b>, <a>)).
Parameters: Returns: - RGBA tuple (i.e., (<r>, <g>, <b>, <a>)), where range of
each channel in tuple is [0, normalize_to].
Return type: (tuple)
connections
Module¶
-
svg_model.connections.
extend_shapes
(df_shapes, axis, distance)[source]¶ Extend shape/polygon outline away from polygon center point by absolute distance.
-
svg_model.connections.
extract_adjacent_shapes
(df_shapes, shape_i_column, extend=0.5)[source]¶ Generate list of connections between “adjacent” polygon shapes based on geometrical “closeness”.
Parameters: - df_shapes (pandas.DataFrame) –
Table of polygon shape vertices (one row per vertex).
Table rows with the same value in the
shape_i_column
column are grouped together as a polygon. - shape_i_column (str or list[str]) – Column name(s) that identify the polygon each row belongs to.
- extend (float, optional) – Extend
x
/y
coords by the specified number of absolute units from the center point of each polygon. Each polygon is stretched independently in thex
andy
direction. In each direction, a polygon considered adjacent to all polygons that are overlapped by the extended shape.
Returns: Adjacency list as a frame containing the columns
source
andtarget
.The
source
andtarget
of each adjacency connection is ordered such that thesource
is less than thetarget
.Return type: pandas.DataFrame
- df_shapes (pandas.DataFrame) –
-
svg_model.connections.
extract_connections
(svg_source, shapes_canvas, line_layer='Connections', line_xpath=None, path_xpath=None, namespaces=None)[source]¶ Load all
<svg:line>
elements and<svg:path>
elements from a layer of an SVG source. For each element, if endpoints overlap distinct shapes inshapes_canvas
, add connection between overlapped shapes.Changed in version 0.6.post1: Allow both
<svg:line>
and<svg:path>
instances to denote connected/adjacent shapes.New in version 0.6.post1:
path_xpath
Parameters: - svg_source (filepath) – Input SVG file containing connection lines.
- shapes_canvas (shapes_canvas.ShapesCanvas) – Shapes canvas containing shapes to compare against connection endpoints.
- line_layer (str) – Name of layer in SVG containing connection lines.
- line_xpath (str) – XPath string to iterate through connection lines.
- path_xpath (str) – XPath string to iterate through connection paths.
- namespaces (dict) – SVG namespaces (compatible with
etree.parse()
).
Returns: Each row corresponds to connection between two shapes in
shapes_canvas
, denotedsource
andtarget
.Return type: pandas.DataFrame
data_frame
Module¶
-
svg_model.data_frame.
get_bounding_box
(df_points)[source]¶ Calculate the bounding box of all points in a data frame.
-
svg_model.data_frame.
get_bounding_boxes
(df_shapes, shape_i_columns)[source]¶ Return a pandas.DataFrame indexed by shape_i_columns (i.e., each row corresponds to a single shape/polygon), containing the following columns:
- width: The width of the widest part of the shape.
- height: The height of the tallest part of the shape.
-
svg_model.data_frame.
get_shape_areas
(df_shapes, shape_i_columns, signed=False)[source]¶ Return a pandas.Series indexed by shape_i_columns (i.e., each entry corresponds to a single shape/polygon), containing the following columns the area of each shape.
If signed=True, a positive area value corresponds to a clockwise loop, whereas a negative area value corresponds to a counter-clockwise loop.
-
svg_model.data_frame.
get_shape_infos
(df_shapes, shape_i_columns)[source]¶ Return a pandas.DataFrame indexed by shape_i_columns (i.e., each row corresponds to a single shape/polygon), containing the following columns:
- area: The area of the shape.
- width: The width of the widest part of the shape.
- height: The height of the tallest part of the shape.
detect_connections
Module¶
-
svg_model.detect_connections.
auto_detect_adjacent_shapes
(svg_source, shape_i_attr='id', layer_name='Connections', shapes_xpath='//svg:path | //svg:polygon', extend=1.5)[source]¶ Attempt to automatically find “adjacent” shapes in a SVG layer.
In a layer within a new SVG document, draw each detected connection between the center points of the corresponding shapes.
Parameters: - svg_source (str) – Input SVG file as a filepath (or file-like object).
- shape_i_attr (str, optional) – Attribute of each shape SVG element that uniquely identifies the shape.
- layer_name (str, optional) –
Name to use for the output layer where detected connections are drawn.
Note
Any existing layer with the same name will be overwritten.
- shapes_xpath (str, optional) –
XPath path expression to select shape nodes.
By default, all
svg:path
andsvg:polygon
elements are selected. - extend (float, optional) –
Extend
x
/y
coords by the specified number of absolute units from the center point of each shape.Each shape is stretched independently in the
x
andy
direction. In each direction, a shape is considered adjacent to all other shapes that are overlapped by the extended shape.
Returns: File-like object containing SVG document with layer named according to
layer_name
with the detected connections drawn assvg:line
instances.Return type:
draw
Module¶
-
svg_model.draw.
draw_lines_svg_layer
(df_endpoints, layer_name, layer_number=1)[source]¶ Draw lines defined by endpoint coordinates as a layer in a SVG file.
Parameters: Returns: A file-like object containing SVG XML source.
The XML contains a layer named
"Connections"
, which in turn contains one line per row in the inputdf_endpoints
table.Return type:
-
svg_model.draw.
draw_shapes_svg_layer
(df_shapes, shape_i_columns, layer_name, layer_number=1, use_svg_path=True)[source]¶ Draw shapes as a layer in a SVG file.
Parameters: - df_shapes (pandas.DataFrame) – Table of shape vertices (one row per vertex).
- shape_i_columns (str or list) – Either a single column name as a string
or a list of column names in
df_shapes
. Rows indf_shapes
with the same value in theshape_i_columns
column(s) are grouped together as a shape. - layer_name (str) – Name of Inkscape layer.
- layer_number (int, optional) – Z-order index of Inkscape layer.
- use_svg_path (bool, optional) – If
True
, electrodes are drawn assvg:path
elements. Otherwise, electrodes are drawn assvg:polygon
elements.
Returns: A file-like object containing SVG XML source.
The XML contains a layer named according to
layer_name
, which in turn containssvg:polygon
orsvg:path
elements corresponding to the shapes in the inputdf_shapes
table.Return type:
geo_path
Module¶
This is a New BSD License. http://www.opensource.org/licenses/bsd-license.php
Copyright (c) 2008-2009, Jonathan Hartley (tartley@tartley.com) Copyright (c) 2012, Christian Fobel (christian@fobel.net) All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Jonathan Hartley nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
-
class
svg_model.geo_path.
ColoredPath
(loops)[source]¶ Bases:
svg_model.geo_path.Path
Methods
get_area
()get_bounding_box
()get_center
()get_centroid
()get_mass
()get_moment
()offset
(x, y)offset_to_origin
()
-
class
svg_model.geo_path.
Path
(loops)[source]¶ Bases:
object
A Path is a list of loops.
Methods
get_area
()get_bounding_box
()get_center
()get_centroid
()get_mass
()get_moment
()offset
(x, y)offset_to_origin
()
gui_demo
Module¶
loop
Module¶
This is a New BSD License. http://www.opensource.org/licenses/bsd-license.php
Copyright (c) 2008-2009, Jonathan Hartley (tartley@tartley.com) Copyright (c) 2012, Christian Fobel (christian@fobel.net) All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Jonathan Hartley nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
-
class
svg_model.loop.
Loop
(verts=None)[source]¶ Bases:
object
Methods
get_area
()Always returns a positive number. get_centroid
()get_mass
()get_signed_area
()Return area of a simple (ie. is_clockwise
()Assume y-axis points up offset
(x, y)-
density
= 1¶
-
get_area
()[source]¶ Always returns a positive number. If poly is self-intersecting, the actual area will be smaller than this.
-
merge
Module¶
-
svg_model.merge.
get_svg_layers
(svg_sources)[source]¶ Collect layers from input svg sources.
Parameters: svg_sources (list) – A list of file-like objects, each containing one or more XML layers. Returns: (width, height), layers – The first item in the tuple is the shape of the largest layer, and the second item is a list of Element
objects (fromlxml.etree
module), one per SVG layer.Return type: (int, int), list
-
svg_model.merge.
merge_svg_layers
(svg_sources, share_transform=True)[source]¶ Merge layers from input svg sources into a single XML document.
Parameters: - svg_sources (list) – A list of file-like objects, each containing one or more XML layers.
- share_transform (bool) – If exactly one layer has a transform, apply it to all other layers as well.
Returns: File-like object containing merge XML document.
Return type:
path_group
Module¶
This is a New BSD License. http://www.opensource.org/licenses/bsd-license.php
Copyright (c) 2012, Christian Fobel (christian@fobel.net) All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Jonathan Hartley nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
plot
Module¶
point_query
Module¶
-
svg_model.point_query.
get_shapes_pymunk_space
(df_convex_shapes, shape_i_columns)[source]¶ Return two-ple containing:
- A pymunk.Space instance.
- A pandas.Series mapping each pymunk.Body object in the Space to a shape index.
The Body to shape index mapping makes it possible to, for example, look up the index of the convex shape associated with a Body returned by a pymunk point query in the Space.
seidel
Module¶
-
class
svg_model.seidel.
Edge
(p, q)[source]¶ Bases:
object
Methods
add_mpoint
(point)is_above
(point)is_below
(point)
-
class
svg_model.seidel.
MonotoneMountain
[source]¶ Methods
add
(point)angle
(p)angle_sign
()gen_mono_poly
()is_convex
(p)process
()remove
(point)triangulate
()valid
(p)
-
class
svg_model.seidel.
Point
(x, y)[source]¶ Bases:
object
Methods
clone
()cross
(p)dot
(p)length
()less
(p)neq
(other)normalize
()
-
class
svg_model.seidel.
QueryGraph
(head)[source]¶ Methods
case1
(sink, edge, tlist)case2
(sink, edge, tlist)case3
(sink, edge, tlist)case4
(sink, edge, tlist)follow_edge
(edge)locate
(edge)replace
(sink, node)
-
class
svg_model.seidel.
Sink
(trapezoid)[source]¶ Bases:
svg_model.seidel.Node
Methods
locate
(edge)replace
(node)
-
class
svg_model.seidel.
Trapezoid
(left_point, right_point, top, bottom)[source]¶ Bases:
object
Methods
add_points
()area
()contains
(point)segments
(p)trim_neighbors
()update_left
(ul, ll)update_left_right
(ul, ll, ur, lr)update_right
(ur, lr)vertices
()
-
class
svg_model.seidel.
TrapezoidalMap
[source]¶ Bases:
object
Methods
bounding_box
(edges)case1
(t, e)case2
(t, e)case3
(t, e)case4
(t, e)clear
()
-
class
svg_model.seidel.
Triangulator
(poly_line)[source]¶ Bases:
object
Methods
create_mountains
()init_edges
(points)mark_outside
(t)mono_polies
()order_edges
(edge_list)process
()trapezoid_map
()triangles
()
-
class
svg_model.seidel.
XNode
(point, lchild, rchild)[source]¶ Bases:
svg_model.seidel.Node
Methods
locate
(edge)replace
(node)
-
class
svg_model.seidel.
YNode
(edge, lchild, rchild)[source]¶ Bases:
svg_model.seidel.Node
Methods
locate
(edge)replace
(node)
shapes_canvas
Module¶
-
class
svg_model.shapes_canvas.
ShapesCanvas
(df_shapes, shape_i_columns, canvas_shape=None, padding_fraction=0)[source]¶ Bases:
object
The ShapesCanvas class fits all shapes defined by vertices in a pandas.DataFrame (one vertex per row) into a specified canvas shape (with optional padding), while maintaining aspect ratio.
The ShapesCanvas.find_shape method returns the shape located at the specified canvas coordinates (or None, if no shape intersects with specified point).
Methods
find_shape
(canvas_x, canvas_y)Look up shape based on canvas coordinates. from_svg
(svg_filepath, *args, **kwargs)reset_shape
([canvas_shape, padding_fraction])
tesselate
Module¶
-
svg_model.tesselate.
tesselate_shapes_frame
(df_shapes, shape_i_columns)[source]¶ Tesselate each shape path into one or more triangles.
Parameters: - df_shapes (pandas.DataFrame) –
Table containing vertices of shapes, one row per vertex, with the at least the following columns:
x
: The x-coordinate of the vertex.y
: The y-coordinate of the vertex.
- shape_i_columns (str or list) – Column(s) forming key to differentiate rows/vertices for each distinct shape.
Returns: - pandas.DataFrame
- Table where each row corresponds to a triangle vertex, with the following
- columns –
shape_i_columns[]
: The shape path index column(s).triangle_i
: The integer triangle index within each electrode path.vertex_i
: The integer vertex index within each triangle.
- df_shapes (pandas.DataFrame) –