Skip to content

Line

Overview

Displays a (stroked) line. Inherits Path, and allows for optimized drawing and improved parameter handling.

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class Line

import { Line } from 'scenerystack/scenery';

Constructor

new Line( options? : LineOptions )

Instance Methods

setLine( x1 : number, y1 : number, x2 : number, y2 : number ) : this

Set all of the line's x and y values.

@param x1 - the start x coordinate @param y1 - the start y coordinate @param x2 - the end x coordinate @param y2 - the end y coordinate

setPoint1( p1 : Vector2 ) : this

Set the line's first point's x and y values

setPoint1( x1 : number, y1 : number ) : this

setPoint1( x1 : number | Vector2, y1? : number ) : this

setPoint2( p1 : Vector2 ) : this

Set the line's second point's x and y values

setPoint2( x2 : number, y2 : number ) : this

setPoint2( x2 : number | Vector2, y2? : number ) : this

setX1( x1 : number ) : this

Sets the x coordinate of the first point of the line.

getX1() : number

Returns the x coordinate of the first point of the line.

setY1( y1 : number ) : this

Sets the y coordinate of the first point of the line.

getY1() : number

Returns the y coordinate of the first point of the line.

setX2( x2 : number ) : this

Sets the x coordinate of the second point of the line.

getX2() : number

Returns the x coordinate of the second point of the line.

setY2( y2 : number ) : this

Sets the y coordinate of the second point of the line.

getY2() : number

Returns the y coordinate of the second point of the line.

containsPointSelf( point : Vector2 ) : boolean

Computes whether the provided point is "inside" (contained) in this Line's self content, or "outside".

Since an unstroked Line contains no area, we can quickly shortcut this operation.

@param point - Considered to be in the local coordinate frame

canvasPaintSelf( wrapper : CanvasContextWrapper, matrix : Matrix3 )

(protected)

Draws the current Node's self representation, assuming the wrapper's Canvas context is already in the local coordinate frame of this node.

@param wrapper @param matrix - The transformation matrix already applied to the context.

computeShapeBounds() : Bounds2

Computes the bounds of the Line, including any applied stroke. Overridden for efficiency.

createSVGDrawable( renderer : number, instance : Instance ) : SVGSelfDrawable

Creates a SVG drawable for this Line.

@param renderer - In the bitmask format specified by Renderer, which may contain additional bit flags. @param instance - Instance object that will be associated with the drawable

createCanvasDrawable( renderer : number, instance : Instance ) : CanvasSelfDrawable

Creates a Canvas drawable for this Line.

@param renderer - In the bitmask format specified by Renderer, which may contain additional bit flags. @param instance - Instance object that will be associated with the drawable

setShape( shape : Shape | null ) : this

It is impossible to set another shape on this Path subtype, as its effective shape is determined by other parameters.

Throws an error if it is not null.

getShape() : Shape

Returns an immutable copy of this Path subtype's representation.

NOTE: This is created lazily, so don't call it if you don't have to!

hasShape() : boolean

Returns whether this Path has an associated Shape (instead of no shape, represented by null)

setShapeProperty( newTarget : TReadOnlyProperty<Shape | string | null> | null ) : this

mutate( options? : LineOptions ) : this

Type LineOptions

import type { LineOptions } from 'scenerystack/scenery';
  • p1?: Vector2
  • p2?: Vector2
  • x1?: number
  • y1?: number
  • x2?: number
  • y2?: number
  • & StrictOmit<PathOptions, "shape" | "shapeProperty">

Source Code

See the source for Line.ts in the scenery repository.