Compare commits
2 Commits
a3f3f6a31b
...
43cbf8a3a0
Author | SHA1 | Date | |
---|---|---|---|
|
43cbf8a3a0 | ||
|
21f09c4a4d |
@ -72,21 +72,21 @@ const coordnames = IdDict{Symbol, Vector{Union{Symbol, Nothing}}}(
|
||||
nameof(Sphere) => [:rₛ, :sₛ, :xₛ, :yₛ, :zₛ]
|
||||
)
|
||||
|
||||
coordname(elem::Element, index) = coordnames[nameof(typeof(elem))][index]
|
||||
coordname(elt::Element, index) = coordnames[nameof(typeof(elt))][index]
|
||||
|
||||
function pushcoordname!(coordnamelist, indexed_elem::Tuple{Any, Element}, coordindex)
|
||||
elemindex, elem = indexed_elem
|
||||
name = coordname(elem, coordindex)
|
||||
function pushcoordname!(coordnamelist, indexed_elt::Tuple{Any, Element}, coordindex)
|
||||
eltindex, elt = indexed_elt
|
||||
name = coordname(elt, coordindex)
|
||||
if !isnothing(name)
|
||||
subscript = Subscripts.sub(string(elemindex))
|
||||
subscript = Subscripts.sub(string(eltindex))
|
||||
push!(coordnamelist, Symbol(name, subscript))
|
||||
end
|
||||
end
|
||||
|
||||
function takecoord!(coordlist, indexed_elem::Tuple{Any, Element}, coordindex)
|
||||
elem = indexed_elem[2]
|
||||
if !isnothing(coordname(elem, coordindex))
|
||||
push!(elem.coords, popfirst!(coordlist))
|
||||
function takecoord!(coordlist, indexed_elt::Tuple{Any, Element}, coordindex)
|
||||
elt = indexed_elt[2]
|
||||
if !isnothing(coordname(elt, coordindex))
|
||||
push!(elt.coords, popfirst!(coordlist))
|
||||
end
|
||||
end
|
||||
|
||||
@ -132,12 +132,12 @@ mutable struct Construction{T}
|
||||
end
|
||||
end
|
||||
|
||||
function Base.push!(ctx::Construction{T}, elem::Point{T}) where T
|
||||
push!(ctx.points, elem)
|
||||
function Base.push!(ctx::Construction{T}, elt::Point{T}) where T
|
||||
push!(ctx.points, elt)
|
||||
end
|
||||
|
||||
function Base.push!(ctx::Construction{T}, elem::Sphere{T}) where T
|
||||
push!(ctx.spheres, elem)
|
||||
function Base.push!(ctx::Construction{T}, elt::Sphere{T}) where T
|
||||
push!(ctx.spheres, elt)
|
||||
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[]
|
||||
elemenum = enumerate(Iterators.flatten((ctx.spheres, ctx.points)))
|
||||
eltenum = enumerate(Iterators.flatten((ctx.spheres, ctx.points)))
|
||||
for coordindex in 1:5
|
||||
for indexed_elem in elemenum
|
||||
pushcoordname!(coordnamelist, indexed_elem, coordindex)
|
||||
for indexed_elt in eltenum
|
||||
pushcoordname!(coordnamelist, indexed_elt, coordindex)
|
||||
end
|
||||
end
|
||||
|
||||
@ -161,25 +161,34 @@ function realize(ctx::Construction{T}) where T
|
||||
coordring, coordqueue = polynomial_ring(parent_type(T)(), coordnamelist, ordering = :degrevlex)
|
||||
|
||||
# retrieve coordinates
|
||||
for (_, elem) in elemenum
|
||||
empty!(elem.coords)
|
||||
for (_, elt) in eltenum
|
||||
empty!(elt.coords)
|
||||
end
|
||||
for coordindex in 1:5
|
||||
for indexed_elem in elemenum
|
||||
takecoord!(coordqueue, indexed_elem, coordindex)
|
||||
for indexed_elt in eltenum
|
||||
takecoord!(coordqueue, indexed_elt, coordindex)
|
||||
end
|
||||
end
|
||||
|
||||
# construct coordinate vectors
|
||||
for (_, elem) in elemenum
|
||||
buildvec!(elem)
|
||||
for (_, elt) in eltenum
|
||||
buildvec!(elt)
|
||||
end
|
||||
|
||||
# turn relations into equations
|
||||
eqns = vcat(
|
||||
equation.(ctx.relations),
|
||||
[elem.rel for (_, elem) in elemenum if !isnothing(elem.rel)]
|
||||
[elt.rel for (_, elt) in eltenum if !isnothing(elt.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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user