API Reference
Exports
GeometryBasics.AbstractGeometry
— TypeAbstract Geometry in R{Dim} with Number type T
GeometryBasics.AbstractMesh
— TypeAbstractMesh
An abstract mesh is a collection of Polytope elements (Simplices / Ngons). The connections are defined via faces(mesh), the coordinates of the elements are returned by coordinates(mesh). Arbitrary meta information can be attached per point or per face
GeometryBasics.Circle
— TypeCircle{T}
An alias for a HyperSphere of dimension 2. (i.e. HyperSphere{2, T}
)
GeometryBasics.Cylinder
— TypeCylinder{N, T}
A Cylinder
is a 2D rectangle or a 3D cylinder defined by its origin point, its extremity and a radius. origin
, extremity
and r
, must be specified.
GeometryBasics.Cylinder2
— TypeCylinder2{T}
Cylinder3{T}
A Cylinder2
or Cylinder3
is a 2D/3D cylinder defined by its origin point, its extremity and a radius. origin
, extremity
and r
, must be specified.
GeometryBasics.FaceView
— TypeFaceView{Elemnt, Point, Face, P, F}
FaceView enables to link one array of points via a face array, to generate one abstract array of elements. E.g., this becomes possible:
x = FaceView(rand(Point3f0, 10), TriangleFace[(1, 2, 3), (2, 4, 5), ...])
x[1] isa Triangle == true
x isa AbstractVector{<: Triangle} == true
# This means we can use it as a mesh:
Mesh(x) # should just work!
Can also be used for Points:
linestring = FaceView(points, LineFace[...])
Polygon(linestring)
GeometryBasics.HyperSphere
— TypeHyperSphere{N, T}
A HyperSphere
is a generalization of a sphere into N-dimensions. A center
and radius, r
, must be specified.
GeometryBasics.LineString
— TypeLineString(points::AbstractVector{<:AbstractPoint})
A LineString is a geometry of connected line segments
GeometryBasics.LineString
— TypeLineString(points::AbstractVector{<: AbstractPoint}, indices::AbstractVector{<: Integer}, skip = 1)
Creates a LineString from a vector of points and an index list. With skip == 1
, the default, it will connect the line like this:
points = Point[a, b, c, d]; faces = [1, 2, 3, 4]
linestring = LineString(points, faces)
@assert linestring == LineString([a => b, b => c, c => d])
To make a segmented line, set skip to 2
points = Point[a, b, c, d]; faces = [1, 2, 3, 4]
linestring = LineString(points, faces, 2)
@assert linestring == LineString([a => b, c => d])
GeometryBasics.LineString
— TypeLineString(points::AbstractVector{<: AbstractPoint}, skip = 1)
Creates a LineString from a vector of points With skip == 1
, the default, it will connect the line like this:
points = Point[a, b, c, d]
linestring = LineString(points)
@assert linestring == LineString([a => b, b => c, c => d])
GeometryBasics.Mesh
— TypeMesh <: AbstractVector{Element}
The conrecte AbstractMesh implementation
GeometryBasics.MultiPoint
— TypeMultiPoint(points::AbstractVector{AbstractPoint})
A collection of points
GeometryBasics.MultiPolygon
— TypeMultiPolygon(polygons::AbstractPolygon)
GeometryBasics.NormalMesh
— TypeNormalMesh{Dim, T}
PlainMesh with normals meta at each point. normalmesh.normals isa AbstractVector{Vec3f0}
GeometryBasics.NormalUVMesh
— TypeNormalUVMesh{Dim, T}
PlainMesh with normals and uv meta at each point. normalmesh.normals isa AbstractVector{Vec3f0}
normalmesh.uv isa AbstractVector{Vec2f0}
GeometryBasics.NormalUVWMesh
— TypeNormalUVWMesh{Dim, T}
PlainMesh with normals and uvw (texture coordinates in 3D) meta at each point. normalmesh.normals isa AbstractVector{Vec3f0}
normalmesh.uvw isa AbstractVector{Vec3f0}
GeometryBasics.OffsetInteger
— TypeOffsetInteger{O, T}
OffsetInteger type mainly for indexing.
O
- The offset relative to Julia arrays. This helps reduce copying when
communicating with 0-indexed systems such as OpenGL.
GeometryBasics.PlainMesh
— TypePlainMesh{Dim, T}
Triangle mesh with no meta information (just points + triangle faces)
GeometryBasics.Polygon
— TypePolygon(exterior::AbstractVector{<:Point})
Polygon(exterior::AbstractVector{<:Point}, interiors::Vector{<:AbstractVector{<:AbstractPoint}})
GeometryBasics.Polytope
— TypeGeometry made of N connected points. Connected as one flat geometry, it makes a Ngon / Polygon. Connected as volume it will be a Simplex / Tri / Cube. Note That Polytope{N} where N == 3
denotes a Triangle both as a Simplex or Ngon.
GeometryBasics.Polytope
— MethodThe Ngon Polytope element type when indexing an array of points with a SimplexFace
GeometryBasics.Polytope
— MethodThe Simplex Polytope element type when indexing an array of points with a SimplexFace
GeometryBasics.Polytope
— MethodThe fully concrete Ngon type, when constructed from a point type!
GeometryBasics.Polytope
— MethodThe fully concrete Simplex type, when constructed from a point type!
GeometryBasics.Rect
— MethodRect(vals::Number...)
Rect(vals::Number...)
Rect constructor for indidually specified intervals. e.g. Rect(0,0,1,2) has origin == Vec(0,0) and width == Vec(1,2)
GeometryBasics.Rect
— MethodConstruct a HyperRectangle enclosing all points.
GeometryBasics.Simplex
— TypeA Simplex
is a generalization of an N-dimensional tetrahedra and can be thought of as a minimal convex set containing the specified points.
- A 0-simplex is a point.
- A 1-simplex is a line segment.
- A 2-simplex is a triangle.
- A 3-simplex is a tetrahedron.
Note that this datatype is offset by one compared to the traditional mathematical terminology. So a one-simplex is represented as Simplex{2,T}
. This is for a simpler implementation.
It applies to infinite dimensions. The structure of this type is designed to allow embedding in higher-order spaces by parameterizing on T
.
GeometryBasics.Sphere
— TypeSphere{T}
An alias for a HyperSphere of dimension 3. (i.e. HyperSphere{3, T}
)
GeometryBasics.Tesselation
— TypeTesselation(primitive, nvertices)
For abstract geometries, when we generate a mesh from them, we need to decide how fine grained we want to mesh them. To transport this information to the various decompose methods, you can wrap it in the Tesselation object e.g. like this:
sphere = Sphere(Point3f0(0), 1)
m1 = mesh(sphere) # uses a default value for tesselation
m2 = mesh(Tesselation(sphere, 64)) # uses 64 for tesselation
length(coordinates(m1)) != length(coordinates(m2))
For grid based tesselation, you can also use a tuple: ```julia rect = Rect2D(0, 0, 1, 1) Tesselation(rect, (5, 5))
GeometryBasics.TriangleMesh
— TypeTriangleMesh{Dim, T, PointType}
Abstract Mesh with triangle elements of eltype T
.
GeometryBasics.TupleView
— TypeTupleView{T, N, Skip, A}
TupleView, groups elements of an array as tuples. N is the dimension of the tuple, M tells how many elements to skip to the next tuple. By default TupleView{N} defaults to skip N items.
a few examples:
x = [1, 2, 3, 4, 5, 6]
TupleView{2, 1}(x):
> [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
TupleView{2}(x):
> [(1, 2), (3, 4), (5, 6)]
TupleView{2, 3}(x):
> [(1, 2), (4, 5)]
TupleView{3, 1}(x):
> [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5, 6)]
TupleView can be used together with reinterpret:
x = [1, 2, 3, 4]
y = reinterpret(Point{2, Int}, TupleView{2, 1}(x))
> [Point(1, 2), Point(2, 3), Point(3, 4)]
GeometryBasics.UVMesh
— TypeUVMesh{Dim, T}
PlainMesh with texture coordinates meta at each point. uvmesh.uv isa AbstractVector{Vec2f0}
GeometryBasics.area
— Methodarea(vertices::AbstractVector{AbstractPoint{3}}, face::TriangleFace)
Calculate the area of one triangle.
GeometryBasics.area
— Methodarea(vertices::AbstractVector{AbstractPoint{3}}, faces::AbstractVector{TriangleFace})
Calculate the area of all triangles.
GeometryBasics.connect
— Methodconnect(points::AbstractVector{<: AbstractPoint}, P::Type{<: Polytype{N}}, skip::Int = N)
Creates a view that connects a number of points to a Polytope P
. Between each polytope, skip
elements are skipped untill the next starts. Example: ```julia x = connect(Point[(1, 2), (3, 4), (5, 6), (7, 8)], Line, 2) x == [Line(Point(1, 2), Point(3, 4)), Line(Point(5, 6), Point(7, 8))]
GeometryBasics.convert_simplex
— Methodconvert_simplex(::Type{Face{2}}, f::Face{N})
Extract all line segments in a Face.
GeometryBasics.convert_simplex
— Methodconvert_simplex(::Type{Face{3}}, f::Face{N})
Triangulate an N-Face into a tuple of triangular faces.
GeometryBasics.coordinates
— Methodcoordinates(geometry)
Returns the edges/vertices/coordinates of a geometry. Is allowed to return lazy iterators! Use decompose(ConcretePointType, geometry)
to get Vector{ConcretePointType}
with ConcretePointType
to be something like Point{3, Float32}
.
GeometryBasics.decompose
— Methodfaces(contour::AbstractArray{Point}, [facetype = GLTriangleFace])
Triangulates a Polygon given as an AbstractArray{Point}
without holes. It will return a Vector{facetype
}, defining indexes into contour
GeometryBasics.faces
— Methodfaces(geometry)
Returns the face connections of a geometry. Is allowed to return lazy iterators! Use decompose(ConcreteFaceType, geometry)
to get Vector{ConcreteFaceType}
with ConcreteFaceType
to be something like TriangleFace{Int}
.
GeometryBasics.intersects
— Methodintersect(a::Line, b::Line) -> Point
Intersection of 2 line segmens a
and b
. Returns intersectionfound::Bool, intersectionpoint
GeometryBasics.meta
— Methodmeta(x::MetaObject)
Returns the metadata of x
GeometryBasics.normals
— Methodnormals{VT,FD,FT,FO}(vertices::Vector{Point{3, VT}},
faces::Vector{Face{FD,FT,FO}},
NT = Normal{3, VT})
Compute all vertex normals.
GeometryBasics.pointmeta
— Methodpointmeta(mesh::Mesh; meta_data...)
Attaches metadata to the coordinates of a mesh
GeometryBasics.self_intersections
— Methodself_intersections(points::AbstractVector{AbstractPoint})
Finds all self intersections of polygon points
GeometryBasics.split_intersections
— Methodsplit_intersections(points::AbstractVector{AbstractPoint})
Splits polygon points
into it's self intersecting parts. Only 1 intersection is handled right now.
Private
GeometryBasics.HyperRectangle
— TypeHyperRectangle{N, T}
A HyperRectangle
is a generalization of a rectangle into N-dimensions. Formally it is the cartesian product of intervals, which is represented by the origin
and width
fields, whose indices correspond to each of the N
axes.
GeometryBasics.Ngon
— TypeFixed Size Polygon, e.g. N 1-2 : Illegal! N = 3 : Triangle N = 4 : Quadrilateral (or Quad, Or tetragon) N = 5 : Pentagon ...
GeometryBasics.Quad
— TypeQuad{T}
A rectangle in 3D space.
Base.:*
— Method*(m::Mat, h::Rect)
Transform a Rect
using a matrix. Maintains axis-align properties so a significantly larger Rect may be generated.
Base.in
— Methodin(b1::Rect, b2::Rect)
Check if Rect b1
is contained in b2
. This does not use strict inequality, so Rects may share faces and this will still return true.
Base.in
— Methodin(pt::VecTypes, b1::Rect{N, T})
Check if a point is contained in a Rect. This will return true if the point is on a face of the Rect.
Base.in
— Methodin(point, triangle)
InsideTriangle decides if a point P is Inside of the triangle defined by A, B, C.
Base.union
— MethodPerform a union between two Rects.
GeometryBasics.MetaFree
— MethodMetaFree(::Type{T})
Returns the original type containing no metadata for T
E.g: ```julia MetaFree(PointMeta) == Point
GeometryBasics.MetaType
— MethodMetaType(::Type{T})
Returns the Meta Type corresponding to T
E.g: ```julia MetaType(Point) == PointMeta
GeometryBasics.attributes
— Methodattributes(hasmeta)
Returns all attributes of meta as a Dict{Symbol, Any}. Needs to be overloaded, and returns empty dict for non overloaded types! Gets overloaded by default for all Meta types.
GeometryBasics.diff
— Methoddiff(h1::Rect, h2::Rect)
Perform a difference between two Rects.
GeometryBasics.facemeta
— Methodfacemeta(mesh::Mesh; meta_data...)
Attaches metadata to the faces of a mesh
GeometryBasics.getcolumns
— Methodgetcolumns(t, colnames::Symbol...)
Gets a column from any Array like (Table/AbstractArray). For AbstractVectors, a column will be the field names of the element type.
GeometryBasics.intersect
— Methodintersect(h1::Rect, h2::Rect)
Perform a intersection between two Rects.
GeometryBasics.mesh
— Methodmesh(primitive::GeometryPrimitive;
pointtype=Point, facetype=GLTriangle,
uvtype=nothing, normaltype=nothing)
Creates a mesh from primitive
. Uses the element types from the keyword arguments to create the attributes. The attributes that have their type set to nothing are not added to the mesh. Note, that this can be an Int
or Tuple{Int, Int}
`, when the primitive is grid based. It also only losely correlates to the number of vertices, depending on the algorithm used. #TODO: find a better number here!
GeometryBasics.mesh
— Methodmesh(polygon::AbstractVector{P}; pointtype=P, facetype=GLTriangleFace,
normaltype=nothing)
Polygon triangluation!
GeometryBasics.orthogonal_vector
— MethodThe unnormalized normal of three vertices.
GeometryBasics.pop_pointmeta
— Methodpop_pointmeta(mesh::Mesh, property::Symbol)
Remove property
from point metadata. Returns the new mesh, and the property!
GeometryBasics.split
— Methodsplit(rectangle, axis, value)
Splits an Rect into two along an axis at a given location.
GeometryBasics.volume
— Methodvolume(triangle)
Calculate the signed volume of one tetrahedron. Be sure the orientation of your surface is right.
GeometryBasics.volume
— Methodvolume(mesh)
Calculate the signed volume of all tetrahedra. Be sure the orientation of your surface is right.