# Class DynamicPolygon<Point>

Represents a dynamic polygon. It is possible to add, insert and remove points to it and have those changes reflect its 3D visualization. Useful for tools that need to calculate area.

#### Type Parameters

- Point extends DynamicPolygonPoint = DynamicPolygonPoint

  Defaults to DynamicPolygonPoint. However, a custom class can be specified which derives from DynamicPolygonPoint.

#### Implements

- DynamicPolygonPointParent<DynamicPolygonPoint>

##### Index

### Constructors

constructor

### Properties

_api
_onParentWorldMatrixUpdateObserver
dragPointPositioningFunction?
height
name
onAreaLabelTrackableScreen
onPointTrackableScreen

### Accessors

bottomArea
interiorPoint
isDisposed
isEmpty
isEnabled
mesh
parent
plane
surfaceArea
volume

### Methods

apply
assignNewPolygonPoints
build
clear
dispose
points
registerParentWorldMatrixCallback
transformAndValidatePoints
worldMatrix
validatePoints

## Constructors

### constructor

- new DynamicPolygon<Point extends DynamicPolygonPoint = DynamicPolygonPoint>(
  name: string,
  _api: BimCoreApi,
  pointFactory: DynamicPolygonPointFactoryHandler<Point>,
  recalculate2DEachFrame?: boolean,
  parent?: TransformNode,
  dragPointPositioningFunction?: DragPointPositioningFunction,
  ): DynamicPolygon<Point>

  Polygon constructor, counter-clockwise polygon winding order.

  #### Type Parameters

  - Point extends DynamicPolygonPoint = DynamicPolygonPoint

  #### Parameters

  - name: string

    Name of polyline

  - _api: BimCoreApi

    BimCoreApi instance

  - pointFactory: DynamicPolygonPointFactoryHandler<Point>

    Factory method which is used to create the instances of generic class type `Point`.

  - recalculate2DEachFrame: boolean = false

    If `true` then it updates the 2D positions for each tracked 3D coordinate at the end of each frame.

  - `Optional` parent: TransformNode

    If Babylon TransformNode is provided the dynamic polygon will attach as a child and follow its parent.

  - `Optional` dragPointPositioningFunction: DragPointPositioningFunction

    Function to calculate the drag points position in the polygon.

  #### Returns DynamicPolygon<Point>

## Properties

### `Protected` `Readonly`_api

_api: BimCoreApi

BimCoreApi instance

### `Protected`_onParentWorldMatrixUpdateObserver

_onParentWorldMatrixUpdateObserver: Nullable<Observer<TransformNode>>

### `Optional` dragPointPositioningFunction

dragPointPositioningFunction?: DragPointPositioningFunction

Function to calculate the drag points position in the polygon.

### height

height: number = 0

### `Readonly` name

name: string

Name of polyline

### `Readonly` onAreaLabelTrackableScreen

onAreaLabelTrackableScreen: Observable<TrackCoordinate2D<Vector3>>

Triggered when DynamicPolygon.apply is called or when camera moves around. By listening to this event it is possible to know when the area label X,Y position is updated (This always exists on a DynamicPolygon). It is also possible to see how far away the points are from the camera. What position they have in 2D space (perhaps one wants to add a HTML element to the DOM there.).

### `Readonly` onPointTrackableScreen

onPointTrackableScreen: Observable<TrackCoordinate2D<Point>>

Triggered when DynamicPolygon.apply is called or when camera moves around. By listening to this event, it is possible to know when new polygon points are added, updated and removed. It is also possible to see how far away the points are from the camera. And to see what position they have in 2D space (for example, to add a HTML element to the DOM).

## Accessors

### bottomArea

- get bottomArea(): number

  Polygon bottom area. Only updated when DynamicPolygon.apply or DynamicPolygon.build is called. Calculated with polygonArea function with a height of zero.

  #### Returns number

  The polygon bottom area.

### interiorPoint

- get interiorPoint(): Vertex3

  Interior point. Only updated when DynamicPolygon.apply or DynamicPolygon.build is called.

  #### Returns Vertex3

  The interior point.

### isDisposed

- get isDisposed(): boolean

  Whether or not the mesh is disposed or not.

  #### Returns boolean

  boolean.

### isEmpty

- get isEmpty(): boolean

  #### Returns boolean

  `true` if polygon has no points. Otherwise `false`.

### isEnabled

- get isEnabled(): boolean

  #### Returns boolean

  `true` if the dynamic polygon is enabled otherwise `false`.

  Implementation of DynamicPolygonPointParent.isEnabled

- set isEnabled(b: boolean): void

  Sets isEnabled on the dynamicpolygon and sets isEnabled on the polygon mesh if it has any points.

  #### Parameters

  - b: boolean

    state to set

  #### Returns void

  Implementation of DynamicPolygonPointParent.isEnabled

### mesh

- get mesh(): Mesh

  BabylonJS mesh.

  #### Returns Mesh

  mesh

### parent

- get parent(): undefined | TransformNode

  #### Returns undefined | TransformNode

- set parent(node: undefined | TransformNode): void

  Sets the parent of the DynamicPolygon without keeping the position in world space.

  #### Parameters

  - node: undefined | TransformNode

    new parent for the DynamicPolygon.

  #### Returns void

### plane

- get plane(): Plane

  Plane spanned by points. Only updated when DynamicPolygon.build or DynamicPolygon.assignNewPolygonPoints is called.

  #### Returns Plane

  The Plane.

### surfaceArea

- get surfaceArea(): number

  Polygon surface area. Only updated when DynamicPolygon.apply or DynamicPolygon.build is called.

  #### Returns number

  The polygon surface area.

### volume

- get volume(): number

  Polygon volume. Only updated when there exists a height and DynamicPolygon.apply or DynamicPolygon.build is called.

  #### Returns number

  The polygon volume.

## Methods

### apply

- apply(): void

  Applies changes to polygon which occurred when calling methods on DynamicPolygonPoint.move, DynamicPolygonPoint.virtual and DynamicPolygonPoint.delete. It will also trigger DynamicPolygon.onPointTrackableScreen events.

  #### Returns void

  Implementation of DynamicPolygonPointParent.apply

### assignNewPolygonPoints

- assignNewPolygonPoints(dynamicPolygonPoints: Point[]): void

  Assigns points to define the polygon, this method can be used instead of build which adds virtual points

  #### Parameters

  - dynamicPolygonPoints: Point[]

  #### Returns void

### build

- build(
  points: Vertex3[],
  transformPointsToLocal?: boolean,
  ): DynamicPolygonPointValidationResult

  Attempt to build a DynamicPolygon using the `points` parameter.

  #### Parameters

  - points: Vertex3[]

    Vertex3 points.

  - transformPointsToLocal: boolean = true

    Wheter to transform the points to the DynamicPolygon's parent local space before using them to build

  #### Returns DynamicPolygonPointValidationResult

  returns a DynamicPolygonPointValidationResult.

### clear

- clear(): void

  Clears the polygon of all current points

  #### Returns void

### dispose

- dispose(): void

  Disposes the DynamicPolygon. It is no longer useable after this call.

  #### Returns void

### points

- points(
  predicate?: (p: DynamicPolygonPoint) => boolean,
  backwards?: boolean,
  ): Generator<DynamicPolygonPoint, void, unknown>

  #### Parameters

  - `Optional` predicate: (p: DynamicPolygonPoint) => boolean
  - backwards: boolean = false

  #### Returns Generator<DynamicPolygonPoint, void, unknown>

### registerParentWorldMatrixCallback

- registerParentWorldMatrixCallback(): void

  #### Returns void

### transformAndValidatePoints

- transformAndValidatePoints(
  points: Vertex3[],
  transformPointsToLocal: boolean,
  ): DynamicPolygonPointValidationResult
  `Internal`

  If transformPointsToLocal is `true`, transforms all provided points according to this DynamicPolygon's parent. In either case, validate points and return the validation result

  #### Parameters

  - points: Vertex3[]

    The points to transform

  - transformPointsToLocal: boolean

    Whether to transform the points to the DynamicPolygon's parent local space before validating them

  #### Returns DynamicPolygonPointValidationResult

  The validation result NOTE: Internal API. Subject to change. Use of these APIs in production applications is not supported.

### worldMatrix

- worldMatrix(): Matrix

  Get the world matrix of this DynamicPolygon

  #### Returns Matrix

  the world matrix for this DynamicPolygon.

  Implementation of DynamicPolygonPointParent.worldMatrix

### `Static` validatePoints

- validatePoints(
  points: Vertex3[],
  minPoints?: number,
  ): DynamicPolygonPointValidationResult

  Validates the specified `points`.

  #### Parameters

  - points: Vertex3[]

    Vertex3 points.

  - minPoints: number = 3

  #### Returns DynamicPolygonPointValidationResult

  returns a DynamicPolygonPointValidationResult.