Kernel SDK Developer's Guide > Working with the Ge Library > Working with Intervals
Working with Intervals

Parametric geometry in the ODA Kernel SDK uses intervals for determining regions of parameter values. For working with intervals of real numbers, the Ge library provides the OdGeInterval class, which represents finite, infinite, or semi-infinite intervals of the real axis. Finite intervals have bounds defined with given tolerance.

To create an interval object, use the following OdGeInterval() constructors:

  • OdGeInterval::OdGeInterval(double tol = 1.e-12) — Creates an unbounded interval.
  • OdGeInterval::OdGeInterval(const OdGeInterval& interval) — Creates a tolerance cloned from the source interval object.
  • OdGeInterval::OdGeInterval(double lower, double upper, double tol = 1.e-12) — Creates a tolerance with given lower and upper bounds.
  • OdGeInterval::OdGeInterval(bool boundedBelow, double bound, double tol = 1.e-12) — Creates a tolerance with the specified upper bound. If the boundedBelow is true, the lower bound is set to the same value as the upper. If false, creates an interval unbounded below.

For example:

OdGeInterval interval1;
OdGeInterval interval2(true, 1.0);
OdGeInterval interval3(2.0, 6.5);

The OdGeInterval class provides methods for working with intervals. You can get and set different parameters of an interval and apply comparison and boolean operations for pairs of intervals.

Check whether the interval is bounded or unbounded (above, below and both directions) using the isBoundedAbove(), isBoundedBelow(), isBounded() and isUnBounded() methods.

The upperBound() and the lowerBound() methods return the upper and lower bounds of the interval respectively. The getBounds() method obtains both bounds. To set bounds, use the setLower() and setUpper() methods.

double lower, upper;
if (interval1.isBounded())
interval1.getBounds(lower, upper);
else
{
  if (!interval1.isBoundedAbove())
    interval1.setUpper(3);
  if (!interval1.isBoundedBelow())
    interval1.setLower(2);
}

To check whether the interval owns a specified value or an interval, use the contains() method.

The following methods provide the ability to perform merging and intersecting operations with intervals:

  • void OdGeInterval::getMerge(const OdGeInterval& otherInterval, OdGeInterval& result) — Returns the smallest interval containing both the specified interval and this interval.
  • bool OdGeInterval::intersectWith(const OdGeInterval& otherInterval, OdGeInterval& result) — Returns true if the specified interval intersects with this one, and calculates the interval of the intersection.

You can subtract another interval from this one using the subtract() method:

int OdGeInterval::subtract(const OdGeInterval& otherInterval, OdGeInterval& lInterval, OdGeInterval& rInterval);

The method returns 0 if the subtraction result is empty. If the result of subtraction is a single interval, the returning value is 1 and the subtraction result is the lInterval. A returned value of 2 indicates that the result of subtraction is two intervals and they are the lInterval and rInterval.

The length() method calculates the length of the interval. If the interval is unbounded above or below, it returns a -1 value:

double length = interval1.length();

If the upper and lower bounds are equal, the interval is a singleton and its length is 0.0. To check if the interval is a singleton, use the isSingleton() method:

if (!interval1.isSingleton())
  double length = interval1.length();

For determining bounds of the interval, the tolerance is used. The tolerance can be defined while creating a new OdGeInterval (as a parameter of a OdGeInterval() constructor (except the constructor that clones the interval), or it can be set using the setTolerance() method. To return the current boundary tolerance value, use the tolerance() method. The default boundary tolerance for a newly created interval is 1.e-12.

See Also

Working with Tolerances

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.