package me.eater.test.threedom.dom import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldHaveSingleElement import io.kotest.matchers.shouldBe import me.eater.threedom.dom.Document import me.eater.threedom.dom.IDocument import me.eater.threedom.dom.PlainNode import me.eater.threedom.dom.createNode import me.eater.threedom.utils.joml.Vector3d import me.eater.threedom.utils.joml.getTranslation import me.eater.threedom.utils.joml.setTranslation class PositionTest : StringSpec({ "ensure positioning works" { val doc: IDocument = Document() val node = doc.createNode() doc.addNode(node) node.model { setTranslation(10, 0, 10) } node.absolute.getTranslation() shouldBe Vector3d(10, 0, 10) val nodeTwo = doc.createNode() node.addNode(nodeTwo) nodeTwo.model { setTranslation(-10, 20, 0) } nodeTwo.absolute.getTranslation() shouldBe Vector3d(0, 20, 10) doc.addNode(nodeTwo) nodeTwo.absolute.getTranslation() shouldBe Vector3d(-10, 20, 0) } "ensure position search tree works" { val doc: IDocument = Document() val node = doc.createNode() val nodeTwo = doc.createNode() val nodeThree = doc.createNode() doc.addNode(node) node.addNode(nodeTwo) nodeTwo.addNode(nodeThree) node.model { setTranslation(10, 0, 10) } nodeTwo.model { setTranslation(-10, 20, 0) } nodeThree.model { setTranslation(0, 20, 0) } doc.findAt(10, 0, 10) shouldHaveSingleElement node doc.findAt(0, 20, 10) shouldHaveSingleElement nodeTwo doc.findAt(0, 40, 10) shouldHaveSingleElement nodeThree doc.rebalance() doc.findAt(10, 0, 10) shouldHaveSingleElement node doc.findAt(0, 20, 10) shouldHaveSingleElement nodeTwo doc.findAt(0, 40, 10) shouldHaveSingleElement nodeThree doc.addNode(nodeTwo) doc.findAt(-10, 20, 0) shouldHaveSingleElement nodeTwo doc.findAt(-10, 40, 0) shouldHaveSingleElement nodeThree } })