Freigeben über


Stroke class

Represents a concrete stroke object.

Constructors

Stroke(IStrokeCreationOptions)

Creates a new Stroke instance.

Properties

brush

Gets the stroke's brush.

clientId

Gets the id of the client the stroke was created on.

id

Gets the id of the stroke.

length

Gets the stroke's number of points.

timeStamp

Gets the time when the stroke was created.

Methods

addPoints(IPointerPoint[])

Adds the specified points to the stroke. Points are added if they are sufficiently far from each other.

clear()

CLears the stroke, i.e. removes all of its points.

deserialize(string)

Deserializes the specified stroke string and sets this stroke's brush, points and other proprties accordingly.

getAllPoints()

Gets a copy of all the points in the stroke.

getBoundingRect()

Computes the stroke's bounding rectangle. Once computed, the bounding rectangle is cached until new points are added to the stroke.

getIntersectionPoints(ISegment)

Computes the intersection points between the stroke and the specified segment.

getPointAt(number)

Gets the point at the given index.

intersectsWithRectangle(IRect)

Determines if the stroke intersects with the specified rectangle.

pointErase(IRect)

Splits this stroke into several other ones by "erasing" the portions that are within the eraser rectangle.

serialize()

Serializes the stroke to a string.

[iterator]()

Constructor Details

Stroke(IStrokeCreationOptions)

Creates a new Stroke instance.

new Stroke(options?: IStrokeCreationOptions)

Parameters

options
IStrokeCreationOptions

Optional creation options such as id, points, etc.

Property Details

brush

Gets the stroke's brush.

IBrush brush

Property Value

clientId

Gets the id of the client the stroke was created on.

undefined | string clientId

Property Value

undefined | string

id

Gets the id of the stroke.

string id

Property Value

string

length

Gets the stroke's number of points.

number length

Property Value

number

timeStamp

Gets the time when the stroke was created.

number timeStamp

Property Value

number

Method Details

addPoints(IPointerPoint[])

Adds the specified points to the stroke. Points are added if they are sufficiently far from each other.

function addPoints(points: IPointerPoint[]): boolean

Parameters

points

IPointerPoint[]

The points to add.

Returns

boolean

true if at least one point was added, false otherwise.

clear()

CLears the stroke, i.e. removes all of its points.

function clear()

deserialize(string)

Deserializes the specified stroke string and sets this stroke's brush, points and other proprties accordingly.

function deserialize(serializedStroke: string)

Parameters

serializedStroke

string

The serialized stroke.

getAllPoints()

Gets a copy of all the points in the stroke.

function getAllPoints(): IPointerPoint[]

Returns

A collection of points.

getBoundingRect()

Computes the stroke's bounding rectangle. Once computed, the bounding rectangle is cached until new points are added to the stroke.

function getBoundingRect(): IRect

Returns

The stroke's bounding rectangle.

getIntersectionPoints(ISegment)

Computes the intersection points between the stroke and the specified segment.

function getIntersectionPoints(segment: ISegment): IPoint[]

Parameters

segment
ISegment

The segment to test against.

Returns

IPoint[]

An array of intersection points.

getPointAt(number)

Gets the point at the given index.

function getPointAt(index: number): IPointerPoint

Parameters

index

number

The point index.

Returns

The requested point.

intersectsWithRectangle(IRect)

Determines if the stroke intersects with the specified rectangle.

function intersectsWithRectangle(rectangle: IRect): boolean

Parameters

rectangle
IRect

The rectangle to test against.

Returns

boolean

true if the stroke intersects with rectangle, false otherwise.

pointErase(IRect)

Splits this stroke into several other ones by "erasing" the portions that are within the eraser rectangle.

function pointErase(eraserRect: IRect): undefined | IStroke[]

Parameters

eraserRect
IRect

The eraser rectangle.

Returns

undefined | IStroke[]

An array of new strokes (which might be empty if the whole stroke was erased), or undefined if the stroke was unchanged.

serialize()

Serializes the stroke to a string.

function serialize(): string

Returns

string

The serialized stroke.

[iterator]()

function [iterator](): { next: () => { done: boolean, value: IPointerPoint } }

Returns

{ next: () => { done: boolean, value: IPointerPoint } }