Skip to content

Geometry objects

Jiří Cihelka edited this page Jan 2, 2024 · 3 revisions

The Geometry.js library provides a set of classes for creating and manipulating geometric objects.
The library uses inheritance to create a hierarchy of classes and interfaces that represent geometric objects. Interfaces are used for features and inheritance for implementation.

Categorization of objects

When we talk about classes provided by the library, they can be divided into categories based on some of their properties. Divisions commonly used by the documentation will be explained below.

Object with type

Fisrt category is a so-called object with type. We use object with type when we talk about a class (or more commonly an interface) that represents a geometric object. For example, the Point interface represents a point in the plane. The Point class is an object with type (the type is Point).
The implementation of the Point interface is in this case irrelevant. This categorization is based solely on what the class represents.

Bound vs. Unbound object

One of the most important categorizations is the categorization of objects into bound and unbound.
We can think of unbound objects as of lightweight data objects. They only store data and can calculate some basic properties of themselves. They are independent of any other objects. All of their properties remain constant, if not changed by the user.

Bound objects are objects that are part of the internal dependency graph (more information can be found on the Dependency graph page). This means, that the value of their properties is dependent on the values of properties of their dependencies and can change if the values of their dependencies change. These objects are also bound to a specific plane. This means they will show up while iterating over the objects of the plane.
Bound objects are created using methods that start with create, construct or extract and are created explicitly by the user. Be careful when creating bound objects, beacuse they are not garbage collected (this happens, beacause a reference to the object is stored in the plane). Using bound objects for temporary calculations is therefore not recommended.

Create vs. Construct vs. Extract

The difference between the methods that create bound objects is in the way they are created.

  • create methods create a new object by combining existing objects or numbers. An example of this can be creating a line from two points.
  • construct methods create a new object by following a geometric construction. An example of this can be creating a perpendicular line to a given line through a given point.
  • extract methods create a new object by extracting it from an existing object. An example of this can be extracting a direction vector from a line.

Virtual vs. Non-virtual object

Another categorization is the categorization of objects into virtual and non-virtual. All objects with type are either virtual or non-virtual.
Virtual objects are objects that don't have a graphical representation. Example of this can be the Vector interface or the Value interface.

Non-virtual objects are objects that have a graphical representation. Example of this can be the Point interface or the Line interface.

Enum and Union Objects

Besides the standard objects the library also provides Enum and Union objects. These are so-called derived objects. They don't represent anything by themselves, but are used to group other objects together.
They can be chained (you can have, for example, an enum of unions).

Enum Objects

Enum objects are used to group objects that are mutually exclusive. This means that only one of the objects in the group can be used at a time. This is useful, for example, when the construction has multiple cases with the result being of different type in each case (for example the intersection of two lines).

Union Objects

Union objects represent an object that is represented by multiple objects at the same time. This is useful, for example, when the result of a construction is multiple objects (for example the intersection of a line and a circle).

Null object

A special objects is the NullObject. It is used to represent a null value. It is used, for example, when the result of a construction is not defined (for example the intersection of two parallel lines).