linkcad.geom
The geometry module provides 2D primitives for coordinate math and shape manipulation.
from linkcad.v1.geom import Point, Vector, Bounds, Transformation, Angle, ResolutionCoordinates 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 / Method | Description |
|---|---|
Point() / Point(x, y) | Construct a point |
x, y | Coordinate 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 / Method | Description |
|---|---|
Vector() / Vector(x, y) | Construct a vector |
x, y | Vector components; assignable |
length | Vector 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 / Property | Description |
|---|---|
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 |
scaling | Scale factor; assignable |
rotation | Rotation Angle (read-only) |
translation | Translation Vector (read-only) |
inverse | The inverse transformation |
is_identity | True 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.boundsif not b.empty: print(b.min_x, b.min_y, b.width, b.height)| Property / Method | Description |
|---|---|
Bounds() / Bounds(min_pt, max_pt) | Construct an empty box, or one from two Points |
min_xy / max_xy | Corner points |
min_x / max_x / min_y / max_y | Individual edges |
width / height | Dimensions |
center | Centre point |
empty | True 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 / Method | Description |
|---|---|
Angle() | Zero angle |
Angle.from_degrees(degrees) | Create from degrees |
Angle.from_radians(radians) | Create from radians |
angle.degrees | Value in degrees |
angle.radians | Value in radians |
angle.equals(other, tolerance_radians=1e-12) | Comparison within a tolerance |
Angle.zero / Angle.pi_half / Angle.pi / Angle.two_pi | Constants 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 circleres.maximum_error = 1 # max deviation in database units
print(res.segment_count(10_000))| Property / Method | Description |
|---|---|
Resolution() / Resolution(min_facets=0, error_max=...) | Construct |
minimum_facets | Minimum number of polygon segments per full circle; assignable |
maximum_error | Maximum allowed deviation from the true curve, in database units; assignable |
segment_count(diameter) | Segments a circle of that diameter would be broken into |