# Point2

class Point2()

Constructors

- `constructor()`

Properties

- `x`

- `y`

Methods

- `add()`

- `assign()`

- `copy()`

- `equals()`

- `length()`

- `scale()`

- `set()`

- `squaredLength()`

- `subtract()`

- `toJson()`

- `distance()`

- `fromJson()`

- `fromPoint3()`

- `zero()`

## Constructors

Point2.constructor(x, y)
  Arguments

    - x (`number()`) – value to set for x

    - y (`number()`) – value to set for y

  Creates a new point

  Return type

    Point2

## Properties

Point2.x
  Type

    number

Point2.y
  Type

    number

## Methods

### static add

Point2.add(pt1, pt2)
  Arguments

    - pt1 (`Point2()`) – initial point

    - pt2 (`Point2()`) – the point to add

  Adds two points

  Returns

    new point set to pt1 + pt2

  Return type

    Point2

### assign

Point2.assign(pt)
  Arguments

    - pt (`Point2()`) – the point whose values will be used to set this object

  Sets this point equal to another point

  Returns

    the point object

  Return type

    this

### copy

Point2.copy()

  Creates a copy of this point

  Returns

    Copy of this point

  Return type

    Point2

### equals

Point2.equals(pt)
  Arguments

    - pt (`Point2()`) – the point to compare with

  Compares this point with another point

  Returns

    True if the values of this point equal the other. False otherwise.

  Return type

    boolean

### length

Point2.length()

  Returns the length of this point

  Returns

    the point length

  Return type

    number

### static scale

Point2.scale(pt, k)
  Arguments

    - pt (`Point2()`) – Point to be scaled

    - k (`number()`) – Amount to scale by

  Scale a point by a constant factor

  Returns

    The scaled point

  Return type

    Point2

### set

Point2.set(x, y)
  Arguments

    - x (`number()`) – value to set for x

    - y (`number()`) – value to set for y

  Sets the values of this point

  Returns

    the point object

  Return type

    this

### squaredLength

Point2.squaredLength()

  Returns the squared length of this vector.

  Returns

    Vector squared length.

  Return type

    number

### static subtract

Point2.subtract(pt1, pt2)
  Arguments

    - pt1 (`Point2()`) – initial point

    - pt2 (`Point2()`) – the point to subtract

  Subtracts a point from another

  Returns

    new point set to pt1 - pt2

  Return type

    Point2

### toJson

Point2.toJson()

  Creates an object ready for JSON serialization.

  Returns

    The prepared object.

  Return type

    IPoint2

### static distance

Point2.distance(p1, p2)
  Arguments

    - p1 (`Point2()`) – first point

    - p2 (`Point2()`) – second point

  Calculate distance between two points

  Returns

    the distance between p1 and p2

  Return type

    number

### static fromJson

Point2.fromJson(objData)
  Arguments

    - objData (`unknown()`) – An object given by [[toJson]].

  Creates a new [[Point2]] from an object given by [[toJson]].

  Returns

    The prepared object.

  Return type

    Point2

### static fromPoint3

Point2.fromPoint3(p)
  Arguments

    - p (`IPoint3()`) – None

  Return type

    Point2

### static zero

Point2.zero()

  Creates a point initialized to (0,0)

  Returns

    The new point

  Return type

    Point2