# 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)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOS
- Cmn

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

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

*** ** * ** ***

Represents a directed line segment between two points.

## Summary

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

| ### Public properties |
|---|---|---|
| `abstract https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Segment#end()` | Cmn |
| `abstract https://developer.android.com/reference/kotlin/androidx/ink/geometry/Vec` | `https://developer.android.com/reference/kotlin/androidx/ink/geometry/Segment#start()` | Cmn |

## Public functions

### computeBoundingBox

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

```
fun computeBoundingBox(): ImmutableBox
```

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

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

### computeBoundingBox

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

```
fun computeBoundingBox(outBox: MutableBox): MutableBox
```

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

### computeDisplacement

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

```
fun computeDisplacement(): ImmutableVec
```

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/kotlin/androidx/ink/geometry/Segment#computeDisplacement()` with a pre-allocated instance of `https://developer.android.com/reference/kotlin/androidx/ink/geometry/MutableVec`.

### computeDisplacement

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

```
fun computeDisplacement(outVec: MutableVec): MutableVec
```

Populates `https://developer.android.com/reference/kotlin/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/kotlin/androidx/ink/geometry/Segment#computeDisplacement(androidx.ink.geometry.MutableVec)`.

### computeLength

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

```
fun computeLength(): @FloatRange(from = 0.0) Float
```

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

### computeLerpPoint

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

```
fun computeLerpPoint(ratio: Float): ImmutableVec
```

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/kotlin/androidx/ink/geometry/Segment#project(androidx.ink.geometry.Vec)`.

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

### computeLerpPoint

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

```
fun computeLerpPoint(ratio: Float, outVec: MutableVec): MutableVec
```

Fills `https://developer.android.com/reference/kotlin/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/kotlin/androidx/ink/geometry/Segment#project(androidx.ink.geometry.Vec)`.

### computeMidpoint

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

```
fun computeMidpoint(): ImmutableVec
```

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

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

### computeMidpoint

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

```
fun computeMidpoint(outVec: MutableVec): MutableVec
```

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

### isAlmostEqual

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

```
fun isAlmostEqual(other: Segment, tolerance: @FloatRange(from = 0.0) Float): Boolean
```

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

### project

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

```
fun project(pointToProject: Vec): Float
```

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

### toImmutable

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

```
abstract fun toImmutable(): ImmutableSegment
```

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

## Public properties

### end

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

```
abstract val end: Vec
```

### start

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

```
abstract val start: Vec
```