Skip to content

Commit e97de92

Browse files
committed
unix port tweaks, starting test
1 parent 2ea3c38 commit e97de92

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

shared-bindings/vectorio/__init__.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ MP_DEFINE_CONST_FUN_OBJ_KW(vectorio_line_contains_point_obj, 0, vectorio_line_co
324324
//| y1: int,
325325
//| x2: int,
326326
//| y2: int,
327-
// cx: int, cy: int, cr: int
327+
//| cx: int,
328+
//| cy: int,
329+
//| cr: int,
330+
//| padding: float
328331
//| ) -> bool:
329332
//| """Checks whether a line intersects with a circle
330333
//|

shared-module/vectorio/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool common_hal_vectorio_line_contains_point(
106106
float d1 = measure_distance(x1, y1, px, py);
107107
float d2 = measure_distance(x2, y2, px, py);
108108

109-
if (d1 + d2 >= line_length - padding && d1 + d2 <= line_length + padding) {
109+
if (d1 + d2 >= line_length - (float)padding && d1 + d2 <= line_length + (float)padding) {
110110
return true;
111111
}
112112
return false;
@@ -125,12 +125,12 @@ bool common_hal_vectorio_line_circle_intersects(
125125
}
126126
float line_length = measure_distance(x1, y1, x2, y2);
127127

128-
float dot = (((cx - x1) * (x2 - x1)) + ((cy - y1) * (y2 - y1))) / pow(line_length, 2);
128+
float dot = (float)(((cx - x1) * (x2 - x1)) + ((cy - y1) * (y2 - y1))) / (float)pow(line_length, 2);
129129

130130
float closestX = x1 + (dot * (x2 - x1));
131131
float closestY = y1 + (dot * (y2 - y1));
132132

133-
if (!common_hal_vectorio_line_contains_point(x1, y1, x2, y2, closestX, closestY, padding)) {
133+
if (!common_hal_vectorio_line_contains_point(x1, y1, x2, y2, (int)closestX, (int)closestY, padding)) {
134134
return false;
135135
}
136136
float distance = measure_distance(closestX, closestY, cx, cy);

tests/vectorio/intersection.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import vectorio
2+
3+
args = (50, 50, 10, 50, 71, 10)
4+
print(f"circle circle validate False: {args}")
5+
print(vectorio.circle_circle_intersects(*args))
6+
7+
args = (50, 50, 10, 50, 70, 10)
8+
print(f"circle circle validate True: {args}")
9+
print(vectorio.circle_circle_intersects(*args))
10+
11+
args = (50, 50, 10, 50, 29, 10, 10)
12+
print(f"circle rectangle validate False: {args}")
13+
print(vectorio.circle_rectangle_intersects(*args))
14+
15+
args = (50, 50, 10, 50, 30, 10, 10)
16+
print(f"circle rectangle validate True: {args}")
17+
print(vectorio.circle_rectangle_intersects(*args))
18+
19+
args = (0, 0, 50, 50, 50, 60, 10)
20+
padding = 0.1
21+
print(f"line circle validate True: {args}, {padding}")
22+
print(vectorio.line_circle_intersects(*args, padding=padding))
23+
24+
args = (0, 0, 50, 50, 50, 61, 10)
25+
padding = 0.1
26+
print(f"line circle validate False: {args}, {padding}")
27+
print(vectorio.line_circle_intersects(*args, padding=padding))
28+
29+
args = ([(50, 0), (100, 0), (150, 50), (0, 50)], 0, 0, 161, 50, 10)
30+
padding = 0.1
31+
print(f"polygon circle validate False: {args}, {padding}")
32+
print(vectorio.polygon_circle_intersects(*args, padding=padding))
33+
34+
args = ([(50, 0), (100, 0), (150, 50), (0, 50)], 0, 0, 160, 50, 10)
35+
padding = 0.1
36+
print(f"polygon circle validate True: {args}, {padding}")
37+
print(vectorio.polygon_circle_intersects(*args, padding=padding))

0 commit comments

Comments
 (0)