# LineSegmentsUnit

The `LineSegmentsUnit` class represents a collection of line segments in 2D space. It is a derived class of `IntermediateResultUnit`.

## Definition

*Namespace:* com.dynamsoft.core.intermediate_results

*Assembly:* DynamsoftCaptureVisionBundle.aar

```java
class LineSegmentsUnit extends IntermediateResultUnit
```

## Methods

| Methods | Description |
| ------- | ----------- |
| [`getLineSegments`](#getlinesegments) | Gets an array of [`LineSegment`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/basic-structures/line-segment.md) objects, each representing a segment of a line detected within the image. |
| [`getCount`](#getcount) | Gets the number of line segments. |
| [`getLineSegment`](#getlinesegment) | Gets the [`LineSegment`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/basic-structures/line-segment.md) at the specified index. |
| [`removeAllLineSegments`](#removealllinesegments) | Removes all line segments. |
| [`removeLineSegment`](#removelinesegment) | Removes the line segment at the specified index. |
| [`addLineSegment`](#addlinesegment) | Adds a line segment. |
| [`setLineSegment`](#setlinesegment) | Sets the line segment at the specified index. |

## Inherited Methods

The following methods are inherited from class [`IntermediateResultUnit`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/intermediate-results/intermediate-result-unit.md).

| Method | Description |
|------- |-------------|
| [`clone`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/intermediate-results/intermediate-result-unit.md#clone) | Creates a copy of the intermediate result unit. |
| [`gethashId`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/intermediate-results/intermediate-result-unit.md#gethashid) | Gets the hash ID of the unit. The hash ID is the unique identifier for the intermediate result unit. |
| [`getOriginalImageHashId`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/intermediate-results/intermediate-result-unit.md#getoriginalimagehashid) | Gets the hash ID of the original image. You can use this ID to get the original image via `IntermediateResultManager` class. |
| [`getOriginalImageTag`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/intermediate-results/intermediate-result-unit.md#getoriginalimagetag) | Gets the image tag of the original image associated with this unit. |
| [`getType`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/intermediate-results/intermediate-result-unit.md#gettype) | Gets the type of the intermediate result unit, defined by the enumeration [`EnumIntermediateResultUnitType`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/enum/intermediate-result-unit-type.md). |
| [`getTransformMatrix`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/intermediate-results/intermediate-result-unit.md#gettransformmatrix) | Gets the transformation matrix via [`EnumTransformMatrixType`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/enum/transform-matrix-type.md). |
| [`replace`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/intermediate-results/intermediate-result-unit.md#replace) | Replaces the old unit with the new unit. |

### getLineSegments

Gets the array of [`LineSegment`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/basic-structures/line-segment.md).

```java
@Nullable
LineSegment[] getLineSegments();
```

**Return Value**

The array of [`LineSegment`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/basic-structures/line-segment.md).

### getCount

Gets the number of line segments.

```java
int getCount();
```

**Return Value**

The number of line segments.

### getLineSegment

Gets the [`LineSegment`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/basic-structures/line-segment.md) at the specified index.

```java
@Nullable
LineSegment getLineSegment(int index);
```

**Return Value**

The [`LineSegment`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/android/api-reference/core/basic-structures/line-segment.md) at the specified index.

### removeAllLineSegments

Removes all line segments.

```java
void removeAllLineSegments();
```

### removeLineSegment

Removes the line segment at the specified index.

```java
int removeLineSegment(int index);
```

**Parameters**

`[in] index`: The index of the line segment to remove.

**Return Value**

Returns the `ErrorCode` if failed. Otherwise, returns 0.

### addLineSegment

Adds a line segment.

```java
int addLineSegment(LineSegment line, Matrix matrixToOriginalImage);
```

**Parameters**

`[in] line`: The line segment to add.

`[in] matrixToOriginalImage`: The transformation matrix from the line segment to the original image.

**Return Value**

Returns the `ErrorCode` if failed. Otherwise, returns 0.

### setLineSegment

Sets the line segment at the specified index.

```java
int setLineSegment(int index, LineSegment line,  Matrix matrixToOriginalImage);
```

**Parameters**

`[in] index`: The index of the line segment to set.

`[in] line`: The line segment to set.

`[in] matrixToOriginalImage`: The transformation matrix from the line segment to the original image.

**Return Value**

Returns the `ErrorCode` if failed. Otherwise, returns 0.
