Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim down GeometryBasics and remove all type complexity #173

Merged
merged 69 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
be5c6ba
get rid of StaticArrays
SimonDanisch Feb 22, 2022
505c89b
alias must be fully typed
SimonDanisch Feb 22, 2022
88f6a12
more fixes
SimonDanisch Feb 22, 2022
13854cc
fix order
SimonDanisch Feb 22, 2022
3beed30
Merge branch 'master' into sd/no-sarray
SimonDanisch Feb 25, 2022
46bebc3
more fixes
SimonDanisch Mar 2, 2022
b2ca48b
Merge branch 'master' into sd/no-sarray
SimonDanisch Mar 14, 2022
ea0db94
simplify fixed array
SimonDanisch Mar 16, 2022
c1ea315
remove meta types
SimonDanisch Mar 16, 2022
924bd2e
try to get mesh working
SimonDanisch Mar 16, 2022
a8f3293
remove all the things!!
SimonDanisch Mar 17, 2022
834fb12
more tests
SimonDanisch Mar 17, 2022
c52937e
remove 1.3
SimonDanisch Mar 17, 2022
857ae2d
drop 1.3
SimonDanisch Mar 17, 2022
848e281
add imports and get overload
SimonDanisch Mar 18, 2022
e58d235
add getindex for faces for vec too
SimonDanisch Jun 16, 2022
9e9bf34
fixes
SimonDanisch Jun 20, 2022
635150e
bring back connect
SimonDanisch Jun 20, 2022
991bacc
add / for e.g. mean(points)
SimonDanisch Jun 21, 2022
90aed0e
small improvements
SimonDanisch Jun 21, 2022
ffa5e08
introduce TriangleMesh
SimonDanisch Jun 22, 2022
cba8ec8
fix constructor and print Mesh more nicely
SimonDanisch Jun 22, 2022
1238b05
add zero for value
SimonDanisch Aug 8, 2022
b0be05a
likely broken merge attempt
SimonDanisch Aug 24, 2022
4e42013
Merge branch 'sd/simple-mesh' of https://github.com/JuliaGeometry/Geo…
SimonDanisch Aug 24, 2022
a7fba75
fix tests
SimonDanisch Sep 15, 2022
785d940
polys
SimonDanisch Sep 16, 2022
b1f6567
Merge branch 'master' into sd/simple-mesh
SimonDanisch Feb 15, 2023
4ec151a
Merge branch 'master' into sd/simple-mesh
SimonDanisch Nov 7, 2023
26f5388
Merge branch 'master' into sd/simple-mesh
SimonDanisch May 1, 2024
113812f
fix some compile errors
ffreyer Aug 30, 2024
26a861a
fix Simplex <: AbstractSimplex <: Polytope
ffreyer Aug 30, 2024
5567b04
fix decompose test
ffreyer Aug 30, 2024
12c6eb4
fix Rect2 Tesselation
ffreyer Aug 30, 2024
2fa2020
fix ngeom for LineString
ffreyer Aug 30, 2024
8a6c975
fix compat bounds
ffreyer Aug 30, 2024
6c7b407
change getindex index to Integer
ffreyer Aug 31, 2024
15eb932
remove triangle_mesh Tesselation deprecation warning
ffreyer Aug 31, 2024
f600cb6
fix Base.intersect extension
ffreyer Sep 2, 2024
5bcefb1
update union docs and comment out broken diff or rects
ffreyer Sep 2, 2024
fe8380d
add decompose_x methdos with types
ffreyer Sep 2, 2024
73093c5
disable diff test
ffreyer Sep 2, 2024
5d2a134
fix MatN constructors
ffreyer Sep 4, 2024
406397f
fix type ambiguity
ffreyer Sep 4, 2024
ede77d7
fix vcat of StaticVector, Mat convert
ffreyer Sep 4, 2024
54d9e52
add mat[VecOrInt, VecOrInt] and Vec(mat)
ffreyer Sep 4, 2024
e420121
match isapprox implementation with docstring
ffreyer Sep 4, 2024
58a4d83
add isapprox to Mat
ffreyer Sep 4, 2024
8562c1d
fix indexing instead of implementing isapprox
ffreyer Sep 4, 2024
556df6f
rework broadcasting & add more tests
ffreyer Sep 5, 2024
4207897
fix nested broadcast
ffreyer Sep 5, 2024
1e08423
fix Mat getindex, Boundschecks and add tests
ffreyer Sep 5, 2024
454cd4e
fix broadcast size missmatch
ffreyer Sep 5, 2024
a5ab6fd
handle map like StaticArrays
ffreyer Sep 5, 2024
4891a29
add isapprox and converts from Matrix for Mat3f-like types
ffreyer Sep 6, 2024
94aefd5
avoid creating Base arrays on copy
ffreyer Sep 6, 2024
d485293
Geometry Basics refactor (#219)
ffreyer Oct 16, 2024
73ae2c1
add GLMakie to docs
SimonDanisch Oct 16, 2024
6ba2806
fix pkg command
SimonDanisch Oct 16, 2024
c8ba30b
rename clear_faceviews & update
ffreyer Oct 16, 2024
943095e
Merge branch 'sd/simple-mesh' of https://github.com/JuliaGeometry/Geo…
ffreyer Oct 16, 2024
14ab2d3
fix pkg
SimonDanisch Oct 16, 2024
536a9b5
Merge branch 'sd/simple-mesh' of https://github.com/JuliaGeometry/Geo…
SimonDanisch Oct 16, 2024
5fe7d9e
fix another clear_faceviews
ffreyer Oct 16, 2024
cf57b4c
Merge branch 'sd/simple-mesh' of https://github.com/JuliaGeometry/Geo…
ffreyer Oct 16, 2024
a3b5ddd
fix docs
SimonDanisch Oct 16, 2024
df37139
Merge branch 'sd/simple-mesh' of https://github.com/JuliaGeometry/Geo…
SimonDanisch Oct 16, 2024
06fb3ea
use action cache
SimonDanisch Oct 16, 2024
4a27454
fix typo
SimonDanisch Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- master
- sd/simple-mesh
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand All @@ -29,16 +30,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
Expand All @@ -47,20 +39,23 @@ jobs:
file: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
JULIA_PKG_SERVER: ""
steps:
- uses: actions/checkout@v2
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev xsettingsd x11-xserver-utils
- uses: julia-actions/setup-julia@v1
with:
version: "1.7"
version: "1.11"
- uses: julia-actions/cache@v2
- run: |
julia --project=docs -e '
DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
pkg"add MeshIO#ff/GeometryBasics_refactor MakieCore#breaking-0.22 Makie#breaking-0.22 GLMakie#breaking-0.22"
Pkg.instantiate()'
- run: julia --project=docs docs/make.jl
- run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
9 changes: 4 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
Aqua = "0.8"
Expand All @@ -22,10 +22,9 @@ GeoJSON = "0.7, 0.8"
IterTools = "1.3.0"
LinearAlgebra = "<0.0.1,1"
OffsetArrays = "1"
PrecompileTools = "1.0"
Random = "<0.0.1,1"
StaticArrays = "0.12, 1.0"
StructArrays = "0.6"
Tables = "0.2, 1"
StaticArrays = "0.6, 1"
Test = "<0.0.1,1"
julia = "1.6"

Expand Down
3 changes: 1 addition & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ makedocs(format=Documenter.HTML(prettyurls=get(ENV, "CI", "false") == "true"),
pages=[
"index.md",
"primitives.md",
"rectangles.md",
"polygons.md",
"meshes.md",
"decomposition.md",
"metadata.md",
"static_array_types.md",
"api.md"
],
modules=[GeometryBasics])
Expand Down
111 changes: 24 additions & 87 deletions docs/src/decomposition.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,26 @@
# Decomposition


## GeometryBasics Mesh interface

GeometryBasics defines an interface to decompose abstract geometries into
points and triangle meshes.
This can be done for any arbitrary primitive, by overloading the following interface:

```julia

function GeometryBasics.coordinates(rect::Rect2, nvertices=(2,2))
mini, maxi = extrema(rect)
xrange, yrange = LinRange.(mini, maxi, nvertices)
return ivec(((x,y) for x in xrange, y in yrange))
end

function GeometryBasics.faces(rect::Rect2, nvertices=(2, 2))
w, h = nvertices
idx = LinearIndices(nvertices)
quad(i, j) = QuadFace{Int}(idx[i, j], idx[i+1, j], idx[i+1, j+1], idx[i, j+1])
return ivec((quad(i, j) for i=1:(w-1), j=1:(h-1)))
end
```
Those methods, for performance reasons, expect you to return an iterator, to make
materializing them with different element types allocation free. But of course,
can also return any `AbstractArray`.

With these methods defined, this constructor will magically work:

```julia
rect = Rect2(0.0, 0.0, 1.0, 1.0)
m = GeometryBasics.mesh(rect)
```
If you want to set the `nvertices` argument, you need to wrap your primitive in a `Tesselation`
object:
```julia
m = GeometryBasics.mesh(Tesselation(rect, (50, 50)))
length(coordinates(m)) == 50^2
```

As you can see, `coordinates` and `faces` are also defined on a mesh
```julia
coordinates(m)
faces(m)
```
But will actually not be an iterator anymore. Instead, the mesh constructor uses
the `decompose` function, that will collect the result of coordinates and will
convert it to a concrete element type:
```julia
decompose(Point2f, rect) == convert(Vector{Point2f}, collect(coordinates(rect)))
```
The element conversion is handled by `simplex_convert`, which also handles convert
between different face types:
```julia
decompose(QuadFace{Int}, rect) == convert(Vector{QuadFace{Int}}, collect(faces(rect)))
length(decompose(QuadFace{Int}, rect)) == 1
fs = decompose(GLTriangleFace, rect)
fs isa Vector{GLTriangleFace}
length(fs) == 2 # 2 triangles make up one quad ;)
```
`mesh` uses the most natural element type by default, which you can get with the unqualified Point type:
```julia
decompose(Point, rect) isa Vector{Point{2, Float64}}
```
You can also pass the element type to `mesh`:
```julia
m = GeometryBasics.mesh(rect, pointtype=Point2f, facetype=QuadFace{Int})
```
You can also set the uv and normal type for the mesh constructor, which will then
calculate them for you, with the requested element type:
```julia
m = GeometryBasics.mesh(rect, uv=Vec2f, normaltype=Vec3f)
```

As you can see, the normals are automatically calculated,
the same is true for texture coordinates. You can overload this behavior by overloading
`normals` or `texturecoordinates` the same way as coordinates.
`decompose` works a bit different for normals/texturecoordinates, since they dont have their own element type.
Instead, you can use `decompose` like this:
```julia
decompose(UV(Vec2f), rect)
decompose(Normal(Vec3f), rect)
# the short form for the above:
decompose_uv(rect)
decompose_normals(rect)
```
You can also use `triangle_mesh`, `normal_mesh` and `uv_normal_mesh` to call the
`mesh` constructor with predefined element types (Point2/3f, Vec2/3f), and the requested attributes.
## decompose functions

The `decompose` functions allow you to grab certain data from an `AbstractGeometry` like a mesh or primitive and convert it to a requested type, if possible.
They can also be used to convert an array of e.g. faces into a different face type directly.
The default decomposition implemented by GeoemtryBasics are:
- `decompose(::Type{<: Point}, source)` which collects data from `source` using `coordinates(source)` and converts it to the given point type.
- `decompose_normals([::Type{<: Vec},] source) = decompose([::Type{Normals{<: Vec}}},] source)` which collects data with `normals(source)` and converts it to the given Vec type.
- `decompose_uv([::Type{<: Vec},] source) = decompose([::Type{UV{<: Vec}}},] source)` which collects data with `texturecoordinates(source)` and converts it to the given Vec type. This function also exists with `UVW` texture coordinates.
- `decompose(::Type{<: AbstractFace}, source)` which collects data with `faces(source)` and converts it to the given face type.

### Extending decompose

For `decompose` to work there needs to be a conversion from some element type to some target type.
GeometryBasics relies on `GeometryBasics.convert_simplex(TargetType, value)` for this.
If you want to add new types to decompose, e.g. a new face type, you will need to add a method to that function.

## Primitive decomposition

GeometryBasics defines an interface to decompose geometry primitives into vertex attributes and faces.
The interface includes four functions:
- `coordinates(primitive[, nvertices])` which produces the positions associated with the primitive
- `faces(primitive[, nvertices])` which produces the faces which connect the vertex positions to a mesh
- `normals(primitive[, nvertices])` which optionally provide normal vectors of the primitive
- `texturecoordinates(primitive[, nvertices])` which optional provide texture coordinates (uv/uvw) of the primitive
5 changes: 0 additions & 5 deletions docs/src/implementation.md

This file was deleted.

85 changes: 6 additions & 79 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,20 @@ p2 = Point(1, 3);
p3 = Point(4, 4);
```

Geometries can carry metadata:

```@repl quickstart
poi = meta(p1, city="Abuja", rainfall=1221.2)
```

Metadata is stored in a NamedTuple and can be retrieved as such:

```@repl quickstart
meta(poi)
```

Specific metadata attributes can be directly retrieved:

```@repl quickstart
poi.rainfall
```

To remove the metadata and keep only the geometry, use `metafree`:

```@repl quickstart
metafree(poi)
```

Geometries have predefined metatypes:

```@repl quickstart
multipoi = MultiPointMeta([p1], city="Abuja", rainfall=1221.2)
```

Connect the points with lines:
Connect pairs of points as line segments:

```@repl quickstart
l1 = Line(p1, p2)
l2 = Line(p2, p3);
```

Connect the lines in a linestring:

```@repl quickstart
LineString([l1, l2])
```

Linestrings can also be constructed directly from points:
Or connect multiple points as a linestring:

```@repl quickstart
LineString([p1, p2, p3])
```

The same goes for polygons:
You can also create polygons from points:

```@repl quickstart
Polygon(Point{2, Int}[(3, 1), (4, 4), (2, 4), (1, 2), (3, 1)])
Expand All @@ -89,57 +53,20 @@ Decompose the rectangle into two triangular faces:
rect_faces = decompose(TriangleFace{Int}, rect)
```

Decompose the rectangle into four vertices:
Decompose the rectangle into four positions:

```@repl quickstart
rect_vertices = decompose(Point{2, Float64}, rect)
rect_positions = decompose(Point{2, Float64}, rect)
```

Combine the vertices and faces into a triangle mesh:

```@repl quickstart
mesh = Mesh(rect_vertices, rect_faces)
mesh = Mesh(rect_positions, rect_faces)
```

Use `GeometryBasics.mesh` to get a mesh directly from a geometry:

```@repl quickstart
mesh = GeometryBasics.mesh(rect)
```


## Aliases

GeometryBasics exports common aliases for Point, Vec, Mat and Rect:

### Vec

| |`T`(eltype) |`Float64` |`Float32` |`Int` |`UInt` |
|--------|------------|----------|----------|----------|----------|
|`N`(dim)|`Vec{N,T}` |`Vecd{N}` |`Vecf{N}` |`Veci{N}` |`Vecui{N}`|
|`2` |`Vec2{T}` |`Vec2d` |`Vec2f` |`Vec2i` |`Vec2ui` |
|`3` |`Vec3{T}` |`Vec3d` |`Vec3f` |`Vec3i` |`Vec3ui` |

### Point

| |`T`(eltype) |`Float64` |`Float32` |`Int` |`UInt` |
|--------|------------|----------|----------|----------|----------|
|`N`(dim)|`Point{N,T}`|`Pointd{N}`|`Pointf{N}`|`Pointi{N}`|`Pointui{N}`|
|`2` |`Point2{T}` |`Point2d` |`Point2f` |`Point2i` |`Point2ui`|
|`3` |`Point3{T}` |`Point3d` |`Point3f` |`Point3i` |`Point3ui`|

### Mat

| |`T`(eltype) |`Float64` |`Float32` |`Int` |`UInt` |
|--------|------------|----------|----------|----------|----------|
|`N`(dim)|`Mat{N,T}` |`Matd{N}` |`Matf{N}` |`Mati{N}` |`Matui{N}`|
|`2` |`Mat2{T}` |`Mat2d` |`Mat2f` |`Mat2i` |`Mat2ui` |
|`3` |`Mat3{T}` |`Mat3d` |`Mat3f` |`Mat3i` |`Mat3ui` |

### Rect

| |`T`(eltype) |`Float64` |`Float32` |`Int` |`UInt` |
|--------|------------|----------|----------|----------|----------|
|`N`(dim)|`Rect{N,T}` |`Rectd{N}`|`Rectf{N}`|`Recti{N}`|`Rectui{N}`|
|`2` |`Rect2{T}` |`Rect2d` |`Rect2f` |`Rect2i` |`Rect2ui` |
|`3` |`Rect3{T}` |`Rect3d` |`Rect3f` |`Rect3i` |`Rect3ui` |
Loading
Loading