Skip to content

fontlab.Interval

Interval

A parametric range on a contour.

What is Interval?

Imagine "selecting" a portion of a contour — not a node, but a stretch of curve from 25% to 75% of the way along the path. An Interval stores exactly that: two parametric values t0 and t1 defining a sub-range of a Bézier contour.

Intervals are used internally by the node selection system, by split-curve operations, and by any tool that needs to work with a portion of a contour rather than whole segments. You will mostly encounter them when writing custom canvas tools that deal with selecting or cutting parts of curves.

Tutorial

from fontlab import Interval

# ============================================================
# Create an interval covering the middle third of a contour.
# This represents parametric positions 33.3% to 66.7% along
# the contour arc.
# ============================================================

iv = Interval()
iv.setT0T1(0.333, 0.667)

print(f"Interval: t0={iv.t0:.3f}  t1={iv.t1:.3f}")
print(f"Length:   {iv.d:.3f}")
print(f"Midpoint: {iv.middle():.3f}")
print(f"Is empty: {iv.isEmpty()}")

# ============================================================
# Map a relative position within the interval to an
# absolute contour position.
# "Where is the 1/4 point of this interval on the contour?"
# ============================================================

# 0.25 = 1/4 of the way through [0.333, 0.667]
quarter_abs = iv.toAbsolute(0.25)
print(f"\n1/4 through interval → absolute t = {quarter_abs:.3f}")
# Expected: 0.333 + 0.25 * (0.667 - 0.333) = ~0.417

# Map back: given absolute t=0.5, where is that in the interval?
fraction = iv.toInterval(0.5)
print(f"Absolute t=0.5 → interval fraction = {fraction:.3f}")
# Expected: (0.5 - 0.333) / (0.667 - 0.333) = ~0.5

# ============================================================
# Reverse the interval — same coverage, opposite direction.
# Useful when you need to iterate a selection in reverse.
# ============================================================

rev = iv.reversed()
print(f"\nReversed: t0={rev.t0:.3f}  t1={rev.t1:.3f}")

# ============================================================
# An empty interval — covers nothing.
# This is what you get when a hit test lands exactly on a node.
# ============================================================

empty_iv = Interval()
empty_iv.setT0T1(0.5, 0.5)
print(f"\nEmpty interval: isEmpty={empty_iv.isEmpty()}  d={empty_iv.d}")

Common Scripting Patterns

Check whether a parametric position falls within an interval

from fontlab import Interval

iv = Interval()
iv.setT0T1(0.2, 0.8)

def contains(interval, t):
    return interval.t0 <= t <= interval.t1

print(contains(iv, 0.5))   # True
print(contains(iv, 0.1))   # False

Split an interval into equal thirds

from fontlab import Interval

iv = Interval()
iv.setT0T1(0.0, 1.0)

third = iv.d / 3.0
parts = []
for i in range(3):
    part = Interval()
    part.setT0T1(iv.t0 + i * third, iv.t0 + (i + 1) * third)
    parts.append(part)
    print(f"Part {i}: [{part.t0:.3f}, {part.t1:.3f}]")

Constructors:

Native bases: object

Captured native MRO: Interval, object

Native new allocation evidence (not an init overload): (args, *kwargs) Create and return a new object. See help(type) for accurate signature.

Supplemental documentation: A numeric interval with t0 and t1 (both double) and d and key attributes. The captured declaration exposes isEmpty, middle, reversed, setT0T1, toAbsolute and toInterval. Consult the retained constructor documentation for the supported creation forms.

Source: FontLab Proteus API documentation

Source: generated/fontlab.py: Interval captured declaration

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
__init__ function (self, /, *args: Any, **kwargs: Any) -> None Initialize self. (shared captured text)
d attribute Any Double d
isEmpty function (self) -> bool Returns True if t0 == t1 (a zero-length interval that covers no curve area).
key attribute Any Uint key
middle function (self) -> float Returns the midpoint of the interval: (t0 + t1) / 2.
reversed function (self) -> Any Returns a new interval with t0 and t1 swapped.
setT0T1 function (self, t0: float, t1: float) -> None Sets both t0 and t1 simultaneously.
t0 attribute Any Double t0
t1 attribute Any Double t1
toAbsolute function (self, v: float) -> float Converts a value v expressed as a fraction of this interval (0 = start, 1 = end) to an absolute parametric value on the contour.
toInterval function (self, absv: float) -> float The inverse of toAbsolute.