2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-10-16 15:42:30 +02:00
|
|
|
title: Point.copy()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-02-19 08:04:25 +01:00
|
|
|
|
2021-10-16 15:42:30 +02:00
|
|
|
A point's `copy()` method returns a new point with the same coordinates as the original point.
|
2022-02-20 14:35:50 +01:00
|
|
|
This method does _not_ copy any attributes the original point may have.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-11-06 19:03:54 +01:00
|
|
|
## Point.copy() signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
Point point.copy()
|
|
|
|
```
|
|
|
|
|
2021-10-16 15:42:30 +02:00
|
|
|
<Note>
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-10-16 15:42:30 +02:00
|
|
|
###### Copy vs clone
|
|
|
|
|
|
|
|
this `Point.copy()` method will only copy the point's coordinates.
|
2022-08-20 18:07:26 -04:00
|
|
|
To also copy the attributes, use [`Point.clone()`](/reference/api/point/clone/) instead.
|
2021-10-16 15:42:30 +02:00
|
|
|
|
|
|
|
</Note>
|
|
|
|
|
2021-11-06 19:03:54 +01:00
|
|
|
## Point.copy() example
|
|
|
|
|
2022-01-19 11:31:39 +01:00
|
|
|
<Example part="point_copy">
|
|
|
|
An example of the Point.copy() method
|
|
|
|
</Example>
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
```js
|
|
|
|
let { Point, points, Snippet, snippets } = part.shorthand();
|
|
|
|
|
|
|
|
points.A = new Point(50, 25)
|
|
|
|
.attr("data-text", "Point A")
|
|
|
|
.attr("data-text-class", "text-xl");
|
|
|
|
points.B = points.A.copy().attr("data-text", "Point B");
|
|
|
|
|
|
|
|
snippets.x = new Snippet("notch", points.A);
|
|
|
|
```
|