Path¶
Under Construction
This documentation is auto-generated, and is a work in progress. Please see the source code at https://github.com/phetsims/scenery/blob/main/js/nodes/Path.ts for the most up-to-date information.
Overview¶
A Path draws a Shape with a specific type of fill and stroke. Mixes in Paintable.
@author Jonathan Olson <jonathan.olson@colorado.edu>
Class Path¶
Constructor¶
new Path( shape : InputShape | TReadOnlyProperty<InputShape>, providedOptions? : PathOptions )¶
Instance Methods¶
setShape( shape : InputShape ) : this¶
getShape() : ParsedShape¶
Returns the shape that was set for this Path (or for subtypes like Line and Rectangle, will return an immutable Shape that is equivalent in appearance).
It is best to generally assume modifications to the Shape returned is not supported. If there is no shape currently, null will be returned.
setShapeProperty( newTarget : TReadOnlyProperty<InputShape> | null ) : this¶
See documentation for Node.setVisibleProperty, except this is for the shape
getShapeProperty() : TProperty<InputShape>¶
Like Node.getVisibleProperty(), but for the shape. Note this is not the same as the Property provided in setShapeProperty. Thus is the nature of TinyForwardingProperty.
getStrokedShape() : Shape¶
Returns a lazily-created Shape that has the appearance of the Path's shape but stroked using the current stroke style of the Path.
NOTE: It is invalid to call this on a Path that does not currently have a Shape (usually a Path where the shape is set to null).
getPathRendererBitmask() : number¶
(protected)
Returns a bitmask representing the supported renderers for the current configuration of the Path or subtype.
Should be overridden by subtypes to either extend or restrict renderers, depending on what renderers are supported.
@returns - A bitmask that includes supported renderers, see Renderer for details.
invalidateSupportedRenderers()¶
Triggers a check and update for what renderers the current configuration of this Path or subtype supports. This should be called whenever something that could potentially change supported renderers happen (which can be the shape, properties of the strokes or fills, etc.)
invalidatePath()¶
(protected)
Invalidates the node's self-bounds and any other recorded metadata about the outline or bounds of the Shape.
This is meant to be used for all Path subtypes (unlike invalidateShape).
updateSelfBounds() : boolean¶
(protected)
Computes a more efficient selfBounds for our Path.
@returns - Whether the self bounds changed.
setBoundsMethod( boundsMethod : PathBoundsMethod ) : this¶
getBoundsMethod() : PathBoundsMethod¶
Returns the current bounds method. See setBoundsMethod for details.
computeShapeBounds() : Bounds2¶
Computes the bounds of the Path (or subtype when overridden). Meant to be overridden in subtypes for more efficient bounds computations (but this will work as a fallback). Includes the stroked region if there is a stroke applied to the Path.
areSelfBoundsValid() : boolean¶
Whether this Node's selfBounds are considered to be valid (always containing the displayed self content of this node). Meant to be overridden in subtypes when this can change (e.g. Text).
If this value would potentially change, please trigger the event 'selfBoundsValid'.
getTransformedSelfBounds( matrix : Matrix3 ) : Bounds2¶
Returns our self bounds when our rendered self is transformed by the matrix.
getTransformedSafeSelfBounds( matrix : Matrix3 ) : Bounds2¶
Returns our safe self bounds when our rendered self is transformed by the matrix.
hasShape() : boolean¶
Returns whether this Path has an associated Shape (instead of no shape, represented by null)
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.
isPainted() : boolean¶
Whether this Node itself is painted (displays something itself).
containsPointSelf( point : Vector2 ) : boolean¶
Computes whether the provided point is "inside" (contained) in this Path's self content, or "outside".
@param point - Considered to be in the local coordinate frame
getSelfShape() : Shape¶
Returns a Shape that represents the area covered by containsPointSelf.
intersectsBoundsSelf( bounds : Bounds2 ) : boolean¶
Returns whether this Path's selfBounds is intersected by the specified bounds.
@param bounds - Bounds to test, assumed to be in the local coordinate frame.
dispose()¶
Disposes the path, releasing shape listeners if needed (and preventing new listeners from being added).
mutate( options? : PathOptions ) : this¶
Static Properties¶
DEFAULT_PATH_OPTIONS¶
(readonly)
Initial values for most Node mutator options
Type InputShape¶
The valid parameter types are: - Shape: (from Kite), normally used. - string: Uses the SVG Path format, see https://www.w3.org/TR/SVG/paths.html (the PATH part of <path d="PATH"/>). This will immediately be converted to a Shape object when set, and getShape() or equivalents will return the parsed Shape instance instead of the original string. See "ParsedShape" - null: Indicates that there is no Shape, and nothing is drawn. Usually used as a placeholder.
NOTE: Be aware of the potential for memory leaks. If a Shape is not marked as immutable (with makeImmutable()), Path will add a listener so that it is updated when the Shape itself changes. If there is a listener added, keeping a reference to the Shape will also keep a reference to the Path object (and thus whatever Nodes are connected to the Path). For now, set path.shape = null if you need to release the reference that the Shape would have, or call dispose() on the Path if it is not needed anymore.
Shape | string | null
Type PathBoundsMethod¶
"accurate" | "unstroked" | "tightPadding" | "safePadding" | "none"
Type PathOptions¶
- shape?: InputShape
This sets the shape of the Path, which determines the shape of its appearance. It should generally not be called on Path subtypes like Line, Rectangle, etc. See InputShape for details about what to provide for the shape.
NOTE: When you create a Path with a shape in the constructor, this setter will be called (don't overload the option). - shapeProperty?: TReadOnlyProperty<InputShape>
Similar to shape
, but allows setting the shape as a Property. - boundsMethod?: PathBoundsMethod
Sets the bounds method for the Path. This determines how our (self) bounds are computed, and can particularly determine how expensive to compute our bounds are if we have a stroke.
There are the following options: - 'accurate' - Always uses the most accurate way of getting bounds. Computes the exact stroked bounds. - 'unstroked' - Ignores any stroke, just gives the filled bounds. If there is a stroke, the bounds will be marked as inaccurate - 'tightPadding' - Pads the filled bounds by enough to cover everything except mitered joints. If there is a stroke, the bounds wil be marked as inaccurate. - 'safePadding' - Pads the filled bounds by enough to cover all line joins/caps. - 'none' - Returns Bounds2.NOTHING. The bounds will be marked as inaccurate. NOTE: It's important to provide a localBounds override if you use this option, so its bounds cover the Path's shape. (path.localBounds = ...) - & PaintableOptions & NodeOptions