Skip to main content

Overview

The RectanglePrimitive class creates a rectangular shape in 3D space defined by a center point, width, and breadth. It extends the kernel Rectangle class and implements the IPrimitive interface for selection and editing capabilities.

Constructor

new RectanglePrimitive(rectangleConfig?: RectangleOptions)
rectangleConfig
RectangleOptions
Configuration object for the rectangle primitive

RectangleOptions

ogid
string
Unique identifier for the rectangle object. Auto-generated if not provided.
center
Array<number>
required
Center point coordinates as [x, y, z]
width
number
required
Width of the rectangle
breadth
number
required
Breadth (height) of the rectangle
color
number
required
Rectangle color as hexadecimal number (e.g., 0xFF0000 for red)

Properties

center
Array<number>
Gets or sets the center point of the rectangle. Updates geometry automatically.
width
number
Gets or sets the width of the rectangle. Updates geometry automatically.
breadth
number
Gets or sets the breadth (height) of the rectangle. Updates geometry automatically.
rectangleColor
number
Gets or sets the rectangle color. Updates appearance automatically.
selected
boolean
Indicates whether the rectangle is currently selected
edit
boolean
Indicates whether the rectangle is in edit mode
ogType
string
Returns 'RectanglePrimitive' - the type identifier

Methods

getOPConfig()

Returns the current configuration of the rectangle.
getOPConfig(): RectangleOptions
Returns: RectangleOptions - Current rectangle configuration

setOPGeometry()

Updates the rectangle geometry based on current property values. Called automatically when properties change.
setOPGeometry(): void

Examples

Create a Basic Rectangle

import { RectanglePrimitive } from 'openplans';

const rectangle = new RectanglePrimitive({
  center: [0, 0, 0],
  width: 10,
  breadth: 5,
  color: 0x0000FF // Blue
});

Create a Square

const square = new RectanglePrimitive({
  center: [5, 5, 0],
  width: 8,
  breadth: 8,
  color: 0xFF0000 // Red
});

Update Rectangle Dimensions

// Change width
rectangle.width = 15;

// Change breadth
rectangle.breadth = 8;

// Move center position
rectangle.center = [10, 10, 0];

Change Rectangle Color

// Change to green
rectangle.rectangleColor = 0x00FF00;

Get Rectangle Configuration

const config = rectangle.getOPConfig();
console.log(config);
// Output:
// {
//   ogid: 'auto-generated-id',
//   center: [10, 10, 0],
//   width: 15,
//   breadth: 8,
//   color: 0x00FF00
// }

Create Multiple Rectangles

const rectangles = [
  new RectanglePrimitive({
    center: [0, 0, 0],
    width: 5,
    breadth: 3,
    color: 0xFF0000
  }),
  new RectanglePrimitive({
    center: [10, 0, 0],
    width: 8,
    breadth: 4,
    color: 0x00FF00
  }),
  new RectanglePrimitive({
    center: [20, 0, 0],
    width: 6,
    breadth: 6,
    color: 0x0000FF
  })
];
Last modified on March 7, 2026