Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

GEF/GEF4/Geometry

Description

This is the documentation of the GEF4 Geometry API. You can find a small tutorial for the API here.

Geometric primitives

Angle, Dimension, and Point

The API uses a small number of "primitives" which are globally used to build up, introspect and modify complex objects. These primitives are the Point, Angle and Dimension classes. Presumably, the most important class of the three is the Point class, because you will encounter it very often while working with the API. Point objects represent a point in two dimensional space.(1) From a list of Point objects, you can build up every planar geometry object.

Considering rotation and the angular relationship of two straight lines, Angle objects come into play. They abstract over two angle units: degrees and radians. The user has to specify the unit of the value an Angle object is constructed from. Moreover, the user can read the value of an Angle object in either degrees or radians. Therefore, the use of Angle objects assures that correct values are used in calculations. This indirection is done, due to an inconsistency of several APIs, for example, org.eclipse.swt.graphics.Transform vs. org.eclipse.draw2d.geometry.Transform. Keep in mind that the GEF 4 Geometry API is not yet finished. Maybe, this indirection will be eliminated in a future version.

The Dimension class is the pendant of the draw2d.Dimension class.

(1) For the purpose of imagination, you can assume the coordinate system to be originated in the top left corner of your drawing area, expanding to the right and to the bottom.

Planar geometry

Interface hierarchy

This diagram depicts the interface hierarchy which underlies the individual geometry classes. It classifies the geometry classes mainly into either being ICurves or IShapes. An ICurve is a one dimensional geometry, i.e. the result that you get by drawing a continuous line with a pencil. It has a start and an end point, it is continuous and you can approximate it by a series of Bézier curves. On the other hand, an IShape is a two dimensional geometry, i.e. it continuously encloses a region on the drawing area, without holes. You can retrieve the outline of an IShape, which is an IPolyCurve, a special case of an ICurve. It defines a curve that is composed of multiple continuous ICurves and its purpose is to combine such a set of continuous curves to be able to operate on them as a whole.

Especially important for clipping, another class of planar geometries is introduced: the IPolyShape. Other than the relationship between ICurve and IPolyCurve, an IPolyShape is not an IShape. An IPolyShape is a (possibly) non-continuous set of IShapes. An example for an IPolyShape is a Region. A Region is the area that results from composing multiple Rectangles. It corresponds to the SWT Region.

Important functionality

An important part of a geometry API is the possibility to test the relationship of two geometry objects. The GEF 4 Geometry API provides four methods that perform relation tests. Universally usable is the touches() method for planar geometry objects. It tests if two objects have at least one point in common. Additionally, ICurves can be tested for intersections using the intersects() method and for an overlap using the overlaps() method, among each other. An IShape provides a contains() method to test if it fully contains a given planar geometry object. Moreover, the point test is available for arbitrary planar geometry objects. It tests if a given Point is incidental to the particular geometry object.

Supplementary to the intersects() test, a getIntersections() method is offered among ICurves. BézierCurves do also facilitate the extraction of overlapping segments via the getOverlap() method.

To achieve the full functionality of the API, you have to be aware of how the different planar geometry objects and their implemented interfaces are linked together. The fundamental ICurve is the BezierCurve, because every ICurve can be approximated by a set of continuous BezierCurves. This approximation can be received using the toBezier() method. The outline of an IShape always is an ICurve. You can retrieve it by using the getOutline() method on the particular shape. Furthermore, any planar geometry object can be transformed into a Path object by using its toPath() method.

The Path is special. It can hold any number of curves and shapes. But it does not implement the related interfaces. Therefore, you should only use the Path in situations where you really need it, because it

So, let us consider a few examples.

  1. Compute the points of intersection between a Line l1 and another Line l2:
    Point[] intersections = l1.getIntersections(l2);
  2. Compute the points of intersection between a Line l and a Polygon p:
    Point[] intersections = l.getIntersections(p.getOutline());
  3. Compute the points of intersection between a Polygon p1 and another Polygon p2:
    Point[] intersections = p1.getOutline().getIntersections(p2.getOutline());

Inheritance hierarchy

This diagram depicts the inheritance hierarchy which underlies the individual geometry classes. It classifies the classes by their construction type, so that many operations are generalized in a few abstract classes. Additionally, the different planar geometry objects provide extra functionality, for example, computing the area of a Polygon, or unifying two Rectangles.

IGeometry

IGeometry

ICurve

ICurve

Line

Line

QuadraticCurve

QuadraticCurve

CubicCurve

CubicCurve

BezierCurve

BezierCurve

Arc

Arc

IPolyCurve

IPolyCurve

Polyline

Polyline

PolyBezier

PolyBezier

IShape

IShape

Rectangle

Rectangle

RoundedRectangle

RoundedRectangle

Polygon

Polygon

Ellipse

Ellipse

Pie

Pie

IPolyShape

IPolyShape

Region

Region

Ring

Ring

Path

Path

Conversions

From Geometry to SWT

via the toSWT...() methods

AWT2Geometry

Geometry2AWT

SWT2AWT

Affine transformations

Via projective geometry. All transformations are combined before applying them to the particular shape.

Translation

Rotation

Scaling

Shearing

Euclidean geometry

Vector

Vector

Straight

Straight

Projective geometry

Vector3D

Vector3D

Straight3D

Straight3D

Back to the top