Overview
The Line primitive represents a straight line segment in 3D space, defined by a start point and an end point. It is the simplest 2D primitive in OpenGeometry and is suitable for creating linear segments, edges, and simple geometric constructions.
Use Cases:
- Drawing straight line segments
- Creating basic geometric shapes
- Defining edges in technical drawings
- Path offset operations for parallel lines
Constructor
let line = OGLine::new(id: String);
const line = new Line(options?: ILineOptions);
Rust Constructor Parameters
Unique identifier for the line instance
TypeScript Constructor Parameters
Configuration options for the line
Optional unique identifier (auto-generated if not provided)
Starting point of the line
Line color as a hexadecimal number (e.g., 0x000000 for black)
Enable thick line rendering using Line2
Line width when fatLines is enabled
Methods
set_config
line.set_config(start: Vector3, end: Vector3);
Updates the line’s start and end points.line.setConfig(options: ILineOptions);
Updates the line configuration and regenerates geometry.
generate_geometry
line.generate_geometry();
// Called automatically by setConfig
Generates the BREP (Boundary Representation) geometry for the line, creating vertices and edges.
get_geometry_serialized
let geometry: String = line.get_geometry_serialized();
// Used internally for rendering
Returns serialized vertex buffer data as a JSON string.
get_offset_serialized
let offset_data = line.get_offset_serialized(
distance: f64,
acute_threshold_degrees: f64,
bevel: bool
);
const result = line.getOffset(
distance: number,
acuteThresholdDegrees: number = 35.0,
bevel: boolean = true
): ILineOffsetResult;
Generates an offset path parallel to the line at the specified distance.
Distance to offset the line (positive or negative)
Angle threshold for beveling acute corners
Enable beveling at acute angles
get_brep_serialized
let brep: String = line.get_brep_serialized();
// Available through internal API
Returns the complete BREP representation as JSON.
Properties
Unique identifier for the line instance
Starting point of the line (Rust only)
Ending point of the line (Rust only)
Internal BREP representation containing vertices and edges
Line color (TypeScript only, settable)
Code Examples
Creating a Basic Line
use opengeometry::primitives::OGLine;
use openmaths::Vector3;
let mut line = OGLine::new("line-1".to_string());
line.set_config(
Vector3::new(0.0, 0.0, 0.0),
Vector3::new(10.0, 0.0, 0.0)
);
line.generate_geometry();
import { Line, Vector3 } from 'opengeometry-three';
const line = new Line({
start: new Vector3(0, 0, 0),
end: new Vector3(10, 0, 0),
color: 0x000000
});
Generating Offset Lines
let offset_data = line.get_offset_serialized(2.0, 35.0, true);
let result: OffsetResult = serde_json::from_str(&offset_data).unwrap();
const offsetResult = line.getOffset(
2.0, // distance
35.0, // acute threshold
true // bevel
);
console.log(offsetResult.points); // Vector3[]
console.log(offsetResult.beveledVertexIndices); // number[]
console.log(offsetResult.isClosed); // false for lines
Using Fat Lines
const thickLine = new Line({
start: new Vector3(0, 0, 0),
end: new Vector3(10, 5, 0),
color: 0xff0000,
fatLines: true,
width: 50
});
Updating Line Configuration
line.setConfig({
start: new Vector3(0, 0, 0),
end: new Vector3(15, 10, 0),
color: 0x00ff00
});
// Change color dynamically
line.color = 0x0000ff;