Skip to main content

Square

Class representing a Square, extending the Rectangle class. Provides functionality for rendering, resizing, moving, and rotating the square.

Extends

Constructors

new Square()

new Square(x, y, size, rotation, style?, options?): Square

Constructs a new Square instance.

Parameters

x: number

The x-coordinate of the square's position.

y: number

The y-coordinate of the square's position.

size: number

The size (width/height) of the square.

rotation: number = 0

The initial rotation of the square in degrees clockwise.

style?: IRectangleStyle

The style options for the square.

options?: IRectangleOptions

The configuration options for the square.

Returns

Square

Overrides

Rectangle.constructor

Defined in

shapes/Square.ts:20

Properties

_definition

protected _definition: RectangleDefinition

The shape definition, proxied to trigger observer notifications on change.

Inherited from

Rectangle._definition

Defined in

shapes/Shape.ts:22


_options

protected _options: RectangleOptions

The options for configuring the shape, proxied to trigger observer notifications on change.

Inherited from

Rectangle._options

Defined in

shapes/Shape.ts:28


_state

protected _state: ShapeState = ShapeState.Default

The current state of the shape, representing its visual or interactive status.

Inherited from

Rectangle._state

Defined in

shapes/Shape.ts:31


_style

protected _style: RectangleStyle

The style settings for the shape, proxied to trigger observer notifications on change.

Inherited from

Rectangle._style

Defined in

shapes/Shape.ts:25


observers

protected observers: () => void[] = []

List of observer functions to be notified on shape changes.

Inherited from

Rectangle.observers

Defined in

shapes/Shape.ts:34

Accessors

angle

get angle(): Angle

Gets the angle of the rectangle.

Returns

Angle

The angle (rotation) of the rectangle.

Inherited from

Rectangle.angle

Defined in

shapes/Rectangle.ts:70


height

get height(): number

Gets the height of the square.

set height(height): void

Sets the height of the square and updates the width with same value.

Parameters

height: number

The new height of the square.

Returns

number

The height of the square.

Overrides

Rectangle.height

Defined in

shapes/Square.ts:45


options

get options(): TOptions

Gets the configuration options of the shape.

set options(options): void

Updates the configuration options of the shape and notifies observers.

Parameters

options: TOptions

The new options to apply.

Returns

TOptions

The current options.

Inherited from

Rectangle.options

Defined in

shapes/Shape.ts:203


position

get position(): Point

Gets the position (Point) of the rectangle.

set position(position): void

Sets the position (Point) of the rectangle.

Parameters

position: Point

The new position of the rectangle.

Returns

Point

The position of the rectangle.

Inherited from

Rectangle.position

Defined in

shapes/Rectangle.ts:62


rotation

get rotation(): number

Gets the rotation of the rectangle in degrees.

set rotation(rotation): void

Sets the rotation of the rectangle.

Parameters

rotation: number

The new rotation of the rectangle.

Returns

number

The rotation of the rectangle.

Inherited from

Rectangle.rotation

Defined in

shapes/Rectangle.ts:78


size

get size(): number

Gets the size (widht/height) of the square.

set size(size): void

Sets the size (width/height) of the square.

Parameters

size: number

The new size of the square.

Returns

number

The size of the square.

Defined in

shapes/Square.ts:37


state

get state(): ShapeState

Gets the current state of the shape.

set state(state): void

Sets a new state for the shape.

Parameters

state: ShapeState

The new state to assign to the shape.

Returns

ShapeState

The current state of the shape.

Inherited from

Rectangle.state

Defined in

shapes/Shape.ts:221


stateStyle

get stateStyle(): TStyle

Retrieves the effective style of the shape based on its current state.

Returns

TStyle

The computed style object for the current shape state, with state-specific overrides merged in as necessary.

Inherited from

Rectangle.stateStyle

Defined in

shapes/Shape.ts:243


style

get style(): TStyle

Gets the style settings of the shape.

set style(style): void

Updates the style settings of the shape and notifies observers.

Parameters

style: TStyle

The new style settings to apply.

Returns

TStyle

The current style settings.

Inherited from

Rectangle.style

Defined in

shapes/Shape.ts:185


width

get width(): number

Gets the width of the square.

set width(width): void

Sets the width of the square and updates the height with same value.

Parameters

width: number

The new width of the square.

Returns

number

The width of the square.

Overrides

Rectangle.width

Defined in

shapes/Square.ts:53

Methods

addObserver()

addObserver(observer): void

Adds an observer function that will be called when the shape's state changes.

Parameters

observer

The observer callback function.

Returns

void

Inherited from

Rectangle.addObserver

Defined in

shapes/Shape.ts:154


hasBorder()

protected hasBorder(): boolean

Determines if the current state style includes a visible border.

Returns

boolean

true if borderColor and borderWidth are defined and indicate a visible border; otherwise, false.

Inherited from

Rectangle.hasBorder

Defined in

shapes/Shape.ts:280


hide()

hide(): void

Hides the shape, preventing it from being rendered on the canvas. The shape will still exist and retain its properties, but it will not appear during rendering until show() is called.

Returns

void

Inherited from

Rectangle.hide

Defined in

shapes/Shape.ts:127


isMouseOver()

isMouseOver(mousePosition): boolean

Determines if the mouse is currently over the shape.

Parameters

mousePosition: Point

The current mouse position.

Returns

boolean

True if the mouse is over the shape, false otherwise.

Inherited from

Rectangle.isMouseOver

Defined in

shapes/Rectangle.ts:233


isVisible()

isVisible(): boolean

Checks whether the shape is currently visible.

Returns

boolean

Returns true if the shape is visible and will be rendered on the canvas. Returns false if the shape is hidden and will not be rendered.

Inherited from

Rectangle.isVisible

Defined in

shapes/Shape.ts:137


move()

move(deltaX, deltaY): void

Moves the rectangle by adjusting the current position by delta values.

Parameters

deltaX: number = 0

The change in the x-coordinate.

deltaY: number = 0

The change in the y-coordinate.

Returns

void

Inherited from

Rectangle.move

Defined in

shapes/Rectangle.ts:144


removeObserver()

removeObserver(observer): void

Removes a previously added observer function.

Parameters

observer

The observer callback function to be removed.

Returns

void

Inherited from

Rectangle.removeObserver

Defined in

shapes/Shape.ts:165


render()

render(context): void

Renders the rectangle on the canvas using the provided 2D rendering context.

The rectangle will be rendered with its current position, size, and rotation.

Parameters

context: CanvasRenderingContext2D

The 2D rendering context of the canvas where the rectangle will be drawn.

Returns

void

Inherited from

Rectangle.render

Defined in

shapes/Rectangle.ts:180


resize()

resize(deltaSize): void

Resizes the rectangle by adjusting the current size, width and height by delta value.

Parameters

deltaSize: number

The change in width.

Returns

void

Overrides

Rectangle.resize

Defined in

shapes/Square.ts:101


rotate()

rotate(deltaRotation): void

Rotates the rectangle by adjusting its current angle.

Parameters

deltaRotation: number

The amount to adjust the rectangle's rotation, in degrees.

Returns

void

Inherited from

Rectangle.rotate

Defined in

shapes/Rectangle.ts:153


setSize()

setSize(size): void

Updates the size of the square by setting new width and height values.

Parameters

size: number

The new width and height of the square.

Returns

void

Overrides

Rectangle.setSize

Defined in

shapes/Square.ts:91


show()

show(): void

Makes the shape visible, allowing it to be rendered on the canvas. If the shape was previously hidden, calling this method will make it appear during the next rendering cycle.

Returns

void

Inherited from

Rectangle.show

Defined in

shapes/Shape.ts:118


toArray()

toArray(): any[]

Converts the shape's definition to an array.

Returns

any[]

An array representation of the shape's definition.

Inherited from

Rectangle.toArray

Defined in

shapes/Shape.ts:100


toJson()

toJson(): string

Converts the shape's definition to a JSON string.

Returns

string

A JSON string representation of the shape's definition.

Inherited from

Rectangle.toJson

Defined in

shapes/Shape.ts:109