Paths

For original class documentation see Path class reference and DPath class reference.

A note of caution: you’ll see a lot of warnings in this section. Path rendering lacks standardization in GDS and OASIS too. Only simple paths are guaranteed to render the same geometry in all systems. It’s easy to create paths that look differently in different systems. In case of doubt, consider converting your paths to polygons.

Paths are lines along a series of points with a given width. The path ends can be configured to be flat, square or something between. The path ends can be round as well.

Warning: round-ended paths are deprecated in many applications.

Paths are build from a sequence of points and take a width and optionally path end configuration parameters. By default a flush-ended path is created:

import klayout.db as db

points = [
  db.DPoint(0, 0),
  db.DPoint(0, 5),
  db.DPoint(5, 5)
]

p = db.DPath(points, 2.0)

Gives

Result

Paths can easily be configured in ways that introduce interpretation ambiguities. Other systems may read such paths differently (see below for some examples). If you need to be sure that paths are read the same way by other systems, you can convert them to polygons:

import klayout.db as db

points = [
  db.DPoint(0, 0),
  db.DPoint(0, 5),
  db.DPoint(5, 5)
]

path = db.DPath(points, 2.0)
poly = path.polygon()

Gives

Result

The ends are configured using two additional parameters: the start and end extension. The extension is added to the front and end of the path. To create a square-ended path, pass half the width to begin and end extensions:

import klayout.db as db

points = [
  db.DPoint(0, 0),
  db.DPoint(0, 5),
  db.DPoint(5, 5)
]

p = db.DPath(points, 2.0, 1.0, 1.0)

Gives

Result

Arbitrary extensions can be specified. Even negative extensions are possible.

Warning: the results of negative extensions may be undefined on other systems.

import klayout.db as db

points = [
  db.DPoint(0, 0),
  db.DPoint(0, 5),
  db.DPoint(5, 5)
]

# flush start and over-extended end
p = db.DPath(points, 2.0, 0.0, 2.0)

Gives

Result

Round ends can be specified by adding one additional boolean parameter: True gives a round-ended path. Extensions can be combined with the round-mode flag, basically giving elliptic ends. Specifying half the width for begin and end extensions gives circular ends. Contrary to popular expectation, the corners of the path itself are not rounded.

Warning: only round-ended paths with circular ends are supported in GDS. In OASIS, round-ended paths are replaced by flat-ended ones and two circles at the ends.

import klayout.db as db

points = [
  db.DPoint(0, 0),
  db.DPoint(0, 5),
  db.DPoint(5, 5)
]

p = db.DPath(points, 2.0, 1.0, 1.0, True)

Gives

Result

A special case is a single-point path with round ends. Formally such a path allows defining circles in GDS. It is translated into a single circle object in OASIS.

Warning: in GDS, such paths may not be read properly by other systems.

import klayout.db as db

# A circle at 1,2 with diameter 2
p = db.DPath([ db.DPoint(1, 2) ], 2.0, 1.0, 1.0, True)

Gives

Result

Acute corners will be clipped.

Warning: other system reading such a path may apply a different clipping.

import klayout.db as db

points = [
  db.DPoint(0, 0),
  db.DPoint(2, 5),
  db.DPoint(4, 0)
]

p = db.DPath(points, 2.0)

Gives

Result

Short start and end segments are handled by KLayout in a specific way.

Warning: other systems my render such paths differently.

import klayout.db as db

points = [
  db.DPoint(0, 0),
  db.DPoint(10, 0),
  db.DPoint(10, 2)
]

p = db.DPath(points, 10.0)

Gives

Result

Paths can be configured to have a width that is an odd multiple of the database unit. This will create path outlines which are not on the database unit grid. Such paths cannot be translated exactly to polygons.

Warning: such paths cannot be written to OASIS.

import klayout.db as db

# Note we use integer-unit paths here

points = [
  db.Point(0, 0),
  db.Point(0, 5),
  db.Point(5, 5)
]

p = db.Path(points, 3)

Gives

Result