Coordinate Systems

The modern Cartesian coordinate system in two dimensions (also called a rectangular coordinate system) is commonly defined by two axes, at right angles to each other, forming an xy plane. These axes are measured using a Scale for each dimension: one for the x-axis and one for the y-axis (or one for the degree and one for the radius when using polar-coordinates).

In a three-dimensional coordinate system, another axis is added to provide a third dimension of spatial measurement. These axes are commonly defined as being mutually orthogonal to each other. Many other coordinate systems have been developed since the time of Descartes. One is the aforementioned polar-coordinate system. Astronomers, for example, often use spherical coordinates, a type of polar coordinate system.

Interface CoordinateSystem

In a graphical context, every object must lie within a coordinate system. Very often, you have a complex situation where coordinate systems are nested. This class can therefore convert coordinates from an outer coordinate system to an inner coordinate system and vice versa.

  • double descale(int, double, double, double)

    Converts the value given by valueToDescale to the range given by minimum and maximum to the range Scale in the given direction.

  • Transform2D getTransform2D(double, double, double, double)

    Returns the Transform2D resulting from the given min and max values (defining a bounding-box) and the scalefactors used by the Scales of this CoordinateSystem.

  • Transform2D getTransform2D_inverse(double, double, double, double)

    Returns the inverse Transform2D resulting from the given min and max values (defining a bounding-box) and the scalefactors used by the Scales of this CoordinateSystem.

  • double scale(int, double, double, double)

    Converts the value given by valueToScale from the range of the Scale in the given direction to the range given by minimum and maximum.

To avoid creating identical CoordinateSystem objects (using the same Scale types and intervals), objects are pooled in the CoordinateSystemPool singleton. Since many clients may have a reference to the very same instance, CoordinateSystem objects are immutable. A mutable version is defined by the MutableCoordinateSystem interface.

Pooling

To avoid the creation of identical Scale and CoordinateSystem objects, instances of these classes are pooled by the Tensegrity Graph Framework. As a consequence of pooling and multiple object references by multiple clients, pooled objects are always immutable.

During the design phase of Tensegrity Graph Framework it was known that there are certain situations that necessitate changing a Scale or CoordinateSystem object at runtime. For this reason, the interfaces MutableScale and MutableCoordinateSystem define mutable versions of these components. Instances of these types are never pooled and can be changed by a client without introducing negative side effects.

Class ScalePool defines the needed facility to pool created Scale instances. This class is responsible for maintaining global references to Scale objects needed by multiple clients.

While it is possible to remove all pooled Scale objects by invoking the clear method, this should only be done when you are sure that all pooled objects are no longer being referenced by any other object. The actual number of pooled Scale objects can be determined by invoking the size method. Additionally, the ScalePool can parse a canonical description and return a new or existing Scale when you invoke the parse method.

Class CoordinateSystemPool defines the needed facility to pool created CoordinateSystem instances. This class is responsible for maintaining global references to CoordinateSystem objects needed by multiple clients.

While it is possible to remove all pooled CoordinateSystem objects by invoking the clear method, this should only be done when you are sure that all pooled objects are no longer being referenced by any other object. The actual number of pooled CoordinateSystem objects can be determined by invoking the size method. Additionally, the CoordinateSystemPool can parse a canonical description and return a new or existing CoordinateSystem when you invoke the parse method.