Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Change abstract type Basis to AbstractBasis to be more consistent with our naming convention #307

Merged
merged 4 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion src/Optical/ParaxialAnalysis/HeadEyeModel/Arrangement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ center(h::Shape) = h._center
points(h::Shape) = h._points
coordinates(h::Shape) = h._coordinates

function get_shapes(basis::Basis{2,T},cells::AbstractMatrix{Int}, radius::T) where{T}
function get_shapes(basis::AbstractBasis{2,T},cells::AbstractMatrix{Int}, radius::T) where{T}
basic_tile = Repeat.tilevertices(basis) * radius
cols = Base.size(cells)[2]
res = Vector{Shape{2, T}}(undef, 0)
Expand Down
12 changes: 6 additions & 6 deletions src/RepeatingStructures/Cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

"""A Cluster is a repeating pattern of indices defined in a lattice called the element lattice. The cluster of elements has its own lattice, which by definition is different from the element lattice unless each cluster consists of a single element. A LatticeCluster subtype must implement these methods:

clusterbasis(a::AbstractLatticeCluster) returns the Basis object for the cluster. This is not generally the same as the basis for the underlying lattice.
clusterbasis(a::AbstractLatticeCluster) returns the AbstractBasis object for the cluster. This is not generally the same as the basis for the underlying lattice.

elementbasis(a::AbstractLatticeCluster) returns the Basis object the underlying lattice of the cluster.
elementbasis(a::AbstractLatticeCluster) returns the AbstractBasis object the underlying lattice of the cluster.

clusterelements(a::AbstractLatticeCluster) returns the lattice indices, represented in the underlying lattice basis, for each of the elements in a unit cluster cell.

Expand Down Expand Up @@ -35,13 +35,13 @@ julia> lattice[1,1] #returns the locations of the 3 elements in the cluster at
abstract type AbstractLatticeCluster end

"""Basic lattic cluster type"""
struct LatticeCluster{N1, N, T<:Real, B1<:Basis{N,Int},B2<:Basis{N,T}} <: AbstractLatticeCluster
struct LatticeCluster{N1, N, T<:Real, B1<:AbstractBasis{N,Int},B2<:AbstractBasis{N,T}} <: AbstractLatticeCluster
clusterbasis::B1 #this basis defines the offsets of the clusters
elementbasis::B2 #this basis defines the underlying lattice

clusterelements::SVector{N1,NTuple{N,Int}} #vector containing the lattice indices of the elements in the cluster. Each column is one lattice coordinate. These indices are assumed to be offsets from the origin of the lattice.

LatticeCluster(clusterbasis::B1,eltlattice::B2,clusterelements::SVector{N1,NTuple{N,Int}}) where{N1,N,T<:Real,B1<:Basis{N,Int},B2<:Basis{N,T}} = new{N1,N,T,B1,B2}(clusterbasis,eltlattice,clusterelements)
LatticeCluster(clusterbasis::B1,eltlattice::B2,clusterelements::SVector{N1,NTuple{N,Int}}) where{N1,N,T<:Real,B1<:AbstractBasis{N,Int},B2<:AbstractBasis{N,T}} = new{N1,N,T,B1,B2}(clusterbasis,eltlattice,clusterelements)
end
export LatticeCluster

Expand All @@ -53,7 +53,7 @@ clusterbasis(a::LatticeCluster) = a.clusterbasis
export clusterbasis

"""returns the positions of every element in a cluster given the cluster indices"""
function Base.getindex(A::LatticeCluster{N1,N,T,B1,B2}, indices::Vararg{Int, N}) where{N1,N,T,B1<:Basis{N,Int},B2<:Basis{N,T}}
function Base.getindex(A::LatticeCluster{N1,N,T,B1,B2}, indices::Vararg{Int, N}) where{N1,N,T,B1<:AbstractBasis{N,Int},B2<:AbstractBasis{N,T}}
clusteroffset = A.clusterbasis[indices...]
temp = MMatrix{N,N1,T}(undef)
for i in 1:N1
Expand All @@ -68,7 +68,7 @@ function Base.size(::LatticeCluster{N1,N}) where{N1,N}
return ntuple((i)->Base.IsInfinite(),N)
end

Base.setindex!(A::Basis{N}, v, I::Vararg{Int, N}) where{N} = nothing #can't set lattice points. Might want to throw an exception instead.
Base.setindex!(A::AbstractBasis{N}, v, I::Vararg{Int, N}) where{N} = nothing #can't set lattice points. Might want to throw an exception instead.

""" returns the lattice indices of the elements in the cluster. These are generally not the positions of the elements"""
function clustercoordinates(a::LatticeCluster{N1,N},indices::Vararg{Int,N}) where{N1,N}
Expand Down
4 changes: 2 additions & 2 deletions src/RepeatingStructures/HexagonalLattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const hexcoords = [
cos60 sin60
]

struct HexBasis1{N,T} <: Basis{N,T}
struct HexBasis1{N,T} <: AbstractBasis{N,T}
HexBasis1(::Type{T} = Float64) where{T<:Real} = new{2,T}()
end
export HexBasis1
Expand Down Expand Up @@ -163,7 +163,7 @@ function hexcellsinbox(numi,numj)
end
export Repeat

struct HexBasis3{N,T}<:Basis{N,T}
struct HexBasis3{N,T}<:AbstractBasis{N,T}
HexBasis3(::Type{T} = Float64) where{T} = new{2,T}()
end
export HexBasis3
Expand Down
18 changes: 9 additions & 9 deletions src/RepeatingStructures/Lattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@ julia> a[1,2]
10
```

Subtypes supporting the Basis interface should implement these functions:
Subtypes supporting the AbstractBasis interface should implement these functions:

Returns the neighbors in ring n surrounding centerpoint, excluding centerpoint
```
neighbors(::Type{B},centerpoint::Tuple{T,T},neighborhoodsize::Int) where{T<:Real,B<:Basis}
neighbors(::Type{B},centerpoint::Tuple{T,T},neighborhoodsize::Int) where{T<:Real,B<:AbstractBasis}
```
Returns the lattice basis vectors that define the lattice
```
basis(a::S) where{S<:Basis}
basis(a::S) where{S<:AbstractBasis}
```
Returns the vertices of the unit polygon that tiles the plane for the basis
```
tilevertices(a::S) where{S<:Basis}
tilevertices(a::S) where{S<:AbstractBasis}
```
"""
abstract type Basis{N,T<:Real} end
export Basis
abstract type AbstractBasis{N,T<:Real} end
export AbstractBasis

function Base.getindex(A::B1, indices::Vararg{Int, N}) where{N,T,B1<:Basis{N,T}}
function Base.getindex(A::B1, indices::Vararg{Int, N}) where{N,T,B1<:AbstractBasis{N,T}}
return basismatrix(A)*SVector{N,Int}(indices)
end

# temp::SVector{N,T} = (basis(A)*SVector{N,Int}(indices))::SVector{N,T}
# return temp
# end

Base.setindex!(A::Basis{N,T}, v, I::Vararg{Int, N}) where{T,N} = nothing #can't set lattice points. Might want to throw an exception instead.
Base.setindex!(A::AbstractBasis{N,T}, v, I::Vararg{Int, N}) where{T,N} = nothing #can't set lattice points. Might want to throw an exception instead.

struct LatticeBasis{N,T<:Real} <: Basis{N,T}
struct LatticeBasis{N,T<:Real} <: AbstractBasis{N,T}
basisvectors::SMatrix{N,N,T}

""" Convenience constructor that lets you use tuple arguments to describe the basis instead of SVector
Expand Down
2 changes: 1 addition & 1 deletion src/RepeatingStructures/RectangularLattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See LICENSE in the project root for full license information.


struct RectangularBasis{N,T} <: Basis{N,T}
struct RectangularBasis{N,T} <: AbstractBasis{N,T}
RectangularBasis(::Type{T} = Float64) where{T<:Real} = new{2,T}()
end
export RectangularBasis
Expand Down
4 changes: 2 additions & 2 deletions src/Vis/VisRepeatingStructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# lattice visualizations are drawn with Luxor because it is easier to do 2D drawings with Luxor than with Makie.

function draw(tilebasis::Basis,tilesize,i,j,color,name)
function draw(tilebasis::AbstractBasis,tilesize,i,j,color,name)
vertices = Repeat.tilevertices(tilebasis)
tile = tilesize*[Luxor.Point(vertices[:,i]...) for i in 1:size(vertices)[2]]
pt = tilesize*tilebasis[i,j]
Expand All @@ -36,7 +36,7 @@ function draw(tilebasis::Basis,tilesize,i,j,color,name)
end

"""Draws a list of hexagonal cells, represented by their lattice coordinates"""
function drawcells(tilebasis::Basis, tilesize,cells; color::Union{AbstractArray,Nothing} = nothing, name::Union{AbstractArray{String},Nothing} = nothing, format=:png, resolution=(500,500))
function drawcells(tilebasis::AbstractBasis, tilesize,cells; color::Union{AbstractArray,Nothing} = nothing, name::Union{AbstractArray{String},Nothing} = nothing, format=:png, resolution=(500,500))

numcells = size(cells)[2]
Luxor.Drawing(resolution[1], resolution[2], format)
Expand Down
14 changes: 14 additions & 0 deletions test/testsets/Repeat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,19 @@
return Repeat.ClusterWithProperties(lattice,properties)
end

""" Create a LatticeCluser with three elements at (0,0),(-1,0),(-1,1) coordinates in the HexBasis1 lattice"""
function hex3cluster()
clusterelts = SVector((0,0),(-1,0),(-1,1))
eltlattice = Repeat.HexBasis1()
clusterbasis = Repeat.LatticeBasis(( -1,2),(2,-1))
return Repeat.LatticeCluster(clusterbasis,eltlattice,clusterelts)
end

@test [-1 2;2 -1] == Repeat.basismatrix(Repeat.clusterbasis(hex3RGB()))

function basistest(a::Repeat.AbstractLatticeCluster)
return Repeat.clusterbasis(a)
end

@test basistest(hex3cluster()) == basistest(hex3RGB())
end