Skip to content

Commit aef7746

Browse files
author
Andrea Ghensi
committed
fix closest_point_on_segment_xy
fixes #837
1 parent 75072d9 commit aef7746

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@
3030
- Xingxin He <<[email protected]>> [@XingxinHE](https://github.com/XingxinHE)
3131
- Robin Godwyll <<[email protected]>> [@robin-gdwl](https://github.com/robin-gdwl)
3232
- Mattis Koh <<[email protected]>> [@mattiskoh](https://github.com/mattiskoh)
33+
- Andrea Ghensi <<[email protected]>> [@sanzoghenzo](https://github.com/sanzoghenzo)

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
* Changed directory where ghuser components are installed.
2626
* Added ghuser components directory to those removed by the `clean` task.
2727
* Clean up the ghuser directory before building ghuser components.
28+
* Fixed bug in `compas.geometry.distance.closest_point_on_segment_xy`
2829

2930
### Removed
3031

src/compas/geometry/_core/distance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,8 @@ def closest_point_on_segment_xy(point, segment):
764764
d2 = distance_point_point_sqrd_xy(b, p)
765765
if d1 > d or d2 > d:
766766
if d1 < d2:
767-
return a
768-
return b
767+
return [a[0], a[1], 0.0]
768+
return [b[0], b[1], 0.0]
769769
return p
770770

771771

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from compas.geometry import Point
2+
from compas.geometry import Line
3+
from compas.geometry import closest_point_on_segment_xy
4+
5+
6+
def test_closest_point_segment_xy():
7+
point = Point(0, 0, -10)
8+
line = Line([1, 1, -15], [10, 10, 20])
9+
ponl = closest_point_on_segment_xy(point, line)
10+
assert ponl == Point(1, 1, 0)

0 commit comments

Comments
 (0)