# Segment

Class representing a segment

## Constructor

#### new Segment(ps, pe)

Source:
  - classes/segment.js, line 20

##### Parameters:

Name | Type | Description
--- | --- | ---
`ps` | `Point` | start point
`pe` | `Point` | end point

### Classes

Segment

### Members

#### box

Bounding box

Source:
  - classes/segment.js, line 125

#### end

End point

Source:
  - classes/segment.js, line 91

#### length

Length of a segment

Source:
  - classes/segment.js, line 108

#### pe :Point

End Point

Source:
  - classes/segment.js, line 30

##### Type:

- `Point`

#### ps :Point

Start point

Source:
  - classes/segment.js, line 25

##### Type:

- `Point`

#### slope

Slope of the line - angle to axe x in radians from 0 to 2PI

Source:
  - classes/segment.js, line 116

#### start

Start point

Source:
  - classes/segment.js, line 83

#### vertices

Returns array of start and end point

Source:
  - classes/segment.js, line 100

### Methods

#### clone() → {Segment}

Return new cloned instance of segment

Source:
  - classes/segment.js, line 75

##### Returns:

Type:
  `Segment`

#### contains(pt) → {boolean}

Returns true if segment contains point

Source:
  - classes/segment.js, line 148

##### Parameters:

Name | Type | Description
--- | --- | ---
`pt` | `Point` | Query point

##### Returns:

Type:
  `boolean`

#### distanceTo(shape) → {number|Segment}

Calculate distance and shortest segment from segment to shape and return as array [distance, shortest segment]

Source:
  - classes/segment.js, line 193

##### Parameters:

Name | Type | Description
--- | --- | ---
`shape` | `Shape` | Shape of the one of supported types Point, Line, Circle, Segment, Arc, Polygon or Planar Set

##### Returns:

- Type:
    `number`
  distance from segment to shape
- Type:
    `Segment`
  shortest segment between segment and shape (started at segment, ended at shape)

#### equalTo(seg) → {boolean}

Returns true if equals to query segment, false otherwise

Source:
  - classes/segment.js, line 139

##### Parameters:

Name | Type | Description
--- | --- | ---
`seg` | `Seg` | query segment

##### Returns:

Type:
  `boolean`

#### intersect(shape) → {Array.<Point>}

Returns array of intersection points between segment and other shape

Source:
  - classes/segment.js, line 157

##### Parameters:

Name | Type | Description
--- | --- | ---
`shape` | `Shape` | Shape of the one of supported types

##### Returns:

Type:
  `Array.<Point>`

#### isZeroLength() → {boolean}

Returns true if segment start is equal to segment end up to DP_TOL

Source:
  - classes/segment.js, line 349

##### Returns:

Type:
  `boolean`

#### middle() → {Point}

Return middle point of the segment

Source:
  - classes/segment.js, line 281

##### Returns:

Type:
  `Point`

#### pointAtLength(length) → {Point}

Get point at given length

Source:
  - classes/segment.js, line 290

##### Parameters:

Name | Type | Description
--- | --- | ---
`length` | `number` | The length along the segment

##### Returns:

Type:
  `Point`

#### reverse() → {Segment}

Returns new segment with swapped start and end points

Source:
  - classes/segment.js, line 253

##### Returns:

Type:
  `Segment`

#### rotate(angle, center) → {Segment}

Return new segment rotated by given angle around given point If point omitted, rotate around origin (0,0) Positive value of angle defines rotation counter clockwise, negative - clockwise

Source:
  - classes/segment.js, line 330

##### Parameters:

Name | Type | Default | Description
--- | --- | --- | ---
`angle` | `number` | 0 | rotation angle in radians
`center` | `Point` |  | center point, default is (0,0)

##### Returns:

Type:
  `Segment`

#### sortPoints(pts) → {Array.<Point>}

Sort given array of points from segment start to end, assuming all points lay on the segment

Source:
  - classes/segment.js, line 358

##### Parameters:

Name | Type | Description
--- | --- | ---
`pts` | `Array.<Point>` | array of points

##### Returns:

Type:
  `Array.<Point>`

new array sorted

#### split(pt) → {Array.<Segment>}

When point belongs to segment, return array of two segments split by given point, if point is inside segment. Returns clone of this segment if query point is incident to start or end point of the segment. Returns empty array if point does not belong to segment

Source:
  - classes/segment.js, line 264

##### Parameters:

Name | Type | Description
--- | --- | ---
`pt` | `Point` | Query point

##### Returns:

Type:
  `Array.<Segment>`

#### svg(attrs) → {string}

Return string to draw segment in svg

Source:
  - classes/segment.js, line 379

##### Parameters:

Name | Type | Description
--- | --- | ---
`attrs` | `Object` | an object with attributes for svg path element, like "stroke", "strokeWidth" Defaults are stroke:"black", strokeWidth:"1"

##### Returns:

Type:
  `string`

#### tangentInEnd() → {Vector}

Return unit vector in the direction from end to start

Source:
  - classes/segment.js, line 244

##### Returns:

Type:
  `Vector`

#### tangentInStart() → {Vector}

Returns unit vector in the direction from start to end

Source:
  - classes/segment.js, line 235

##### Returns:

Type:
  `Vector`

#### toJSON() → {Object}

This method returns an object that defines how data will be serialized when called JSON.stringify() method

Source:
  - classes/segment.js, line 368

##### Returns:

Type:
  `Object`

#### transform(matrix) → {Segment}

Return new segment transformed using affine transformation matrix

Source:
  - classes/segment.js, line 341

##### Parameters:

Name | Type | Description
--- | --- | ---
`matrix` | `Matrix` | affine transformation matrix

##### Returns:

Type:
  `Segment`

- transformed segment

#### translate(vec) → {Segment}

Returns new segment translated by vector vec

Source:
  - classes/segment.js, line 318

##### Parameters:

Name | Type | Description
--- | --- | ---
`vec` | `Vector` |

##### Returns:

Type:
  `Segment`