-
Notifications
You must be signed in to change notification settings - Fork 41
point arithmetic #136
Comments
Point is an abstract vector, so this is kind of expected. I'd say if you want your point to be treated as a scalar in a given broadcasting operation, just wrap it in a Ref or tuple: julia> [Point(1,1), Point(2,2), Point(3,3)] .- (Point(1, -1),)
3-element Array{Point{2,Int64},1}:
[0, 2]
[1, 3]
[2, 4] That seems pretty consistent with the v0.7 way of forcing users to be somewhat explicit about what should be a "scalar" in a given broadcasting operation. |
I see what you're saying, but what is more common: 1) given three points A, B, and P, wanting to add the x-coordinate of point P to both the x and y coordinates of point A, while also adding the y-coordinate of point P to the x and y coordinates of point B, or 2) wanting to add a point to a list of other points (i.e. translating a polygon)? Does that first operation really make sense in the context of cartesian geometry? I guess I'm asking, would you ever want a point to broadcast as anything but a scalar? Perhaps I'm missing an obvious use case. |
No, I think that's a reasonable question. I would venture that specifically overriding broadcasting for the case of Perhaps you could try defining |
I very much agree. Personally, I would gladly have |
I'm not sure if modifying this would help with other operations, like * and /? As of now I don't see a way of scaling an array of Points (or Vecs) by a Vec: |
There are a few surprises (at least to me) that can happen with broadcasted Point arithmetic:
I would have instead expected:
One possible fix on julia 0.7 is to define something like:
Though I haven't thought through the broader implications, this is how I'm getting around the problem in a package I have that defines its own Point types. I'd much rather use the Point type defined here so that I can have compatibility with your visualization packages.
The text was updated successfully, but these errors were encountered: