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.

94 lines
2.0 KiB
Kotlin

4 years ago
package me.eater.threedom.dom
4 years ago
import me.eater.threedom.utils.joml.times
4 years ago
import org.joml.Matrix4d
4 years ago
import org.joml.Matrix4dc
4 years ago
import java.util.concurrent.atomic.AtomicLong
interface INode<T : INode<T>> : Comparable<INode<*>>, INodeContainer {
4 years ago
/**
* The ID of this node
*/
4 years ago
var id: String?
4 years ago
/**
* Set with all class names assigned to this node
*/
4 years ago
val classList: MutableSet<String>
4 years ago
/**
* Internal ID of this node, should be unique inside document
*/
4 years ago
val nodeId: Long
4 years ago
/**
* Parent of this node
*/
4 years ago
val parentNode: INode<*>?
4 years ago
/**
* Document this node belongs to
*/
4 years ago
val document: IDocument?
4 years ago
/**
* Absolute matrix relative to document
*/
4 years ago
val absolute: Matrix4dc
get() = (parentNode?.absolute ?: Matrix4d()) * model
4 years ago
4 years ago
/**
* model matrix relative to parent node
*/
4 years ago
var model: Matrix4dc
4 years ago
4 years ago
/**
* Clone this node
*
* @param deep also clone all child nodes
*/
4 years ago
fun clone(deep: Boolean): T
4 years ago
/**
* Update the parent of this node, for consistency purposes.
*
* @internal
*/
4 years ago
fun updateParent(refNode: INode<*>?): Boolean
4 years ago
/**
* Detach this node from the owner document
*/
4 years ago
fun detachFromDocument()
4 years ago
/**
* Check if [node] is parent or grand-parent of this node
*/
4 years ago
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)
4 years ago
/**
* Update the absolute position of this node
* @internal
*/
4 years ago
fun updateAbsolute()
4 years ago
companion object {
private val atomicNodeId = AtomicLong(0)
fun getNextNodeId() = atomicNodeId.getAndIncrement()
}
}