UNPKG

@itwin/core-common

Version:

iTwin.js components common to frontend and backend

109 lines 4.45 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Geometry */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ImageGraphic = exports.ImageGraphicCorners = void 0; const core_geometry_1 = require("@itwin/core-geometry"); /** Defines the 4 corners of an [[ImageGraphic]]. The points are expected to lie in a single plane and define a (possibly-skewed) quadrilateral. * The points map to the corners of the image as follows: * ` * 3____2 * | | * |____| * 0 1 * ` * The image can be flipped and/or rotated by specifying the points in a different order. * @public */ class ImageGraphicCorners { 0; 1; 2; 3; constructor(p0, p1, p2, p3) { this[0] = p0; this[1] = p1; this[2] = p2; this[3] = p3; } static fromJSON(props) { return new ImageGraphicCorners(core_geometry_1.Point3d.fromJSON(props[0]), core_geometry_1.Point3d.fromJSON(props[1]), core_geometry_1.Point3d.fromJSON(props[2]), core_geometry_1.Point3d.fromJSON(props[3])); } static from4Points(points) { return new ImageGraphicCorners(points[0], points[1], points[2], points[3]); } clone() { return new ImageGraphicCorners(this[0].clone(), this[1].clone(), this[2].clone(), this[3].clone()); } toJSON() { return [this[0].toJSON(), this[1].toJSON(), this[2].toJSON(), this[3].toJSON()]; } } exports.ImageGraphicCorners = ImageGraphicCorners; /** A geometric primitive that displays an image mapped to the corners of a quadrilateral, with an optional border. * The image is always displayed regardless of [[RenderMode]] or [[ViewFlags]], and is displayed without lighting. * @public */ class ImageGraphic { /** The 4 corners of defining the quadrilateral on which the image is displayed. */ corners; /** The Id of the persistent [[Texture]] element defining the image to be displayed on the quadrilateral. */ textureId; /** Whether or not to draw a border around the image. */ hasBorder; /** Construct a new ImageGraphic. * @param corners Defines the 4 corners of the quadrilateral on which the image is to be displayed. The ImageGraphic takes ownership of this input. * @param textureId Identifies a persistent [[Texture]] element defining the image to be mapped onto the quadrilateral. * @param hasBorder Whether or not to display a border around the image. */ constructor(corners, textureId, hasBorder = false) { this.corners = corners; this.textureId = textureId; this.hasBorder = hasBorder; } static fromJSON(props) { const corners = ImageGraphicCorners.fromJSON(props.corners); return new ImageGraphic(corners, props.textureId, props.hasBorder); } clone() { return new ImageGraphic(this.corners.clone(), this.textureId, this.hasBorder); } cloneTransformed(transform) { const clone = this.clone(); clone.transformInPlace(transform); return clone; } toJSON() { return { corners: this.corners.toJSON(), textureId: this.textureId, hasBorder: this.hasBorder, }; } /** Computes and returns the range. * @param result If supplied, will be modified to hold the computed range and returned. * @returns The computed range. */ computeRange(result) { if (undefined === result) result = new core_geometry_1.Range3d(); else result.setNull(); result.extend(this.corners[0], this.corners[1], this.corners[2], this.corners[3]); return result; } /** Apply a transform to the corners of the quadrilateral. */ transformInPlace(transform) { transform.multiplyPoint3d(this.corners[0], this.corners[0]); transform.multiplyPoint3d(this.corners[1], this.corners[1]); transform.multiplyPoint3d(this.corners[2], this.corners[2]); transform.multiplyPoint3d(this.corners[3], this.corners[3]); } } exports.ImageGraphic = ImageGraphic; //# sourceMappingURL=ImageGraphic.js.map