Compare commits

..

No commits in common. "43cbf8a3a0c3e2152306876e8481fbcab797f7f8" and "a3f3f6a31bde0f28c01cb35c9ad18f7719232d90" have entirely different histories.

View File

@ -72,21 +72,21 @@ const coordnames = IdDict{Symbol, Vector{Union{Symbol, Nothing}}}(
nameof(Sphere) => [:rₛ, :sₛ, :xₛ, :yₛ, :zₛ]
)
coordname(elt::Element, index) = coordnames[nameof(typeof(elt))][index]
coordname(elem::Element, index) = coordnames[nameof(typeof(elem))][index]
function pushcoordname!(coordnamelist, indexed_elt::Tuple{Any, Element}, coordindex)
eltindex, elt = indexed_elt
name = coordname(elt, coordindex)
function pushcoordname!(coordnamelist, indexed_elem::Tuple{Any, Element}, coordindex)
elemindex, elem = indexed_elem
name = coordname(elem, coordindex)
if !isnothing(name)
subscript = Subscripts.sub(string(eltindex))
subscript = Subscripts.sub(string(elemindex))
push!(coordnamelist, Symbol(name, subscript))
end
end
function takecoord!(coordlist, indexed_elt::Tuple{Any, Element}, coordindex)
elt = indexed_elt[2]
if !isnothing(coordname(elt, coordindex))
push!(elt.coords, popfirst!(coordlist))
function takecoord!(coordlist, indexed_elem::Tuple{Any, Element}, coordindex)
elem = indexed_elem[2]
if !isnothing(coordname(elem, coordindex))
push!(elem.coords, popfirst!(coordlist))
end
end
@ -132,12 +132,12 @@ mutable struct Construction{T}
end
end
function Base.push!(ctx::Construction{T}, elt::Point{T}) where T
push!(ctx.points, elt)
function Base.push!(ctx::Construction{T}, elem::Point{T}) where T
push!(ctx.points, elem)
end
function Base.push!(ctx::Construction{T}, elt::Sphere{T}) where T
push!(ctx.spheres, elt)
function Base.push!(ctx::Construction{T}, elem::Sphere{T}) where T
push!(ctx.spheres, elem)
end
function Base.push!(ctx::Construction{T}, rel::Relation{T}) where T
@ -150,10 +150,10 @@ end
function realize(ctx::Construction{T}) where T
# collect coordinate names
coordnamelist = Symbol[]
eltenum = enumerate(Iterators.flatten((ctx.spheres, ctx.points)))
elemenum = enumerate(Iterators.flatten((ctx.spheres, ctx.points)))
for coordindex in 1:5
for indexed_elt in eltenum
pushcoordname!(coordnamelist, indexed_elt, coordindex)
for indexed_elem in elemenum
pushcoordname!(coordnamelist, indexed_elem, coordindex)
end
end
@ -161,34 +161,25 @@ function realize(ctx::Construction{T}) where T
coordring, coordqueue = polynomial_ring(parent_type(T)(), coordnamelist, ordering = :degrevlex)
# retrieve coordinates
for (_, elt) in eltenum
empty!(elt.coords)
for (_, elem) in elemenum
empty!(elem.coords)
end
for coordindex in 1:5
for indexed_elt in eltenum
takecoord!(coordqueue, indexed_elt, coordindex)
for indexed_elem in elemenum
takecoord!(coordqueue, indexed_elem, coordindex)
end
end
# construct coordinate vectors
for (_, elt) in eltenum
buildvec!(elt)
for (_, elem) in elemenum
buildvec!(elem)
end
# turn relations into equations
eqns = vcat(
equation.(ctx.relations),
[elt.rel for (_, elt) in eltenum if !isnothing(elt.rel)]
[elem.rel for (_, elem) in elemenum if !isnothing(elem.rel)]
)
# add relations to center and orient the construction
if !isempty(ctx.points)
append!(eqns, [sum(pt.coords[k] for pt in ctx.points) for k in 1:3])
end
if !isempty(ctx.spheres)
append!(eqns, [sum(sph.coords[k] for sph in ctx.spheres) for k in 3:4])
end
Generic.Ideal(coordring, eqns)
end