Skip to content

Commit

Permalink
Update tests for new label-line behaviour #1716
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanenkoVladimir committed Apr 22, 2021
1 parent 02a7c9e commit cdcf84d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { setIdToNode } from "../../state/store/lookUp/idToNode/idToNode.actions"
import { klona } from "klona"
import { CodeMapLabelService } from "./codeMap.label.service"
import { CodeMapMesh } from "./rendering/codeMapMesh"
import { Material, Object3D, Raycaster, Vector3 } from "three"
import {Geometry, Material, Object3D, Raycaster, Vector3} from "three"
import { CodeMapPreRenderService } from "./codeMap.preRender.service"
import { LazyLoader } from "../../util/lazyLoader"

Expand Down Expand Up @@ -352,15 +352,19 @@ describe("codeMapMouseEventService", () => {
const resultPosition = new Vector3(0.5, 0.5, 0)

const labels = []
const labelLine = new Object3D()
const placeholderLine = new Object3D()
const labelNode = new Object3D()
label["material"] = new Material()
const rayCaster = new Raycaster(new Vector3(10, 10, 0), new Vector3(1, 1, 1))

labelNode.translateX(-4)
labelNode.translateY(5)

labels.push(label, labelLine, labelNode, labelLine)
const lineGeometry = new Geometry()
lineGeometry.vertices.push(new Vector3(2,2,2), new Vector3(1,1,1))
placeholderLine["geometry"] = lineGeometry

labels.push(label, placeholderLine, labelNode, placeholderLine)

threeSceneService.animateLabel(label, rayCaster, labels)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CodeMapNode } from "../../../codeCharta.model"
import { setIdToBuilding } from "../../../state/store/lookUp/idToBuilding/idToBuilding.actions"
import { setIdToNode } from "../../../state/store/lookUp/idToNode/idToNode.actions"
import { setScaling } from "../../../state/store/appSettings/scaling/scaling.actions"
import { Box3, Matrix4, Object3D, Raycaster, Vector3 } from "three"
import {Box3, Geometry, Matrix4, Object3D, Raycaster, Vector3} from "three"

describe("ThreeSceneService", () => {
let threeSceneService: ThreeSceneService
Expand Down Expand Up @@ -260,25 +260,30 @@ describe("ThreeSceneService", () => {

describe("animateLabel", () => {
let labels = null
let labelLine = null
let otherNode = null
let label = null
let rayCaster = null
let placeholderLine = null
let lineGeometry = null

beforeEach(() => {
labels = []
labelLine = new Object3D()
otherNode = new Object3D()
label = new Object3D()
placeholderLine = new Object3D()
lineGeometry = new Geometry()

rayCaster = new Raycaster(new Vector3(10, 10, 0), new Vector3(1, 1, 1))
lineGeometry.vertices.push(new Vector3(2,2,2), new Vector3(1,1,1))
placeholderLine["geometry"] = lineGeometry
})

it("should animate the label by moving it 20% on the viewRay if it has no intersection", () => {
otherNode.translateX(-4)
otherNode.translateY(5)
const resultPosition = new Vector3(0.5, 0.5, 0)

labels.push(label, labelLine, otherNode, labelLine)
labels.push(label, placeholderLine, otherNode, placeholderLine)

threeSceneService.animateLabel(label, rayCaster, labels)
expect(threeSceneService["highlightedLabel"]).toEqual(label)
Expand All @@ -290,7 +295,7 @@ describe("ThreeSceneService", () => {

const resultPosition = new Vector3(0.5, 0.5, 0)

labels.push(label, labelLine, otherNode, labelLine)
labels.push(label, placeholderLine, otherNode, placeholderLine)

threeSceneService.animateLabel(label, rayCaster, labels)
expect(threeSceneService["highlightedLabel"]).toEqual(label)
Expand All @@ -303,7 +308,7 @@ describe("ThreeSceneService", () => {
unObstructingNode.applyMatrix4(new Matrix4().makeTranslation(0.5, 0.5, 0))

label.userData = CODE_MAP_BUILDING
labels.push(label, labelLine, otherNode, labelLine, unObstructingNode, labelLine)
labels.push(label, placeholderLine, otherNode, placeholderLine, unObstructingNode, placeholderLine)

threeSceneService.animateLabel(label, rayCaster, labels)
expect(threeSceneService["highlightedLabel"]).toEqual(label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class ThreeSceneService implements CodeMapPreRenderServiceSubscriber, Map

hoveredLabel.position.add(this.normedTransformVector)

this.animateLine(false, hoveredLabel)
this.toggleLineAnimation(false, hoveredLabel)

this.highlightedLabel = hoveredLabel
}
Expand All @@ -229,7 +229,7 @@ export class ThreeSceneService implements CodeMapPreRenderServiceSubscriber, Map

if(this.highlightedLineIndex > -1) {
this.labels.children.splice(this.highlightedLineIndex, 1)
this.animateLine(true)
this.toggleLineAnimation(true)
}

this.highlightedLabel = null
Expand All @@ -247,7 +247,7 @@ export class ThreeSceneService implements CodeMapPreRenderServiceSubscriber, Map

}

animateLine(reset: boolean, hoveredLabel? : Object3D){
toggleLineAnimation(reset: boolean, hoveredLabel? : Object3D){

const geometry = new Geometry()
const endPoint = reset ? new Vector3(this.highlightedLabel.position.x, this.highlightedLabel.position.y, this.highlightedLabel.position.z) : new Vector3(hoveredLabel.position.x, hoveredLabel.position.y, hoveredLabel.position.z)
Expand Down

0 comments on commit cdcf84d

Please sign in to comment.