Points

Summary

Points live in a Cartesian coordinate system with Real or Unitful.Length coordinates:

julia> Point(1,1)
2-element Devices.Points.Point{Int64}:
 1
 1

julia> Point(1.0,1.0)
2-element Devices.Points.Point{Float64}:
 1.0
 1.0

julia> Point(1.0u"μm", 1.0u"μm")
2-element Devices.Points.Point{Quantity{Float64, Dimensions:{𝐋}, Units:{μm}}}:
 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 Devices.Points.Point{Int64}:
 4
 5

You can also do affine transformations by composing any number of Translation and Rotations, 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([6.12323e-17 -1.0; 1.0 6.12323e-17], (-2.0,1.0000000000000002))

julia> aff(Point(0,0))
2-element Devices.Points.Point{Float64}:
 -2.0
  1.0

API

# Devices.CoordinateConstant.

typealias Coordinate Union{Real,Length}

Type alias for numeric types suitable for coordinate systems.

source

# Devices.Points.PointType.

immutable Point{T} <: FieldVector{T}
    x::T
    y::T
end

2D Cartesian coordinate in the plane.

source

# Devices.Points.getxFunction.

getx(p::Point)

Get the x-coordinate of a point. You can also use p.x or p[1].

source

# Devices.Points.getyFunction.

gety(p::Point)

Get the y-coordinate of a point. You can also use p.y or p[2].

source

# Devices.Points.lowerleftFunction.

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 Devices.Points.Point{Int64}:
 -1
  0

source

# Devices.Points.upperrightFunction.

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 Devices.Points.Point{Int64}:
 2
 3

source

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.

To interface with gdspy, we simply convert the Point object to a Tuple and let PyCall.jl figure out what to do.