All files / app/codeCharta/ui/codeMap/rendering codeMapBuilding.ts

97.36% Statements 37/38
100% Branches 3/3
95% Functions 19/20
97.36% Lines 37/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118  76x 76x   76x                     495x 495x 495x 495x 495x 495x 495x       1x               13x   13x 13x         26x 26x 26x 16x   10x   26x       142x       7x       141x       6x       1x 1x       17x       333x       2x       4x       329x       4x               6x       1x       14x 14x       3x      
import { Node } from "../../../codeCharta.model"
import { Box3, Vector3 } from "three"
import { ColorConverter } from "../../../util/color/colorConverter"
 
export class CodeMapBuilding {
    private readonly _id: number
    private _boundingBox: Box3
    private _color: string
    private _defaultColor: string
    private _deltaColor: string
    private _defaultDeltaColor: string
    private _node: Node
    parent: CodeMapBuilding
 
    constructor(id: number, box: Box3, node: Node, color: string) {
        this._id = id
        this._boundingBox = box
        this._color = color
        this._defaultColor = color
        this._deltaColor = "#000000"
        this._defaultDeltaColor = "#000000"
        this._node = node
    }
 
    getCenterPoint(mapSize: number) {
        return new Vector3(
            this._node.x0 - mapSize + this._node.width / 2,
            this._node.z0 + this._node.height,
            this._node.y0 - mapSize + this._node.length / 2
        )
    }
 
    decreaseLightness(value: number) {
        this._color = this._decreaseLightnessForColor(this._defaultColor, value)
 
        if (this._node.deltas) {
            this._deltaColor = this._decreaseLightnessForColor(this._defaultDeltaColor, value)
        }
    }
 
    private _decreaseLightnessForColor(color: string, value: number) {
        const colorHSL = ColorConverter.hexToHSL(color)
        colorHSL.decreaseLightness(value)
        if (colorHSL.getLightness() < 10) {
            colorHSL.setLightness(10)
        } else {
            colorHSL.setLightness(colorHSL.getLightness())
        }
        return colorHSL.toHex()
    }
 
    getColorVector() {
        return ColorConverter.getVector3(this._color)
    }
 
    getDefaultColorVector() {
        return ColorConverter.getVector3(this._defaultColor)
    }
 
    getDeltaColorVector() {
        return ColorConverter.getVector3(this._deltaColor)
    }
 
    getDefaultDeltaColorVector() {
        return ColorConverter.getVector3(this._defaultDeltaColor)
    }
 
    resetColor() {
        this._color = this._defaultColor
        this._deltaColor = this._defaultDeltaColor
    }
 
    equals(building: CodeMapBuilding) {
        return this._id === building._id
    }
 
    get id() {
        return this._id
    }
 
    get boundingBox() {
        return this._boundingBox
    }
 
    get color() {
        return this._color
    }
 
    get node() {
        return this._node
    }
 
    get deltaColor() {
        return this._deltaColor
    }
 
    get defaultDeltaColor() {
        return this._defaultDeltaColor
    }
 
    setColor(color: string) {
        this._color = color
    }
 
    setNode(node: Node) {
        this._node = node
    }
 
    setInitialDeltaColor(color: string) {
        this._defaultDeltaColor = color
        this._deltaColor = color
    }
 
    setDeltaColor(color: string) {
        this._deltaColor = color
    }
}