Repository: lace/vg

Issue:
`vg.apex()` should copy instead of returning a view

Discussion:
now[bot]: 
This pull request is being automatically deployed with ZEIT Now ([learn more](https://zeit.co/docs/v2/integrations/now-for-github?utm_source=automated&utm_medium=github&utm_campaign=now_bot)).
To see the status of your deployment, click on the icon next to each commit.
	

Patch:
diff --git a/vg/core.py b/vg/core.py
index 0c3867b..273ddc9 100644
--- a/vg/core.py
+++ b/vg/core.py
@@ -503,14 +503,14 @@ def apex(points, along):
             interest.
 
     Returns:
-        np.ndarray: A `3x1` point taken from `points`.
+        np.ndarray: A copy of a point taken from `points`.
     """
     if points.ndim != 2 or points.shape[1] != 3:
         raise ValueError("Invalid shape %s: apex expects nx3" % (points.shape,))
     if along.shape != (3,):
         raise ValueError("along should be a 3x1 vector")
     coords_on_axis = points.dot(along)
-    return points[np.argmax(coords_on_axis)]
+    return points[np.argmax(coords_on_axis)].copy()
 
 
 def nearest(from_points, to_point, ret_index=False):


Test patch:
diff --git a/vg/test_apex.py b/vg/test_apex.py
index 478430c..605aa67 100644
--- a/vg/test_apex.py
+++ b/vg/test_apex.py
@@ -50,3 +50,23 @@ def test_apex():
 
     with pytest.raises(ValueError, match="along should be a 3x1 vector"):
         vg.apex(points, along=points)
+
+
+def test_apex_returns_a_copy():
+    points = np.array(
+        [
+            [-0.97418884, -0.79808404, -0.18545491],
+            [0.60675227, 0.32673201, -0.20369793],
+            [0.67040405, 0.19267665, -0.56983579],
+            [-0.68038753, -0.90011588, 0.4649872],
+            [-0.62813991, -0.23947753, 0.07933854],
+            [0.26348356, 0.23701114, -0.38230596],
+            [0.08302473, 0.2784907, 0.09308946],
+            [0.58695587, -0.33253376, -0.33493078],
+            [-0.39221704, -0.45240036, 0.25284163],
+            [0.46270635, -0.3865265, -0.98106526],
+        ]
+    )
+    result = vg.apex(points, along=vg.basis.x)
+    result[1] = 5.0
+    np.testing.assert_array_equal(points[2], [0.67040405, 0.19267665, -0.56983579])