UNPKG

gl2d

Version:

2D graphics package for WebGL

71 lines (70 loc) 3.08 kB
import { Mat2d, Mat2dStruct, ScaleToFit } from '../struct/mat2d'; import { Point, PointLike } from '../struct/point'; import { Rect } from '../struct/rect'; import { VertexBuffer } from '../struct/vertex'; import { Graphic } from './graphic'; import { Mesh } from './mesh'; /** * Shape defined by matrix transformation of a mesh. */ export declare class Shape extends Graphic { /** * Holds the static vertex and index data for this shape. * The data must be loaded into WebGL in order to draw this shape. */ mesh: Mesh; /** * Creates a shape with the specified mesh data and initial transformation matrix. * @param mesh the static vertex and index data data for this shape. * @param matrix the initial transformation matrix. Defaults to identiy. */ constructor(mesh: Mesh, matrix?: Mat2dStruct); /** * Measures the boundaries of this shape in world space. * @returns the boundaries of this shape, or null if the shape has no vertices. */ measureBoundaries(): Rect; /** * Measures the boundaries of a shape in world space. * @param matrix the matrix that maps the shape to world space. * @param vertices the vertices of the shape in model space. * @returns the boundaries of the shape, or null if the shape has no vertices. */ static measureBoundaries(matrix: Mat2d, vertices: VertexBuffer): Rect; /** * Measures the position of this shape's control point in world space. * @returns the position of the control point in world space. */ measureControl(): Point; /** * Measures the position of this shape's fixed point in world space. * @returns the position of the fixed point in world space. */ measurePivot(): Point; /** * Measures the position of the specified vertex in world space. * @param index the index of the vertex in the buffer associated with this shape's mesh. * @returns the position of the vertex in world space, or null if no vertex exists at the specified position. */ measureVertex(index: number): Point; /** * Checks if this shape contains the specified point. * @param point the point to check. * @param inverse the inverse of this shape's model matrix. If undefined, the inverse matrix will be calculated on the fly. */ contains(pt: PointLike, inverse?: Mat2d): boolean; /** * Maps this shape to the destination Rect using the specified scale to fit option. * @param dst the destination rectangle. * @param stf the scale to fit option. Defaults to Fill. */ mapToRect(dst: Rect, stf?: ScaleToFit): void; /** * Stretch-rotates this shape across the line from p1 to p2. */ stretchAcrossLine(p1: PointLike, p2: PointLike): void; /** * Sets the specified matrix to stretch rotate the specified mesh across the line from p1 to p2. */ static stretchAcrossLine(matrix: Mat2d, mesh: Mesh, p1: PointLike, p2: PointLike): void; }