Points
Points live in a Cartesian coordinate system with Real
or Unitful.Length
coordinates:
julia> Point(1, 1)
2-element Point{Int64} with indices SOneTo(2):
1
1
julia> Point(1.0, 1.0)
2-element Point{Float64} with indices SOneTo(2):
1.0
1.0
julia> Point(1.0u"μm", 1.0u"μm")
2-element Point{Quantity{Float64, 𝐋, Unitful.FreeUnits{(μm,), 𝐋, nothing}}} with indices SOneTo(2):
1.0 μm
1.0 μm
If a point has Real
coordinates, the absence of a unit is interpreted to mean μm
whenever the geometry is saved to a GDS format, but until then it is just considered to be a pure number. Therefore you cannot mix and match Real
and Length
coordinates:
julia> Point(1.0u"μm", 1.0)
ERROR: Cannot use `Point` with this combination of types.
You can add Points together or scale them:
julia> 3 * Point(1, 1) + Point(1, 2)
2-element Point{Int64} with indices SOneTo(2):
4
5
You can also do affine transformations by composing any number of Translation
and Rotation
s, which will return a callable object representing the transformation. You can type the following Unicode symbols with \degree
and \circ
tab-completions in the Julia REPL or using the Atom package latex-completions
.
julia> aff = Rotation(90°) ∘ Translation(Point(1, 2))
AffineMap([0.0 -1.0; 1.0 0.0], (-2.0,1.0))
julia> aff(Point(0, 0))
2-element Point{Float64} with indices SOneTo(2):
-2.0
1.0
API
DeviceLayout.PointTypes
— TypePointTypes = Union{Real, DimensionlessQuantity, Length, InverseLength}
Allowed type variables for Point{T}
types.
DeviceLayout.Coordinate
— TypeCoordinate = Union{Real, Length}
Type alias for numeric types suitable for coordinate systems.
DeviceLayout.Points.Point
— Typestruct Point{T<:PointTypes} <: StaticArrays.FieldVector{2,T}
x::T
y::T
end
2D Cartesian coordinate in the plane.
DeviceLayout.Points.getx
— Functiongetx(p::Point)
Get the x-coordinate of a point. You can also use p.x
or p[1]
.
DeviceLayout.Points.gety
— Functiongety(p::Point)
Get the y-coordinate of a point. You can also use p.y
or p[2]
.
DeviceLayout.Points.lowerleft
— Methodlowerleft{T}(A::AbstractArray{Point{T}})
Return the lower-left Point
of the smallest bounding rectangle (with sides parallel to the x- and y-axes) that contains all points in A
.
Example:
julia> lowerleft([Point(2, 0), Point(1, 1), Point(0, 2), Point(-1, 3)])
2-element Point{Int64} with indices SOneTo(2):
-1
0
DeviceLayout.Points.upperright
— Methodupperright{T}(A::AbstractArray{Point{T}})
Return the upper-right Point
of the smallest bounding rectangle (with sides parallel to the x- and y-axes) that contains all points in A
.
Example:
julia> upperright([Point(2, 0), Point(1, 1), Point(0, 2), Point(-1, 3)])
2-element Point{Int64} with indices SOneTo(2):
2
3
Implementation details
Points are implemented using the abstract type FieldVector
from StaticArrays.jl. This permits a fast, efficient representation of coordinates in the plane. Additionally, unlike Tuple
objects, we can add points together, simplifying many function definitions.