How to use the @here/harp-utils.assert function in @here/harp-utils

To help you get started, we’ve selected a few @here/harp-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heremaps / harp.gl / @here / harp-mapview / lib / text / TextElementsRenderer.ts View on Github external
private initializeGlyphs(
        textElement: TextElement,
        textElementStyle: TextElementStyle,
        tempParams: TempParams
    ): boolean {
        // Trigger the glyph load if needed.
        if (textElement.loadingState === LoadingState.Initialized) {
            return true;
        }

        assert(textElementStyle.textCanvas !== undefined);
        const textCanvas = textElementStyle.textCanvas!;

        if (textElement.loadingState === undefined) {
            textElement.loadingState = LoadingState.Requested;

            if (textElement.renderStyle === undefined) {
                textElement.renderStyle = new TextRenderStyle({
                    ...textElementStyle.renderParams,
                    ...textElement.renderParams
                });
            }
            if (textElement.layoutStyle === undefined) {
                textElement.layoutStyle = new TextLayoutStyle({
                    ...textElementStyle.layoutParams,
                    ...textElement.layoutParams
                });
github heremaps / harp.gl / @here / harp-mapview / lib / text / TextElementsRenderer.ts View on Github external
private placeTextElementGroup(
        groupState: TextElementGroupState,
        renderParams: RenderParams,
        maxNumPlacedLabels: number,
        pass: Pass
    ): boolean {
        // Unvisited text elements are never placed.
        assert(groupState.visited);

        if (this.m_textRenderers.length === 0) {
            logger.warn("No text renderers initialized.");
            return false;
        }

        const shieldGroups: number[][] = [];

        const temp: TempParams = {
            additionParams: {},
            poiMeasurementParams: {},
            measurementParams: {},
            bufferAdditionParams: {}
        };
        const hiddenKinds = this.m_viewState.hiddenGeometryKinds;
github heremaps / harp.gl / @here / harp-mapview / lib / poi / PoiRenderer.ts View on Github external
private setupPoiInfo(
        poiInfo: PoiInfo,
        imageTexture: ImageTexture,
        imageItem: ImageItem,
        zoomLevel: number
    ) {
        assert(poiInfo.uvBox === undefined);

        if (imageItem === undefined || imageItem.imageData === undefined) {
            logger.error("setupPoiInfo: No imageItem/imageData found");
            // invalid render batch number
            poiInfo.poiRenderBatch = INVALID_RENDER_BATCH;
            poiInfo.isValid = false;
            return;
        }

        const technique = poiInfo.technique;

        const imageWidth = imageItem.imageData.width;
        const imageHeight = imageItem.imageData.height;

        const iconWidth = imageTexture.width !== undefined ? imageTexture.width : imageWidth;
        const iconHeight = imageTexture.height !== undefined ? imageTexture.height : imageHeight;
github heremaps / harp.gl / @here / harp-mapview / lib / text / TextElementsRenderer.ts View on Github external
get priority() {
        assert(this.lists.length > 0);
        // All text element lists here have the same priority.
        return this.lists[0].group.priority;
    }
    /**
github heremaps / harp.gl / @here / harp-mapview / lib / geometry / TileDataAccessor.ts View on Github external
featureIndex < starts.length - 1
                    ? starts[featureIndex + 1]
                    : geometryAccessor.getCount();

            // setup/update the accessor for the new range of the object
            geometryAccessor.setRange(featureStart, featureEnd);

            switch (geometryType) {
                case GeometryType.Point:
                case GeometryType.Text:
                    this.visitor.visitPoint(featureId);
                    break;
                case GeometryType.SolidLine:
                case GeometryType.ExtrudedLine:
                case GeometryType.TextPath:
                    assert(isLineAccessor(geometryAccessor));
                    this.visitor.visitLine(featureId, (geometryAccessor as any) as ILineAccessor);
                    break;
                case GeometryType.Polygon:
                case GeometryType.ExtrudedPolygon:
                    this.visitor.visitArea(featureId);
                    break;
                case GeometryType.Object3D:
                    assert(isObject3dAccessor(geometryAccessor));
                    this.visitor.visitObject3D(
                        featureId,
                        (geometryAccessor as any) as IObject3dAccessor
                    );
                    break;
                default:
                    logger.warn("#visitObject: invalid geometryType");
            }
github heremaps / harp.gl / @here / harp-mapview / lib / text / TextElementsRenderer.ts View on Github external
private addPointLabel(
        labelState: TextElementState,
        position: THREE.Vector3,
        screenPosition: THREE.Vector2,
        poiRenderer: PoiRenderer,
        textCanvas: TextCanvas,
        renderParams: RenderParams,
        temp: TempParams,
        iconIndex?: number
    ): boolean {
        const pointLabel: TextElement = labelState.element;
        const textRenderState: RenderState | undefined = labelState.textRenderState;

        assert(iconIndex === undefined || labelState.iconRenderStates !== undefined);
        const iconRenderState: RenderState =
            iconIndex !== undefined
                ? labelState.iconRenderStates![iconIndex]
                : labelState.iconRenderState!;
        assert(iconRenderState !== undefined);

        const poiTextMaxDistance = getMaxViewDistance(
            this.m_viewState,
            this.m_options.maxDistanceRatioForPoiLabels!
        );
        const hasText = textRenderState !== undefined && pointLabel.text !== "";

        // Find the label's original position.
        tempScreenPosition.x = tempPoiScreenPosition.x = screenPosition.x;
        tempScreenPosition.y = tempPoiScreenPosition.y = screenPosition.y;
github heremaps / harp.gl / @here / harp-datasource-protocol / lib / TileInfo.ts View on Github external
getPoints(
        ringIndex: number
    ): {
        points: ArrayLike;
        pointsStart: number;
        numPointValues: number;
    } {
        assert(ringIndex >= 0);
        assert(ringIndex < this.numRings);
        assert(this.polygons !== undefined);
        if (ringIndex < 0 || ringIndex >= this.numRings || this.polygons === undefined) {
            throw new Error("ExtendedTileInfoPolygonAccessor: Invalid ring index");
        }

        // compute the start/size of the points in this ring. All `points` are actually just the
        // indices of a single X/Y coordinate.
        const pointsStart = this.polygons.innerRingStartIndex[this.ringStart + ringIndex];

        let numPointValues: number;
        if (ringIndex < this.numRings - 1) {
            numPointValues =
                this.polygons.innerRingStartIndex[this.ringStart + ringIndex + 1] - pointsStart;
        } else {
            if (this.ringStart + ringIndex < this.polygons.innerRingStartIndex.length - 1) {
                numPointValues =
github heremaps / harp.gl / @here / harp-lrucache / lib / LRUCache.ts View on Github external
itemToRemove.newer.older = null;
            }
        } else {
            if (itemToRemove.newer !== null) {
                assert(itemToRemove.newer.older === itemToRemove);
                itemToRemove.newer.older = itemToRemove.older;
                if (itemToRemove.older !== null) {
                    itemToRemove.older.newer = itemToRemove.newer;
                }
            } else {
                return undefined;
            }
        }

        const isOk = this.m_map.delete(itemToRemove.key);
        assert(isOk === true);
        if (isOk && this.evictionCallback !== undefined) {
            this.evictionCallback(itemToRemove.key, itemToRemove.value);
        }
        this.m_size -= itemToRemove.size;
        return itemToRemove;
    }
github heremaps / harp.gl / @here / harp-examples / lib / PerformanceUtils.ts View on Github external
export async function measureFlyoverSpline(
        mapViewApp: MapViewApp,
        _locationName: string,
        spline: PerformanceTestData.FlyOverConfiguration,
        numFramesOverride: number | undefined,
        verifyLoaded: boolean,
        use2D: boolean,
        showLabels: boolean,
        laps: number = 1,
        isCancelled?: () => boolean
    ): Promise {
        assert(
            spline.controlPoints.length / 2 === spline.zoomLevels.length,
            "Control points and zoom levels must have same number of entries"
        );
        assert(
            spline.controlPoints.length / 2 === spline.tilts.length,
            "Control points and tilts must have same number of entries"
        );

        applyDataFilter(mapViewApp.mapView, showLabels);

        return new Promise((resolve, reject) => {
            const numberOfDrawPoints =
                numFramesOverride !== undefined ? numFramesOverride : spline.numberOfDrawPoints;
            const segments = Math.ceil(numberOfDrawPoints / (spline.controlPoints.length / 2 - 1));

            const controlPoints: THREE.Vector2[] = [];
            for (let j = 0; j < spline.controlPoints.length / 2; j++) {
                controlPoints.push(
                    new THREE.Vector2(spline.controlPoints[j * 2], spline.controlPoints[j * 2 + 1])
                );