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

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 from df_points to fill bounding_box while maintaining aspect ratio.

Parameters:
  • df_points (pandas.DataFrame) – A frame with at least the columns x and y, 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 and y values scaled to fill bounding_box while maintaining aspect ratio.

Return type:

pandas.DataFrame

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 of df_points to fill bounding_box while maintaining aspect ratio.

Parameters:
  • df_points (pandas.DataFrame) – A frame with at least the columns x and y, 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 fill bounding_box while maintaining aspect ratio.

offset contains x and y values for the offset.

Return type:

(pandas.Series, float)

svg_model.__init__.get_scaled_svg_frame(svg_filepath, **kwargs)[source]

Note

Deprecated in svg_model 0.5 get_scaled_svg_frame() was removed in svg_model 0.5, it is replaced by svg_model.scale_points() and svg_model.compute_shape_centers().

svg_model.__init__.remove_layer(svg_source, layer_name)[source]

Remove layer(s) from SVG document.

Parameters:
  • svg_source (str or file-like) – A file path, URI, or file-like object.
  • layer_name (str or list) – Layer name or list of layer names to remove from SVG document.
Returns:

File-like object containing XML document with layer(s) removed.

Return type:

StringIO.StringIO

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 and y columns of input frame by specified scale.

Parameters:
  • df_points (pandas.DataFrame) –

    Table of x/y point positions.

    Must have at least the following columns:
    • x: x-coordinate
    • y: 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 and y values scaled by specified scale.

Return type:

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 into b_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 SVG path element.
Returns:List of coordinates of points found in SVG path.

Each point is represented by a dictionary with keys x and y.

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) in svg_source`.

Parameters:
  • svg_source (str or file-like) – A file path, URI, or file-like object.
  • xpath (str, optional) – XPath path expression to select shape nodes.
  • namespaces (dict, optional) – Key/value mapping of XML namespaces.
Returns:

Frame with one row per vertex for all shapes in svg_source, with the following columns:

  • path_id: The id 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.post10 svg_polygons_to_df() will be removed in svg_model 1.0, it is replaced by svg_shapes_to_df() because the latter is more general and works with svg:path and svg: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:
  • svg_source (str or file-like) – A file path, URI, or file-like object.
  • xpath (str, optional) –

    XPath path expression to select shape nodes.

    By default, all svg:path and svg:polygon elements are selected.

  • namespaces (dict, optional) – Key/value mapping of XML namespaces.
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.)

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.

class svg_model.body_group.BodyGroup(paths=None)[source]

Bases: object

Methods

add_path(name, geo_path)
get_body(name)
get_name(body)
add_path(name, geo_path)[source]
get_body(name)[source]
get_name(body)[source]

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:
  • hex_color (str) – hex-formatted number (e.g., “#2fc”, “#3c2f8611”)
  • normalize_to (int, float) – Factor to normalize each channel by
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.draw_lines_svg_layer(df_endpoints, layer_name='Connections')[source]
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 the x and y 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 and target.

The source and target of each adjacency connection is ordered such that the source is less than the target.

Return type:

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 in shapes_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, denoted source and target.

Return type:

pandas.DataFrame

svg_model.connections.get_adjacency_matrix(df_connected)[source]

Return matrix where $a_{i,j} = 1$ indicates polygon $i$ is connected to polygon $j$.

Also, return mapping (and reverse mapping) from original keys in df_connected to zero-based integer index used for matrix rows and columns.

data_frame Module

svg_model.data_frame.close_paths(df_svg)[source]
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_nearest_neighbours(path_centers)[source]
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.
svg_model.data_frame.get_svg_frame(svg_filepath)[source]
svg_model.data_frame.get_svg_path_frame(svg_path)[source]
svg_model.data_frame.triangulate_svg_frame(svg_frame)[source]

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 and svg: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 and y 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 as svg:line instances.

Return type:

StringIO.StringIO

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:
  • df_endpoints (pandas.DataFrame) – Each row corresponds to the endpoints of a single line, encoded through the columns: x_source, y_source, x_target, and y_target.
  • layer_name (str) – Name of Inkscape layer.
  • layer_number (int, optional) – Z-order index of Inkscape layer.
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 input df_endpoints table.

Return type:

StringIO.StringIO

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 in df_shapes with the same value in the shape_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 as svg:path elements. Otherwise, electrodes are drawn as svg:polygon elements.
Returns:

A file-like object containing SVG XML source.

The XML contains a layer named according to layer_name, which in turn contains svg:polygon or svg:path elements corresponding to the shapes in the input df_shapes table.

Return type:

StringIO.StringIO

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()
get_area()[source]
get_bounding_box()[source]
get_center()[source]
get_centroid()[source]
get_mass()[source]
get_moment()[source]
offset(x, y)[source]
offset_to_origin()[source]

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.

get_centroid()[source]
get_mass()[source]
get_signed_area()[source]

Return area of a simple (ie. non-self-intersecting) polygon. If verts wind anti-clockwise, this returns a negative number. Assume y-axis points up.

is_clockwise()[source]

Assume y-axis points up

offset(x, y)[source]

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 (from lxml.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:

StringIO.StringIO

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.

class svg_model.path_group.PathGroup(paths, boundary)[source]

Bases: object

Methods

get_bounding_box()
load_svg(svg_path[, on_error])
get_bounding_box()[source]
classmethod load_svg(svg_path, on_error=None)[source]

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)
add_mpoint(point)[source]
is_above(point)[source]
is_below(point)[source]
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)
add(point)[source]
angle(p)[source]
angle_sign()[source]
gen_mono_poly()[source]
is_convex(p)[source]
process()[source]
remove(point)[source]
triangulate()[source]
valid(p)[source]
class svg_model.seidel.Node(lchild, rchild)[source]

Bases: object

Methods

replace(node)
replace(node)[source]
class svg_model.seidel.Point(x, y)[source]

Bases: object

Methods

clone()
cross(p)
dot(p)
length()
less(p)
neq(other)
normalize()
clone()[source]
cross(p)[source]
dot(p)[source]
length()[source]
less(p)[source]
neq(other)[source]
normalize()[source]
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)
case1(sink, edge, tlist)[source]
case2(sink, edge, tlist)[source]
case3(sink, edge, tlist)[source]
case4(sink, edge, tlist)[source]
follow_edge(edge)[source]
locate(edge)[source]
replace(sink, node)[source]
class svg_model.seidel.Sink(trapezoid)[source]

Bases: svg_model.seidel.Node

Methods

locate(edge)
replace(node)
locate(edge)[source]
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()
add_points()[source]
area()[source]
contains(point)[source]
segments(p)[source]
trim_neighbors()[source]
update_left(ul, ll)[source]
update_left_right(ul, ll, ur, lr)[source]
update_right(ur, lr)[source]
vertices()[source]
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()
bounding_box(edges)[source]
case1(t, e)[source]
case2(t, e)[source]
case3(t, e)[source]
case4(t, e)[source]
clear()[source]
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()
create_mountains()[source]
init_edges(points)[source]
mark_outside(t)[source]
mono_polies()[source]
order_edges(edge_list)[source]
process()[source]
trapezoid_map()[source]
triangles()[source]
class svg_model.seidel.XNode(point, lchild, rchild)[source]

Bases: svg_model.seidel.Node

Methods

locate(edge)
replace(node)
locate(edge)[source]
class svg_model.seidel.YNode(edge, lchild, rchild)[source]

Bases: svg_model.seidel.Node

Methods

locate(edge)
replace(node)
locate(edge)[source]
svg_model.seidel.isink(trapezoid)[source]
svg_model.seidel.line_intersect(edge, x)[source]
svg_model.seidel.merge_sort(l)[source]
svg_model.seidel.orient2d(pa, pb, pc)[source]
svg_model.seidel.shear_transform(point)[source]

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])
find_shape(canvas_x, canvas_y)[source]

Look up shape based on canvas coordinates.

classmethod from_svg(svg_filepath, *args, **kwargs)[source]
reset_shape(canvas_shape=None, padding_fraction=None)[source]
svg_model.shapes_canvas.get_transform(offset, scale)[source]

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.