You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB
Kotlin

package me.eater.threedom.dom
import org.joml.Matrix4d
import org.joml.Vector3d
import java.util.concurrent.atomic.AtomicLong
interface INode<T : INode<T>> : Comparable<INode<*>>, INodeContainer {
var id: String?
val classList: MutableSet<String>
val nodeId: Long
val parentNode: INode<*>?
val document: IDocument?
val absolute: Matrix4d
get() = (parentNode?.absolute ?: Matrix4d()).mul(model)
var model: Matrix4d
fun clone(deep: Boolean): T
fun updateParent(refNode: INode<*>?): Boolean
fun detachFromDocument()
fun hasParent(node: INode<*>): Boolean {
var current: INode<*>? = parentNode;
while (current != null) {
if (node.nodeId == current.nodeId) {
return true
}
current = current.parentNode
}
return false
}
override fun compareTo(other: INode<*>): Int = this.nodeId.compareTo(other.nodeId)
companion object {
private val atomicNodeId = AtomicLong(0)
fun getNextNodeId() = atomicNodeId.getAndIncrement()
}
}