Skip to content

Commit 25780ec

Browse files
authored
update docstrings and README (#10)
* update README * update docstrings and comments * update README * update docstrings and README
1 parent e674772 commit 25780ec

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TileMaps
22

3-
`TileMaps` is a package that makes it simple to create 2D tile maps in Julia. It is designed to be lightweight and fast, and have minimal dependencies.
3+
`TileMaps` is a package that makes it simple to create 2D tile maps (and higher dimensional equivalents) in Julia. It is designed to be lightweight and fast, and have minimal dependencies.
44

55
**Note:** This package does not export any names. The examples below that demonstrate the use of this package assume that it has been loaded via `import TileMaps as TM`.
66

@@ -24,7 +24,9 @@ struct ObjectIndexableArray{T, N, A, O} <: AbstractArray{T, N}
2424
end
2525
```
2626

27-
We'll refer to an instance of `ObjectIndexableArray` as `object_indexable_array`. An `object_indexable_array` simply wraps an `array` and allows us to index its first dimension using a [singleton](https://docs.julialang.org/en/v1/manual/types/#man-singleton-types) object or an array of singleton objects (in addition to all the other ways of indexing `array`).
27+
An instance of `ObjectIndexableArray`, referred to as `object_indexable_array` here, simply wraps an `array` (whose type is captured by the type parameter `A` above) and allows us to index its first dimension using a [singleton](https://docs.julialang.org/en/v1/manual/types/#man-singleton-types) object or an array of singleton objects (in addition to all the other ways of indexing the wrapped `array`). Information about the objects is stored in the type parameter `O` above which is essentially the type of tuple of objects along the `num_objects` dimension. Note that `size(object_indexable_array, 1)` should be equal to the number of elements in the type parameter `O`.
28+
29+
`size(object_indexable_array, 1)` should be equal to the number of elements in the type parameter `O`.
2830

2931
### Objects
3032

@@ -51,13 +53,15 @@ julia> struct MyObject <: TM.AbstractObject end
5153
julia>
5254
```
5355

54-
### TileMap
56+
For an `object_indexable_array`, you can get the type of tuple of objects in it using `TM.get_objects_type(object_indexable_array)`, or you can get the tuple of objects itself, using `TM.get_objects(object_indexable_array)`.
57+
58+
### `TileMap`
5559

5660
```
5761
const TileMap{O} = ObjectIndexableArray{Bool, 3, BitArray{3}, O}
5862
```
5963

60-
We'll refer to an instance of `TileMap` as `tile_map`. A `tile_map` wraps an `array` of size `(num_objects, height, width)`, which encodes information about the presence or absence of objects across the tiles. Each tile can contain multiple objects, which is captured by a multi-hot encoding along the first dimension (`num_objects` dimension) of the `array`.
64+
An instance of `TileMap`, referred to as `tile_map` here, wraps an `array` of type `BitArray{3}` and is of size `(num_objects, height, width)`, which encodes information about the presence or absence of objects across the tiles using Boolean values. Each tile can contain multiple objects, which is captured by a multi-hot encoding along the first dimension (`num_objects` dimension) of the `array`.
6165

6266
### Constructing a `TileMap`
6367

@@ -73,11 +77,11 @@ You can instantiate a `TileMap` using the following constructor that are provide
7377
7478
1. Create a `tile_map` using a tuple of objects and an existing `array`:
7579
76-
```
77-
julia> tile_map = TM.TileMap((TM.EXAMPLE_OBJECT_1, TM.EXAMPLE_OBJECT_2, TM.EXAMPLE_OBJECT_3), rand(Bool, 3, 8, 16) |> BitArray);
80+
```
81+
julia> tile_map = TM.TileMap((TM.EXAMPLE_OBJECT_1, TM.EXAMPLE_OBJECT_2, TM.EXAMPLE_OBJECT_3), rand(Bool, 3, 8, 16) |> BitArray);
7882
79-
julia>
80-
```
83+
julia>
84+
```
8185
8286
### Indexing a `TileMap`
8387

src/object_indexable_array.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
3+
ObjectIndexableArray{T, N, A, O} <: AbstractArray{T, N}
4+
5+
An instance of `ObjectIndexableArray`, referred to as `object_indexable_array` here, simply wraps an `array` (whose type is captured by the type parameter `A` above) and allows us to index its first dimension using a [singleton](https://docs.julialang.org/en/v1/manual/types/#man-singleton-types) object or an array of singleton objects (in addition to all the other ways of indexing the wrapped `array`). Information about the objects is stored in the type parameter `O` above which is essentially the type of tuple of objects along the `num_objects` dimension. Note that `size(object_indexable_array, 1)` should be equal to the number of elements in the type parameter `O`.
6+
7+
"""
18
struct ObjectIndexableArray{T, N, A, O} <: AbstractArray{T, N}
29
array::A
310
end
@@ -11,7 +18,7 @@ Base.size(object_indexable_array::ObjectIndexableArray, args...; kwargs...) = Ba
1118
Base.getindex(object_indexable_array::ObjectIndexableArray, args...; kwargs...) = Base.getindex(object_indexable_array.array, args..., kwargs...)
1219
Base.setindex!(object_indexable_array::ObjectIndexableArray, args...; kwargs...) = Base.setindex!(object_indexable_array.array, args..., kwargs...)
1320

14-
# indexing using a single object as index
21+
# indexing using a single object
1522
@generated function Base.to_index(object_indexable_array::ObjectIndexableArray{T, N, A, O}, object::X) where {T, N, A, O, X <: AbstractObject}
1623
i = findfirst(X .=== O.parameters)
1724
isnothing(i) && error("Object $object is not present in $object_indexable_array")
@@ -21,6 +28,6 @@ end
2128
Base.getindex(object_indexable_array::ObjectIndexableArray, object::AbstractObject, args...; kwargs...) = getindex(object_indexable_array.array, Base.to_index(object_indexable_array, object), args..., kwargs...)
2229
Base.setindex!(object_indexable_array::ObjectIndexableArray, value::Bool, object::AbstractObject, args...; kwargs...) = setindex!(object_indexable_array.array, value, Base.to_index(object_indexable_array, object), args..., kwargs...)
2330

24-
# indexing using more than one object
31+
# indexing using an array of objects
2532
Base.to_index(object_indexable_array::ObjectIndexableArray, objects::AbstractArray{<:AbstractObject}) = map(object -> Base.to_index(object_indexable_array, object), objects)
2633
Base.getindex(object_indexable_array::ObjectIndexableArray, objects::AbstractArray{<:AbstractObject}, args...; kwargs...) = getindex(object_indexable_array.array, map(object -> Base.to_index(object_indexable_array, object), objects), args..., kwargs...)

src/tile_map.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
2-
The first dimension uses multi-hot encoding to encode objects in a tile.
3-
The second and third dimensions correspond to the height and width of the tile map respectively.
2+
3+
const TileMap{O} = ObjectIndexableArray{Bool, 3, BitArray{3}, O}
4+
5+
An instance of `TileMap`, referred to as `tile_map` here, wraps an `array` of type `BitArray{3}` and is of size `(num_objects, height, width)`, which encodes information about the presence or absence of objects across the tiles using Boolean values. Each tile can contain multiple objects, which is captured by a multi-hot encoding along the first dimension (`num_objects` dimension) of the `array`.
6+
47
"""
58
const TileMap{O} = ObjectIndexableArray{Bool, 3, BitArray{3}, O}
69

0 commit comments

Comments
 (0)