Shape

data class Shape(val id: String = Uuid.random().toString(), val type: String = "Shape", val shapeType: ShapeType, val points: List<Offset>, val strokeColor: Color, val fillColor: Color? = null, val strokeEnabled: Boolean = true, val strokeWidth: Float, val zIndex: Int = 0, val rotation: Float = 0.0f, val cornerRadius: Float = 0.0f, val strokeStyle: StrokeStyle = StrokeStyle.SOLID, val bend: Offset = Offset.Zero, val startBinding: String? = null, val endBinding: String? = null, val createdAt: Long = 0, val modifiedAt: Long = 0) : Element

Constructors

Link copied to clipboard
constructor(id: String = Uuid.random().toString(), type: String = "Shape", shapeType: ShapeType, points: List<Offset>, strokeColor: Color, fillColor: Color? = null, strokeEnabled: Boolean = true, strokeWidth: Float, zIndex: Int = 0, rotation: Float = 0.0f, cornerRadius: Float = 0.0f, strokeStyle: StrokeStyle = StrokeStyle.SOLID, bend: Offset = Offset.Zero, startBinding: String? = null, endBinding: String? = null, createdAt: Long = 0, modifiedAt: Long = 0)

Properties

Link copied to clipboard

Offset of the curve's mid-point from the straight-line midpoint of points[0] → points.last(). Only meaningful for ShapeType.LINE and ShapeType.ARROW; ignored otherwise. Offset.Zero (default) = straight. Non-zero = the line/arrow renders as a quadratic bezier arcing through midpoint + bend.

Link copied to clipboard

Corner radius in world pixels for ShapeType.RECTANGLE and ShapeType.TRIANGLE. Ignored for circle, line, arrow. 0 = sharp. Auto-clamped at render time so it never exceeds half the shortest adjacent edge.

Link copied to clipboard
open override val createdAt: Long

Epoch milliseconds at which this element was first created. Used for ordered replay (and later as a tie-break source for collab clocks). 0L means "unknown" — element predates the timestamp field; consumers that sort by createdAt should treat 0 as "earliest".

Link copied to clipboard

ID of the element this arrow's end endpoint is bound to. Behaves like startBinding for the end point. Only honored for ShapeType.ARROW.

Link copied to clipboard
Link copied to clipboard
open override val id: String

Unique identifier for this element

Link copied to clipboard
open override val modifiedAt: Long

Epoch milliseconds at which any property of this element last changed. On creation, equals createdAt. Bumped via touched on every mutation path so sync layers can resolve concurrent edits with LWW semantics.

Link copied to clipboard
Link copied to clipboard
open override val rotation: Float

Rotation in degrees, applied around the element's axis-aligned bounding box center at render time. Points stored on the element are in the unrotated (logical) coordinate space.

Link copied to clipboard
Link copied to clipboard

ID of the element this arrow's start endpoint is bound to. When set and the bound element moves/resizes/rotates, the arrow's start point follows. Only honored for ShapeType.ARROW.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Stroke pattern for non-filled rendering. Solid by default. For arrows the body line follows this style; the head stays solid for clarity.

Link copied to clipboard
Link copied to clipboard
open override val type: String

String identifier of the element type for serialization

Link copied to clipboard
open override val zIndex: Int

Layering order (higher values appear on top)

Functions

Link copied to clipboard

World-space point on the curve at t = 0.5 — the spot where the bend handle sits.

Link copied to clipboard

Point on this shape's outline closest to the ray from the shape's center toward target. Used by arrow connectors to terminate at the boundary instead of sinking into the shape.

Link copied to clipboard

Axis-aligned bounding box of the element in unrotated logical space.

Link copied to clipboard

World-space attachment point for an arrow connector binding to this shape.

Link copied to clipboard

Quadratic-bezier control point for a curved ShapeType.LINE / ShapeType.ARROW.

Link copied to clipboard
fun Element.hitTest(point: Offset, tolerance: Float = 8.0f): Boolean

Hit test against a world-space point. Inverse-rotates the point into the element's logical space, then applies a per-type test that accounts for stroke width and the provided pick tolerance.

Link copied to clipboard
Link copied to clipboard
fun Element.touched(now: Long = kotlin.time.Clock.System.now().toEpochMilliseconds()): Element

Stamp Element.modifiedAt with now (defaults to current epoch ms). Call this on every mutation site so sync layers see a fresh LWW timestamp.

Link copied to clipboard

Translate all points by delta. Rotation unchanged.

Link copied to clipboard
fun Element.withBounds(newBounds: Rect): Element

Scale points so the bounding box matches newBounds. For two-point shapes this snaps start/end to the new bbox corners (preserving orientation of the original drag direction). For freedraw paths every point is scaled linearly. Rotation unchanged.

Link copied to clipboard

Absolute rotation in degrees.