Skip to content

Commit

Permalink
feat: static toJSON method
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Mar 3, 2020
1 parent 87ba363 commit bd8e944
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/x6/src/geometry/point.ts
Expand Up @@ -350,6 +350,18 @@ export namespace Point {
return new Point(p.x, p.y)
}

export function toJSON(p: Point | PointLike | PointData) {
if (p instanceof Point) {
return { x: p.x, y: p.y }
}

if (Array.isArray(p)) {
return { x: p[0], y: p[1] }
}

return { x: p.x, y: p.y }
}

/**
* Returns a new Point object from the given polar coordinates.
* @see http://en.wikipedia.org/wiki/Polar_coordinate_system
Expand Down

0 comments on commit bd8e944

Please sign in to comment.