compas-dev / compas-dev/compas

[Discussion] Type-consistent through basic math operation

Open
#1,345 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
386
Forks
122
Avg merge
11d 46m
Merged PRs (30d)
1

Description

**Case 1**:
In the documentation: https://compas.dev/compas/latest/userguide/basics.geometry.points_and_vectors.html

We have:
![image](https://github.com/compas-dev/compas/assets/1921878/8a50dc55-d9ea-408d-91d3-7efacb02d1f6)

The different resulting types of `+` and `-` for `Point` looks quite strange to me at the beginning...
It is understandable after a bit of thinking that `-` for point should result a "vector" as it means direction from `p0` to ` p1`.

However, as a basic geometry library, it is recommended to make types consistent across such basic math operations, rather than "interpret" it subjectively -- this may lead to unexpected errors and increase maintenance cost.

**Case 2**:
Another scenario may happen is when I have a `p0` from some computation, and would like to use the corresponding `v0` so that I can use methods in the `compas.Vector` class.

Currently there is no provided method in `compas` for doing sth like `v0 = Vector(p0)` or `v0 = p0.CastToVector()`.

### Recommendation
Perhaps such cases are due to a legacy where "type" was not considered as a first-class citizen in Python development...
I would however recommend to unify the types and make the computation more consistent.

For the math operations, following approach could be an option:
1. Make computation within each `type` constant.
2. Provide casting methods like `v0 = p0.CastToVector()`, or `v0 = p0.CastToVector()`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.