# Segment

Artifact: [androidx.ink:ink-geometry](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/geometry/Segment.kt+class:androidx.ink.geometry.Segment) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

*** ** * ** ***


```
public abstract class Segment
```

<br />

Known direct subclasses [ImmutableSegment](https://developer.android.com/reference/androidx/ink/geometry/ImmutableSegment), [MutableSegment](https://developer.android.com/reference/androidx/ink/geometry/MutableSegment)

|---|---|
| `https://developer.android.com/reference/androidx/ink/geometry/ImmutableSegment` | Represents a directed line segment between two points. |
| `https://developer.android.com/reference/androidx/ink/geometry/MutableSegment` | Represents a mutable directed line segment between two points. |

*** ** * ** ***

Represents a directed line segment between two points.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableBox` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeBoundingBox()()` Returns the minimum bounding box containing the `https://developer.android.com/reference/androidx/ink/geometry/Segment`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableBox` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeBoundingBox(androidx.ink.geometry.MutableBox)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableBox outBox)` Populates `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeBoundingBox(androidx.ink.geometry.MutableBox)` with the minimum bounding box containing the `https://developer.android.com/reference/androidx/ink/geometry/Segment`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeDisplacement()()` Returns an ImmutableVec with the displacement from start to end. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeDisplacement(androidx.ink.geometry.MutableVec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVec)` Populates `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeDisplacement(androidx.ink.geometry.MutableVec)` with the displacement from start to end. |
| `final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLength()()` The length of the `https://developer.android.com/reference/androidx/ink/geometry/Segment`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLerpPoint(kotlin.Float)(float ratio)` Returns the point on the segment at the given ratio of the segment's length, measured from the start point. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLerpPoint(kotlin.Float,androidx.ink.geometry.MutableVec)(float ratio, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVec)` Fills `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLerpPoint(kotlin.Float,androidx.ink.geometry.MutableVec)` with the point on the segment at the given ratio of the segment's length, measured from the start point. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeMidpoint()()` Returns an `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec` that lies halfway along the segment. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeMidpoint(androidx.ink.geometry.MutableVec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableVec outVec)` Populates `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeMidpoint(androidx.ink.geometry.MutableVec)` with the point halfway along the segment. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#getEnd()()` |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#getStart()()` |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#isAlmostEqual(androidx.ink.geometry.Segment,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Segment other, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float tolerance )` Compares this `https://developer.android.com/reference/androidx/ink/geometry/Segment` with `https://developer.android.com/reference/androidx/ink/geometry/Segment#isAlmostEqual(androidx.ink.geometry.Segment,kotlin.Float)`, and returns true if both `https://developer.android.com/reference/androidx/ink/geometry/Segment#start()` points are considered almost equal with the given `https://developer.android.com/reference/androidx/ink/geometry/Segment#isAlmostEqual(androidx.ink.geometry.Segment,kotlin.Float)`, and likewise for both `https://developer.android.com/reference/androidx/ink/geometry/Segment#end()` points. |
| `final float` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#project(androidx.ink.geometry.Vec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec pointToProject)` Returns the multiple of the segment's length at which the infinite extrapolation of this segment is closest to `https://developer.android.com/reference/androidx/ink/geometry/Segment#project(androidx.ink.geometry.Vec)`. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableSegment` | `https://developer.android.com/reference/androidx/ink/geometry/Segment#toImmutable()()` Returns an immutable copy of this object. |

## Public methods

### computeBoundingBox

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull ImmutableBox computeBoundingBox()
```

Returns the minimum bounding box containing the `https://developer.android.com/reference/androidx/ink/geometry/Segment`.

For performance-sensitive code, prefer to use `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeBoundingBox()` with a pre-allocated instance of `https://developer.android.com/reference/androidx/ink/geometry/MutableBox`.

### computeBoundingBox

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull MutableBox computeBoundingBox(@NonNull MutableBox outBox)
```

Populates `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeBoundingBox(androidx.ink.geometry.MutableBox)` with the minimum bounding box containing the `https://developer.android.com/reference/androidx/ink/geometry/Segment`.

### computeDisplacement

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull ImmutableVec computeDisplacement()
```

Returns an ImmutableVec with the displacement from start to end. This is equivalent to `subtract(end, start, output)`.

For performance-sensitive code, prefer to use `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeDisplacement()` with a pre-allocated instance of `https://developer.android.com/reference/androidx/ink/geometry/MutableVec`.

### computeDisplacement

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull MutableVec computeDisplacement(@NonNull MutableVec outVec)
```

Populates `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeDisplacement(androidx.ink.geometry.MutableVec)` with the displacement from start to end. This is equivalent to `subtract(end, start, output)`. Returns `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeDisplacement(androidx.ink.geometry.MutableVec)`.

### computeLength

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @FloatRange(from = 0.0) float computeLength()
```

The length of the `https://developer.android.com/reference/androidx/ink/geometry/Segment`.

### computeLerpPoint

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull ImmutableVec computeLerpPoint(float ratio)
```

Returns the point on the segment at the given ratio of the segment's length, measured from the start point. You may also think of this as linearly interpolating from the start of the segment to the end. Values outside the interval 0, 1 will be extrapolated along the infinite line passing through this segment. This is the inverse of `https://developer.android.com/reference/androidx/ink/geometry/Segment#project(androidx.ink.geometry.Vec)`.

For performance-sensitive code, prefer to use `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLerpPoint(kotlin.Float)` with a pre-allocated instance of `https://developer.android.com/reference/androidx/ink/geometry/MutableVec`.

### computeLerpPoint

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull MutableVec computeLerpPoint(float ratio, @NonNull MutableVec outVec)
```

Fills `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLerpPoint(kotlin.Float,androidx.ink.geometry.MutableVec)` with the point on the segment at the given ratio of the segment's length, measured from the start point. You may also think of this as linearly interpolating from the start of the segment to the end. Values outside the interval 0, 1 will be extrapolated along the infinite line passing through this segment. This is the inverse of `https://developer.android.com/reference/androidx/ink/geometry/Segment#project(androidx.ink.geometry.Vec)`.

### computeMidpoint

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull ImmutableVec computeMidpoint()
```

Returns an `https://developer.android.com/reference/androidx/ink/geometry/ImmutableVec` that lies halfway along the segment.

For performance-sensitive code, prefer to use `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeMidpoint()` with a pre-allocated instance of `https://developer.android.com/reference/androidx/ink/geometry/MutableVec`.

### computeMidpoint

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull MutableVec computeMidpoint(@NonNull MutableVec outVec)
```

Populates `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeMidpoint(androidx.ink.geometry.MutableVec)` with the point halfway along the segment.

### getEnd

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract @NonNull Vec getEnd()
```

### getStart

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract @NonNull Vec getStart()
```

### isAlmostEqual

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean isAlmostEqual(
    @NonNull Segment other,
    @FloatRange(from = 0.0) float tolerance
)
```

Compares this `https://developer.android.com/reference/androidx/ink/geometry/Segment` with `https://developer.android.com/reference/androidx/ink/geometry/Segment#isAlmostEqual(androidx.ink.geometry.Segment,kotlin.Float)`, and returns true if both `https://developer.android.com/reference/androidx/ink/geometry/Segment#start()` points are considered almost equal with the given `https://developer.android.com/reference/androidx/ink/geometry/Segment#isAlmostEqual(androidx.ink.geometry.Segment,kotlin.Float)`, and likewise for both `https://developer.android.com/reference/androidx/ink/geometry/Segment#end()` points.

### project

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final float project(@NonNull Vec pointToProject)
```

Returns the multiple of the segment's length at which the infinite extrapolation of this segment is closest to `https://developer.android.com/reference/androidx/ink/geometry/Segment#project(androidx.ink.geometry.Vec)`. This is the inverse of `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLerpPoint(kotlin.Float)`. If the `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLength()` of this segment is zero, then the projection is undefined and this will throw an error. Note that the `https://developer.android.com/reference/androidx/ink/geometry/Segment#computeLength()` may be zero even if `https://developer.android.com/reference/androidx/ink/geometry/Segment#start()` and `https://developer.android.com/reference/androidx/ink/geometry/Segment#end()` are not equal, if they are sufficiently close that floating-point underflow occurs.

### toImmutable

Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

```
public abstract @NonNull ImmutableSegment toImmutable()
```

Returns an immutable copy of this object. This will return itself if called on an immutable instance.