Skip to content
Yeesian Ng edited this page Jun 27, 2015 · 9 revisions
# JuliaLang/Graphics.jl

immutable Vec2
    x::Float64
    y::Float64
end

immutable BoundingBox
    xmin::Float64
    xmax::Float64
    ymin::Float64
    ymax::Float64
end
# nolta/Winston.jl

immutable Rectangle
    x0::Float64
    x1::Float64
    y0::Float64
    y1::Float64
end

abstract AbstractProjection1
abstract AbstractProjection2

immutable LinearProjection <: AbstractProjection1
    a::Float64
    b::Float64
end

immutable LogProjection <: AbstractProjection1
    a::Float64
    b::Float64
end

immutable SeparableProjection2{P1<:AbstractProjection1,
                               P2<:AbstractProjection1} <: AbstractProjection2
    x::P1
    y::P2
end

immutable PolarProjection
    x0::Float64
    y0::Float64
    sx::Float64
    sy::Float64
end

function line(self::CairoRenderer, px, py, qx, qy)
    move_to(self.ctx, px, py)
    line_to(self.ctx, qx, qy)
    stroke(self.ctx)
end

const symbol_funcs = @Dict(
    "asterisk" => (c, x, y, r) -> (
        move_to(c, x, y+r);
        line_to(c, x, y-r);
        move_to(c, x+0.866r, y-0.5r);
        line_to(c, x-0.866r, y+0.5r);
        move_to(c, x+0.866r, y+0.5r);
        line_to(c, x-0.866r, y-0.5r)
    ),
    "circle" => (c, x, y, r) -> (
        new_sub_path(c);
        circle(c, x, y, r)
    ),
    "cross" => (c, x, y, r) -> (
        move_to(c, x+r, y+r);
        line_to(c, x-r, y-r);
        move_to(c, x+r, y-r);
        line_to(c, x-r, y+r)
    ),
    "diamond" => (c, x, y, r) -> (
        move_to(c, x, y+r);
        line_to(c, x+r, y);
        line_to(c, x, y-r);
        line_to(c, x-r, y);
        close_path(c)
    ),
    "dot" => (c, x, y, r) -> (
        new_sub_path(c);
        rectangle(c, x, y, 1., 1.)
    ),
    "plus" => (c, x, y, r) -> (
        move_to(c, x+r, y);
        line_to(c, x-r, y);
        move_to(c, x, y+r);
        line_to(c, x, y-r)
    ),
    "square" => (c, x, y, r) -> (
        new_sub_path(c);
        rectangle(c, x-0.866r, y-0.866r, 1.732r, 1.732r)
    ),
    "triangle" => (c, x, y, r) -> (
        move_to(c, x, y+r);
        line_to(c, x+0.866r, y-0.5r);
        line_to(c, x-0.866r, y-0.5r);
        close_path(c)
    ),
    "down-triangle" => (c, x, y, r) -> (
        move_to(c, x, y-r);
        line_to(c, x+0.866r, y+0.5r);
        line_to(c, x-0.866r, y+0.5r);
        close_path(c)
    ),
    "right-triangle" => (c, x, y, r) -> (
        move_to(c, x+r, y);
        line_to(c, x-0.5r, y+0.866r);
        line_to(c, x-0.5r, y-0.866r);
        close_path(c)
    ),
    "left-triangle" => (c, x, y, r) -> (
        move_to(c, x-r, y);
        line_to(c, x+0.5r, y+0.866r);
        line_to(c, x+0.5r, y-0.866r);
        close_path(c)
    ),
)

type Polygons3D
    V::Matrix{Float64}
    P::Vector{Vector{Int}}
    colors
end
# JuliaGeometry/GeometricalPredicates.jl

abstract AbstractPoint
abstract AbstractPoint2D <: AbstractPoint
abstract AbstractPoint3D <: AbstractPoint

abstract AbstractLine2D

abstract AbstractPrimitive
abstract AbstractUnOrientedPrimitive <: AbstractPrimitive
abstract AbstractOrientedPrimitive <: AbstractPrimitive
abstract AbstractPositivelyOrientedPrimitive <: AbstractOrientedPrimitive
abstract AbstractNegativelyOrientedPrimitive <: AbstractOrientedPrimitive

abstract AbstractTriangleUnOriented <: AbstractUnOrientedPrimitive
abstract AbstractTetrahedronUnOriented <: AbstractUnOrientedPrimitive
abstract AbstractPositivelyOrientedTriangle <: AbstractPositivelyOrientedPrimitive
abstract AbstractNegativelyOrientedTriangle <: AbstractNegativelyOrientedPrimitive
abstract AbstractPositivelyOrientedTetrahedron <: AbstractPositivelyOrientedPrimitive
abstract AbstractNegativelyOrientedTetrahedron <: AbstractNegativelyOrientedPrimitive

typealias TriangleTypes Union(AbstractTriangleUnOriented, AbstractPositivelyOrientedTriangle, AbstractNegativelyOrientedTriangle)
typealias TetrahedronTypes Union(AbstractTetrahedronUnOriented, AbstractPositivelyOrientedTetrahedron, AbstractNegativelyOrientedTetrahedron)

# standard 2D point
immutable Point2D <: AbstractPoint2D
    _x::Float64
    _y::Float64
    Point2D(x::Float64,y::Float64) = new(x, y)
end

# standard 3D point
immutable Point3D <: AbstractPoint3D
    _x::Float64
    _y::Float64
    _z::Float64
end

immutable Line2D{T<:AbstractPoint2D} <: AbstractLine2D
    _a::T
    _b::T
    _bx::Float64
    _by::Float64
end

abstract AbstractOrientation
type PositivelyOriented <: AbstractOrientation; end
type NegativelyOriented <: AbstractOrientation; end
type UnOriented <: AbstractOrientation; end

abstract AbstractCoordinate
type CoordinateX <: AbstractCoordinate end
type CoordinateY <: AbstractCoordinate end
type CoordinateZ <: AbstractCoordinate end
const coordinatex = CoordinateX()
const coordinatey = CoordinateY()
const coordinatez = CoordinateZ()
next2d(::CoordinateX) = coordinatey
next2d(::CoordinateY) = coordinatex
next3d(::CoordinateX) = coordinatey
next3d(::CoordinateY) = coordinatez
next3d(::CoordinateZ) = coordinatex
nextnext3d(::CoordinateX) = coordinatez
nextnext3d(::CoordinateY) = coordinatex
nextnext3d(::CoordinateZ) = coordinatey

abstract AbstractDirection
type Forward <: AbstractDirection end
type Backward <: AbstractDirection end
const forward = Forward()
const backward = Backward()
!(::Forward) = backward
!(::Backward) = forward
# JuliaGeo/GeoInterface
abstract AbstractGeometry
    abstract AbstractPoint <: AbstractGeometry
    abstract AbstractMultiPoint <: AbstractGeometry
    abstract AbstractLineString <: AbstractGeometry
    abstract AbstractMultiLineString <: AbstractGeometry
    abstract AbstractPolygon <: AbstractGeometry
    abstract AbstractMultiPolygon <: AbstractGeometry
    abstract AbstractGeometryCollection <: AbstractGeometry

# Coordinate Reference System Objects
# (has keys "type" and "properties")
# TODO: Handle full CRS spec
typealias CRS Dict{String,Any}

# Bounding Boxes
# The value of the bbox member must be a 2*n array,
# where n is the number of dimensions represented in the contained geometries,
# with the lowest values for all axes followed by the highest values.

# The axes order of a bbox follows the axes order of geometries.
# In addition, the coordinate reference system for the bbox is assumed to match
# the coordinate reference system of the GeoJSON object of which it is a member.
typealias BBox Vector{Float64}

typealias Position Vector{Float64}
# (x, y, [z, ...]) - meaning of additional elements undefined.
# In an object's contained geometries, Positions must have uniform dimensions.

type Point <: AbstractPoint
    coordinates::Position
end

type MultiPoint <: AbstractMultiPoint
    coordinates::Vector{Position}
end

type LineString <: AbstractLineString
    coordinates::Vector{Position}
end

type MultiLineString <: AbstractMultiLineString
    coordinates::Vector{Vector{Position}}
end

type Polygon <: AbstractPolygon
    coordinates::Vector{Vector{Position}}
end

type MultiPolygon <: AbstractMultiPolygon
    coordinates::Vector{Vector{Vector{Position}}}
end
# JuliaGeo/LibGEOS.jl

type Point <: GeoInterface.AbstractPoint
    ptr::GEOSGeom
end

type MultiPoint <: GeoInterface.AbstractMultiPoint
    ptr::GEOSGeom
end

type LineString <: GeoInterface.AbstractLineString
    ptr::GEOSGeom
end

type MultiLineString <: GeoInterface.AbstractMultiLineString
    ptr::GEOSGeom
end

type LinearRing <: GeoInterface.AbstractLineString
    ptr::GEOSGeom
end

type Polygon <: GeoInterface.AbstractPolygon
    ptr::GEOSGeom
end

type MultiPolygon <: GeoInterface.AbstractMultiPolygon
    ptr::GEOSGeom
end
# JuliaGeo/Shapefile.jl

type Rect{T}
    top::T
    left::T
    bottom::T
    right::T
end

abstract ESRIShape
 
type NullShape <: ESRIShape
end

type Interval{T}
    left::T
    right::T
end

type Point{T} <: ESRIShape
    x::T
    y::T
end

type PointM{T,M} <: ESRIShape
    x::T
    y::T
    m::M # measure
end

type PointZ{T,M} <: ESRIShape
    x::T
    y::T
    z::T
    m::M # measure
end

type Polyline{T} <: ESRIShape
    MBR::Rect{T}
    parts::Vector{Int32}
    points::Vector{Point{T}}
end

type PolylineM{T,M} <: ESRIShape
    MBR::Rect{T}
    parts::Vector{Int32}
    points::Vector{Point{T}}
    measures::Vector{M}
end

type PolylineZ{T,M} <: ESRIShape
    MBR::Rect{T}
    parts::Vector{Int32}
    points::Vector{Point{T}}
    zvalues::Vector{T}
    measures::Vector{M}
end

type Polygon{T} <: ESRIShape
    MBR::Rect{T}
    parts::Vector{Int32}
    points::Vector{Point{T}}
end

type PolygonM{T,M} <: ESRIShape
    MBR::Rect{T}
    parts::Vector{Int32}
    points::Vector{Point{T}}
    measures::Vector{M}
end

type PolygonZ{T,M} <: ESRIShape
    MBR::Rect{T}
    parts::Vector{Int32}
    points::Vector{Point{T}}
    zvalues::Vector{T}
    measures::Vector{M}
end

type MultiPoint{T} <: ESRIShape
    MBR::Rect{T}
    points::Vector{Point{T}}
end

type MultiPointM{T,M} <: ESRIShape
    MBR::Rect{T}
    points::Vector{Point{T}}
    measures::Vector{M}
end

type MultiPointZ{T,M} <: ESRIShape
    MBR::Rect{T}
    points::Vector{Point{T}}
    zvalues::Vector{T}
    measures::Vector{M}
end

type MultiPatch{T,M} <: ESRIShape
    MBR::Rect{T}
    parts::Vector{Int32}
    parttypes::Vector{Int32}
    points::Vector{Point{T}}
    zvalues::Vector{T}
    # measures::Vector{M} # (optional)
end
# JuliaGeo/Geodesy.jl

abstract Datum

# A few common datums

# Default Datum: World Geodetic Coordinate System of 1984 (WGS 84)
immutable WGS84 <: Datum end
ellipsoid(::Type{WGS84}) = eWGS84

immutable ETRS89 <: Datum end
ellipsoid(::Type{ETRS89}) = eGRS80

immutable NAD83 <: Datum end
ellipsoid(::Type{NAD83}) = eGRS80

immutable ED50 <: Datum end
ellipsoid(::Type{ED50}) = eHayford

immutable OSGB36 <: Datum end
ellipsoid(::Type{OSGB36}) = eAiry

immutable NAD27 <: Datum end
ellipsoid(::Type{NAD27}) = eClarke1866

### Point in Latitude-Longitude-Altitude (LLA) coordinates
immutable LLA{T <: Datum}
    lat::Float64
    lon::Float64
    alt::Float64
end

### Latitude-Longitude (LL) coordinates
immutable LL{T <: Datum}
    lat::Float64
    lon::Float64
end

### Point in Earth-Centered-Earth-Fixed (ECEF) coordinates
# Global cartesian coordinate system rotating with the Earth
immutable ECEF
    x::Float64
    y::Float64
    z::Float64
end

### Point in East-North-Up (ENU) coordinates
# Local cartesian coordinate system
# Linearized about a reference point
immutable ENU
    east::Float64
    north::Float64
    up::Float64
end

### XYZ
# Helper for creating other point types in generic code
# e.g. myfunc{T <: Union(ENU, LLA)}(...) = (x, y = ...; T(XY(x, y)))
type XYZ
    x::Float64
    y::Float64
    z::Float64
end

immutable Ellipsoid
    a::Float64        # Semi-major axis
    b::Float64        # Semi-minor axis::Float64       # Eccentricity squared
    e′²::Float64      # Second eccentricity squared
end
# SFML.jl
type Line
    rect::RectangleShape
    p1::Vector2
    p2::Vector2
    thickness::Real
end

type FloatRect
    left::Cfloat
    top::Cfloat
    width::Cfloat
    height::Cfloat
end

type IntRect
    left::Cint
    top::Cint
    width::Cint
    height::Cint
end
# dcjones/Compose.jl

abstract Container <: ComposeNode


# The basic Container which defines a coordinate transform for its children.
type Context <: Container
    # Bounding box relative to the parent's coordinates
    box::BoundingBox

    # Context coordinates used for children
    units::UnitBox

    # Rotation is degrees of
    rot::Rotation

    # Maybe mirror about a line, after rotation
    mir::Maybe(Mirror)

    # Container children
    children::List{ComposeNode}

    # Z-order of this context relative to its siblings.
    order::Int

    # True if children of the canvas should be clipped by its bounding box.
    clip::Bool

    # Ignore this context and everything under it if we are
    # not drawing to the SVGJS backend.
    withjs::Bool

    # Ignore this context if we *are* drawing on the SVGJS backend.
    withoutjs::Bool

    # If possible, render this subtree as a bitmap. This requires the Cairo. If
    # Cairo isn't available, default rendering is used.
    raster::Bool

    # Contexts may be annotated with the minimum size needed to be drawn
    # correctly, information that can be used by layout containers. Sizes
    # are absolute (i.e. millimeters).
    minwidth::Maybe(Float64)
    minheight::Maybe(Float64)

    # A field that can be used by layouts to indicate that one configuration
    # is preferable to another.
    penalty::Float64
end

# Measures without Canvas Units
# -----------------------------

# Rather than introducing a new type to represent measures that
# have no canvas unit dimension, we just parameterize Measure
# over a special type that promotes appropriately.
immutable MeasureNil
end

const measure_nil = MeasureNil()

# All measures in Compose are specified as the sum
immutable Measure{S, T}
    abs::Float64 # absolute measurement in millimeters
    cx::S        # canvas x-units
    cy::T        # canvas y-units
    cw::Float64  # proportion of canvas width
    ch::Float64  # proportion of canvas height
end

typealias SimpleMeasure Measure{MeasureNil, MeasureNil}

immutable Point{XM <: Measure, YM <: Measure}
    x::XM
    y::YM
end

typealias SimplePoint Point{SimpleMeasure, SimpleMeasure}

immutable BoundingBox
    x0::Measure
    y0::Measure
    width::Measure
    height::Measure
end

abstract FormPrimitive

immutable Form{P <: FormPrimitive} <: ComposeNode
    primitives::Vector{P}
end

immutable PolygonPrimitive{P <: Point} <: FormPrimitive
    points::Vector{P}
end

typealias Polygon Form{PolygonPrimitive}

immutable RectanglePrimitive{P <: Point, M1 <: Measure, M2 <: Measure} <: FormPrimitive
    corner::P
    width::M1
    height::M2
end

typealias Rectangle Form{RectanglePrimitive}

immutable CirclePrimitive{P <: Point, M <: Measure} <: FormPrimitive
    center::P
    radius::M
end

typealias Circle Form{CirclePrimitive}

immutable EllipsePrimitive{P1 <: Point, P2 <: Point, P3 <: Point} <: FormPrimitive
    center::P1
    x_point::P2
    y_point::P3
end

typealias Ellipse Form{EllipsePrimitive}

immutable LinePrimitive{P <: Point} <: FormPrimitive
    points::Vector{P}
end

typealias Line Form{LinePrimitive}

immutable CurvePrimitive{P1 <: Point, P2 <: Point, P3 <: Point, P4 <: Point} <: FormPrimitive
    anchor0::P1
    ctrl0::P2
    ctrl1::P3
    anchor1::P4
end

typealias Curve Form{CurvePrimitive}
# Compose3D.jl

type Context <: Compose3DNode
	box :: BoundingBox #Parent box.
	children :: List{Compose3DNode}
end
abstract Measure

immutable Length{unit} <: Measure
    value::Float64
end

# Higher-order measures
immutable Point{N, T}
    x::NTuple{N, T}
end

immutable BoundingBox{N, X, A}
    x0::Point{N, X}
    a::NTuple{N, A}
end

typealias AbsoluteBox{N}   BoundingBox{N, Length{:mm}, Length{:mm}}
typealias Absolute3DBox    AbsoluteBox{3}
abstract GeometryPrimitive

#Geometry type.
immutable Geometry{P <: GeometryPrimitive} <: Compose3DNode
    primitives::Vector{P}
end

#Cube

immutable CubePrimitive <: GeometryPrimitive
    corner::Point{3}
    side::Length
end

typealias Cube Geometry{CubePrimitive}

immutable SpherePrimitive <: GeometryPrimitive
    center::Point{3}
    radius::Length
end

typealias Sphere Geometry{SpherePrimitive}

immutable PyramidPrimitive <: GeometryPrimitive
    corner::Point{3}
    base::Length
    height::Length
end

typealias Pyramid Geometry{PyramidPrimitive}
function polyline3d(px, py, pz)
  assert(length(px) == length(py) == length(pz))
  n = length(px)
  ccall( (:gr_polyline3d, libGR),
        Void,
        (Int32, Ptr{Float64}, Ptr{Float64}, Ptr{Float64}),
        n, convert(Vector{Float64}, px), convert(Vector{Float64}, py), convert(Vector{Float64}, pz))
end

function surface(px, py, pz, option::Int)
  nx = length(px)
  ny = length(py)
  nz = length(pz)
  if ndims(pz) == 1
    out_of_bounds = nz != nx * ny
  elseif ndims(pz) == 2
    out_of_bounds = size(pz)[1] != nx || size(pz)[2] != ny
  else
    out_of_bounds = true
  end
  if !out_of_bounds
    ccall( (:gr_surface, libGR),
          Void,
          (Int32, Int32, Ptr{Float64}, Ptr{Float64}, Ptr{Float64}, Int32),
          nx, ny, convert(Vector{Float64}, px), convert(Vector{Float64}, py), convert(Vector{Float64}, pz), option)
  else
    println("Arrays have incorrect length or dimension.")
  end
end

Clone this wiki locally