kqcircuits.util.geometry_helper

Helper module for general geometric functions

kqcircuits.util.geometry_helper.vector_length_and_direction(vector)[source]

Returns the direction and length of the pya.DVector “vector”.

kqcircuits.util.geometry_helper.point_shift_along_vector(start, other, distance=None)[source]

Returns a point at a distance away from point start in the direction of point other.

kqcircuits.util.geometry_helper.get_direction(angle)[source]

Returns the direction vector corresponding to angle.

Parameters:

angle – angle in degrees

Returns: Unit vector in direction angle

kqcircuits.util.geometry_helper.get_angle(vector)[source]

Returns the angle in degrees for a given DVector (or DPoint)

Parameters:

vector – input vector

Returns: angle in degrees

kqcircuits.util.geometry_helper.get_cell_path_length(cell, layer=None)[source]

Returns the length of the paths in the cell.

Adding together the cell’s paths’ lengths in the “1t1_waveguide_path”, “2b1_waveguide_path” and “waveguide_length” layers.

Parameters:
  • cell – A cell object.

  • layer – None or an unsigned int to specify a non-standard layer

kqcircuits.util.geometry_helper.get_object_path_length(obj, layer=None)[source]

Returns sum of lengths of all the paths in the object and its children

Parameters:
  • obj – ObjectInstPath object

  • layer – layer integer id in the database, waveguide layer by default

kqcircuits.util.geometry_helper.simple_region(region)[source]
kqcircuits.util.geometry_helper.region_with_merged_points(region, tolerance)[source]

In each polygon of the region, removes points that are closer to other points than a given tolerance.

Parameters:
  • region – Input region

  • tolerance – Minimum distance, in database units, between two adjacent points in the resulting region

Returns:

with merged points

Return type:

region

kqcircuits.util.geometry_helper.region_with_merged_polygons(region, tolerance, expansion=0.0)[source]

Merges polygons in given region. Ignores gaps that are smaller than given tolerance.

Parameters:
  • region – input region

  • tolerance – largest gap size to be ignored

  • expansion – the amount by which the polygons are expanded (edges move outwards)

Returns:

region with merged polygons

kqcircuits.util.geometry_helper.merge_points_and_match_on_edges(cell, layout, layers, tolerance=2)[source]

Merges adjacent points of layers. Also goes through each polygon edge and splits the edge whenever it passes close to existing point.

This function can eliminate gaps and overlaps caused by transformation to simple_polygon.

Parameters:
  • cell – A cell object.

  • layout – A layout object

  • layers – List of layers to be considered and modified

  • tolerance – Tolerance in pixels

kqcircuits.util.geometry_helper.is_clockwise(polygon_points)[source]

Returns True if the polygon points are in clockwise order, False if they are counter-clockwise.

Parameters:

polygon_points – list of polygon points, must be either in clockwise or counterclockwise order

kqcircuits.util.geometry_helper.circle_polygon(r, n=64, origin=0, 0)[source]

Returns a polygon for a full circle around the origin.

Parameters:
  • r – Radius

  • origin – Center of the circle, default (0,0)

  • n – Number of points.

Returns: list of DPoint``s, length ``n.

kqcircuits.util.geometry_helper.arc_points(r, start=0, stop=6.283185307179586, n=64, origin=0, 0)[source]

Returns point describing an arc around the origin with specified start and stop angles. The start and stop angle are included.

If start < stop, the points are counter-clockwise; if start > stop, the points are clockwise.

Parameters:
  • r – Arc radius

  • start – Start angle in radians, default 0

  • stop – Stop angle in radians, default 2*pi

  • origin – Center of the arc, default (0,0)

  • n – Number of steps corresponding to a full circle.

kqcircuits.util.geometry_helper.bspline_points(control_points: List[DPoint], sample_points: int = 100, startpoint: bool = False, endpoint: bool = False) List[DPoint][source]

Samples points uniformly from the B-Spline constructed from a sequence of control points. The spline is derived from a sequence of cubic splines for each subsequence of four-control points in a sliding window.

Unlike Bezier curves, for each spline in B-Spline it is not guaranteed that the first and last control point will be in the spline.

B-Spline cubic polynomial implemented based on the following reference: Kaihuai Qin, “General matrix representations for B-splines”, Proceedings Pacific Graphics ‘98 Sixth Pacific Conference on Computer Graphics and Applications, Singapore, 1998, pp. 37-43, doi: 10.1109/PCCGA.1998.731996

Parameters:
  • control_points – a sequence of control points, must have at least 4 pya.DPoints elements

  • sample_points – number of uniform samples of each cubic B-spline, total number of samples is: sample_points * (control_points - 3)

  • startpoint – If True, will prepend duplicates of the first control point so that the first control point will be in the B-Spline

  • endpoint – If True, will append duplicates of the last control point so that the last control point will be in the B-Spline

Returns:

List of pya.DPoints that can be used as part of a polygon

kqcircuits.util.geometry_helper.bezier_points(control_points: List[DPoint], sample_points: int = 100) List[DPoint][source]

Samples points uniformly from the Bezier curve constructed from a sequence of control points. The curve is derived from a sequence of cubic splines for each subsequence of four-control points such that subsequence shares one control point with the previous subsequence.

Special care needs to be taken to guarantee continuity in the tangent of the curve. The third and fourth control point of each subsequence as well as the second control point of the next subsequence have to be in the same line.

Bezier cubic polynomial implemented based on the following reference: Kaihuai Qin, “General matrix representations for B-splines”, Proceedings Pacific Graphics ‘98 Sixth Pacific Conference on Computer Graphics and Applications, Singapore, 1998, pp. 37-43, doi: 10.1109/PCCGA.1998.731996

Parameters:
  • control_points – a sequence of control points, must be of length equal to 3*n+1 for some integer n

  • sample_points – number of uniform samples of each cubic spline, total number of samples is: sample_points * ((control_points - 3) / 3)

Returns:

List of pya.DPoints that can be used as part of a polygon

../_images/kqcircuits.util.geometry_helper.png