Skip to content

linkcad.geom

The geometry module provides 2D primitives for coordinate math and shape manipulation.

from linkcad.v1.geom import Point, Vector, Bounds, Transformation, Angle, Resolution

Coordinates are integers in database units. Point and Vector are plain value types — they are not database objects and can be created freely.

Classes

Point

A 2D coordinate.

from linkcad.v1.geom import Point
p = Point(1000, 2000)
print(p.x, p.y)
print(p[0], p[1]) # indexable, so a Point unpacks like a tuple
Property / MethodDescription
Point() / Point(x, y)Construct a point
x, yCoordinate components; assignable
distance_to(other)Euclidean distance
equals(other, tolerance=1e-12)Equality within a tolerance
+, -Point arithmetic
*, /Scale by an integer
==, !=Exact comparison
p[0] / p[1]Index access to x and y

Everywhere LinkCAD accepts vertices, plain (x, y) tuples work too:

cell.add_polygon(layer, [(0, 0), (1000, 0), (1000, 1000)])
cell.add_polygon(layer, [Point(0, 0), Point(1000, 0), Point(1000, 1000)])

Vector

A 2D direction or offset.

from linkcad.v1.geom import Vector
v = Vector(100, 200)
print(v.length)
Property / MethodDescription
Vector() / Vector(x, y)Construct a vector
x, yVector components; assignable
lengthVector magnitude
normalize()Scale to unit length, in place
+, -Vector arithmetic
*, /Scalar multiplication and division

Transformation

A 2D transformation: uniform scaling, rotation, and translation. Build one by construction and then compose in place — the mutating methods return the transformation itself, so they chain.

from linkcad.v1.geom import Transformation
xform = Transformation()
xform.rotate(45.0).translate(1000, 2000)
print(xform.rotation.degrees, xform.translation.x, xform.translation.y)

Order matters. rotate() also rotates whatever offset is already set, so rotate first and translate afterwards if you want the offset to be the final position.

Method / PropertyDescription
Transformation()Identity transformation
Transformation(scale, rotation, offset)Construct from a scale factor, an Angle, and a Vector
translate(dx, dy)Add a translation. Coordinates are rounded to database integers
rotate(degrees)Add a rotation, in degrees
scale(factor)Add uniform scaling
scalingScale factor; assignable
rotationRotation Angle (read-only)
translationTranslation Vector (read-only)
inverseThe inverse transformation
is_identityTrue if the transformation does nothing
transform_point(point)Apply the transformation to a Point, returning a Point

transform_point() takes and returns a database Point, so the result feeds straight back into cell.add_polygon():

from linkcad.v1.geom import Point, Transformation
xform = Transformation()
xform.rotate(90.0).translate(1000, 2000)
moved = [xform.transform_point(Point(x, y)) for x, y in [(0, 0), (100, 0), (100, 100)]]
cell.add_polygon(layer, moved)

Bounds

An axis-aligned bounding box. cell.bounds and cell_object.bounds return one.

b = cell.bounds
if not b.empty:
print(b.min_x, b.min_y, b.width, b.height)
Property / MethodDescription
Bounds() / Bounds(min_pt, max_pt)Construct an empty box, or one from two Points
min_xy / max_xyCorner points
min_x / max_x / min_y / max_yIndividual edges
width / heightDimensions
centerCentre point
emptyTrue if the box holds nothing
contains(point, tolerance=0)Point-in-bounds test
overlaps(other)Overlap test

Every measurement on Bounds is a noun and therefore a property. This was the one place in the API where the binding leaked the C++ spelling — minXY(), maxX() — and it no longer does.

Angle

An angle value, used wherever LinkCAD accepts or returns an angular quantity.

from linkcad.v1.geom import Angle
a = Angle.from_degrees(45.0)
b = Angle.from_radians(0.785398)
print(a.degrees, a.radians)
Factory / Property / MethodDescription
Angle()Zero angle
Angle.from_degrees(degrees)Create from degrees
Angle.from_radians(radians)Create from radians
angle.degreesValue in degrees
angle.radiansValue in radians
angle.equals(other, tolerance_radians=1e-12)Comparison within a tolerance
Angle.zero / Angle.pi_half / Angle.pi / Angle.two_piConstants for 0°, 90°, 180°, and 360°

Resolution

Controls how curved shapes (circles, arcs, ellipses, NURBS) are tessellated into polygon vertices during processing operations such as merge or explode.

from linkcad.v1.geom import Resolution
res = Resolution()
res.minimum_facets = 32 # at least 32 segments per full circle
res.maximum_error = 1 # max deviation in database units
print(res.segment_count(10_000))
Property / MethodDescription
Resolution() / Resolution(min_facets=0, error_max=...)Construct
minimum_facetsMinimum number of polygon segments per full circle; assignable
maximum_errorMaximum allowed deviation from the true curve, in database units; assignable
segment_count(diameter)Segments a circle of that diameter would be broken into