Segment2D

interface Segment2D<P : Vector2D<P>>(source)

Defines a line segment in a cartesian plane, endpoints are included.

Inheritors

Properties

Link copied to clipboard
abstract val first: P

The first endpoint of the segment.

Link copied to clipboard

Indicates if the two endpoints coincide (= segment has zero length).

Link copied to clipboard

Indicates if the segment is aligned to the x-axis, this is true if isDegenerate.

Link copied to clipboard

Indicates if the segment is aligned to the y-axis, this is true if isDegenerate.

Link copied to clipboard
open val length: Double

The length of the segment.

Link copied to clipboard
open val midPoint: P

The medium point of the segment.

Link copied to clipboard
abstract val second: P

The second endpoint of the segment.

Link copied to clipboard
open val toVector: P

The vector representing the movement from first to second.

Functions

Link copied to clipboard
open fun closestPointTo(point: P): P

Finds the point of the segment which is closest to the provided point.

Link copied to clipboard
open fun contains(point: P): Boolean

Checks if the segment contains a point.

Link copied to clipboard
abstract fun copyWith(first: P = this.first, second: P = this.second): Segment2D<P>

Creates a copy of this Segment2D using the specified first and second points.

Link copied to clipboard
open fun distanceTo(point: P): Double

Computes the shortest distance between the segment and the given point.

open fun distanceTo(other: Segment2D<P>): Double

Computes the shortest distance between two segments (= the shortest distance between any two of their points).

Link copied to clipboard
open fun intersect(other: Segment2D<P>): Intersection2D<P>

Intersects two segments.

Link copied to clipboard
open fun intersectCircle(center: P, radius: Double): Intersection2D<P>

Intersects a segment and a circle.

Link copied to clipboard
open fun isCollinearWith(point: P): Boolean

Checks if first, second and point lie on a single line.

open fun isCollinearWith(other: Segment2D<P>): Boolean

Checks if two segments lie on a single line.

Link copied to clipboard
open fun isInRectangle(origin: Vector2D<*>, width: Double, height: Double): Boolean

Checks if this segment is inside a rectangular region described by an origin, width and height (must be positive).

Link copied to clipboard
open fun isParallelTo(other: Segment2D<P>): Boolean

Checks if two segments are parallel. Throws an UnsupportedOperationException if any of the two segment isDegenerate.

Link copied to clipboard
open fun overlapsWith(other: Segment2D<P>): Boolean

Checks if two segments overlap (= are collinear and share one or more points).

Link copied to clipboard
open fun shrunk(factor: Double): Segment2D<P>
Link copied to clipboard
open fun toLine(): Line2D<P>
Link copied to clipboard
open fun toRange(getXCoords: Boolean = this.isHorizontal): ClosedRange<Double>

Maps the segment a ClosedRange, this is done by extracting either the X coordinates or the Y coordinates of the two endpoints of the segment. getXCoords indicates which pair of coordinates should be extracted (defaults to isHorizontal). This can be useful e.g. to represent portions of axis-aligned segments without creating new ones.