Points
Points live in a Cartesian coordinate system with Real
or Unitful.Length
coordinates:
julia> Point(1,1) 2-element Point{Int64}: 1 1 julia> Point(1.0,1.0) 2-element Point{Float64}: 1.0 1.0 julia> Point(1.0u"μm", 1.0u"μm") 2-element Point{Unitful.Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)},Unitful.FreeUnits{(Unitful.Unit{:Meter,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}(-6, 1//1),),Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}}}: 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}: 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}: -2.0 1.0
API
#
Devices.PointTypes
— Constant.
PointTypes = Union{Real, DimensionlessQuantity, Length, InverseLength}
Allowed type variables for Point{T}
types.
#
Devices.Coordinate
— Constant.
Coordinate = Union{Real, Length}
Type alias for numeric types suitable for coordinate systems.
#
Devices.Points.Point
— Type.
struct Point{T} <: StaticArrays.FieldVector{2,T} x::T y::T end
2D Cartesian coordinate in the plane.
#
Devices.Points.getx
— Function.
getx(p::Point)
Get the x-coordinate of a point. You can also use p.x
or p[1]
.
#
Devices.Points.gety
— Function.
gety(p::Point)
Get the y-coordinate of a point. You can also use p.y
or p[2]
.
#
Devices.lowerleft
— Function.
lowerleft{T}(A::AbstractArray{Point{T}})
Returns 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}: -1 0
lowerleft(r::Rectangle)
Returns the lower-left corner of a rectangle (Point object).
lowerleft(x::Polygon)
Return the lower-left-most corner of a rectangle bounding polygon x
. Note that this point doesn't have to be in the polygon.
#
Devices.upperright
— Function.
upperright{T}(A::AbstractArray{Point{T}})
Returns 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}: 2 3
upperright(r::Rectangle)
Returns the upper-right corner of a rectangle (Point object).
upperright(x::Polygon)
Return the upper-right-most corner of a rectangle bounding polygon x
. Note that this point doesn't have to be in the polygon.
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.