dyna3/engine-proto/engine.jl

34 lines
607 B
Julia

module Engine
export Construction, Sphere, mprod, point
using LinearAlgebra
using Groebner
mutable struct Construction
nextid::Int64
Construction(; nextid = 0) = new(nextid)
end
struct Sphere{T<:Number}
vec::Vector{T}
id
function Sphere(vec::Vector{T}, ctx::Construction) where T <: Number
id = ctx.nextid
ctx.nextid += 1
new{T}(vec, id)
end
end
function mprod(sv::Sphere, sw::Sphere)
v = sv.vec
w = sw.vec
v[1]*w[2] + v[2]*w[1] - dot(v[3:end], w[3:end])
end
point(pt::Vector{<:Number}, ctx::Construction) =
Sphere([one(eltype(pt)), dot(pt, pt), pt...], ctx)
end