ddg.datastructures.halfedge.surface module

Module ‘halfedge’ defines the half edge data strucure. Create a hafedge data structure representing a surface:

class ddg.datastructures.halfedge.surface.Surface[source]

Bases: object

Finite cell decomposition of a 2-dimensional manifold, possibly with boundary, represented by a half edge data structure.

add_vertex()[source]

Add an isolated vertex.

Returns:
vertex
add_edge(v1, v2, epre=None, enex=None)[source]

Insert an edge between two boundary vertices.

Parameters:
v1, v2vertex

Boundary vertices that the edge should connect.

epreedge or None (default=None)

Defines the edge such that epre.nex is the first new edge. If this is None, a boundary edge pointing to v will be looked up.

Returns:
edge

The halfedge from v1 to v2.

add_face(n, v=[])[source]

Adds an n-gon to the surface. The polygon is not connected to any other polygons after addition.

Parameters:
nint

number of vertices of the polygon to be added

vlist

vertices that become vertices of the polygon new vertices are generated if there are non given

Returns:
face

the face that has been added

glue(e1, e2)[source]

Glues edges of the same surface such that the given halfedges form the new shared edge.

The given halfedges e1 and e2 will be preserved and become opposites of each other while their former opposites are eliminated. The vertices of the new halfedge pair will be the original head and tail of the first edge e1, except in the following special case: If the second edge e2 is a loop and the first edge e1 is not a loop, then the gluing operation identifies the original tail of e1 with the head of e1 and the original tail of e1 is removed.

Parameters:
e1edge

interior edge of a face with its opposite being a boundary edge, e1.opp will become e2

e2edge

interior edge of a face with its opposite being a boundary edge, e2.opp will become e1

Returns:
None
Raises:
ValueError

If the arguments e1 and e2 are not different boundary edges of the surface on which the method is called.

validate()[source]

Validate a halfedge object.

The following checks are run (in order). By “all attributes” we mean nex, pre, opp, head for edges; edge for faces; edge for vertices. By “nodes” we mean vertices, edges and faces, with a generic one denoted by v, e or f.

  • Checks that all attributes point to instances of the correct node class belonging to this surface or None, if allowed (e.face == None indicates a boundary edge, v.edge == None indicates an isolated vertex).

  • Checks that no attributes point to removed nodes, meaning nodes with surf == None.

  • Checks consistency of attributes of all nodes, namely:
    • e.nex.pre is e

    • e.face is e.nex.face

    • e.head is e.nex.opp.head

    • f.edge.face is f

    • v.edge.head is v

  • Checks that all face boundaries are simple loops.

  • Checks that all vertex coboundaries are simple loops. A vertex coboundary is the “asterisk” shape of incoming and outgoing edges of a vertex.

Raises:
SurfaceError

If object is invalid.

validate_surface()[source]

Validate a 2D manifold.

Runs validate plus these additional checks:

  • Checks that object is not the empty set by checking if there are vertices.

  • Checks that for each edge, e.face and e.opp.face are not both None.

  • Checks that no two boundary edges have the same head.

  • Checks that there are no vertices with v.edge == None, i.e. isolated vertices.

Raises:
SurfaceError

If object is invalid or is not a 2D manifold.

validate_curve()[source]

Validate a 1D manifold.

Runs validate_graph plus these additional checks:

  • Checks that object is not the empty set by checking if there are vertices.

  • Checks that all vertices have valency 2, by checking e.nex.opp is e.opp.pre for every edge.

  • Checks that there are no vertices with v.edge == None, i.e. isolated vertices.

Raises:
SurfaceError

If object is invalid or is not a 1D manifold.

validate_graph()[source]

Validate a graph.

Runs validate and checks that there are no faces.

Raises:
SurfaceError

If object is invalid or has faces.

exception ddg.datastructures.halfedge.surface.SurfaceError[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.