Skip to content

Commit 5b394cb

Browse files
committed
Step 7.22: Add line-circle intersection method
1 parent c692698 commit 5b394cb

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

resources/cpp/src/geometry/line.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../nullable.h"
55
#include "../utils.h"
66
#include "point.h"
7+
#include "circle.h"
78
#include "line.h"
89

910
namespace geometry {
@@ -100,6 +101,11 @@ namespace geometry {
100101
return Nullable<Point>();
101102
}
102103

104+
// circle - circle intersection method
105+
Nullable<std::vector<Point>> Line::getIntersection(Circle circle) {
106+
return circle.getIntersection(*this);
107+
}
108+
103109
emscripten::val EMLine::getMatchingX(double y) {
104110
Nullable<double> nullableX = Line::getMatchingX(y);
105111
return nullableX.hasValue() ?
@@ -126,6 +132,10 @@ namespace geometry {
126132
emPoint.set("y", emscripten::val(point.y));
127133
return emPoint;
128134
}
135+
136+
emscripten::val EMLine::getIntersection(EMCircle emCircle) {
137+
return emCircle.getIntersection(*this);
138+
}
129139
}
130140

131141
EMSCRIPTEN_BINDINGS(geometry_line_module) {
@@ -146,5 +156,10 @@ EMSCRIPTEN_BINDINGS(geometry_line_module) {
146156
emscripten::select_overload<emscripten::val(geometry::EMLine)>(
147157
&geometry::EMLine::getIntersection
148158
)
159+
)
160+
.function("getCircleIntersection",
161+
emscripten::select_overload<emscripten::val(geometry::EMCircle)>(
162+
&geometry::EMLine::getIntersection
163+
)
149164
);
150165
}

resources/cpp/src/geometry/line.h

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <emscripten/val.h>
55
#include "../nullable.h"
66
#include "point.h"
7+
#include "circle.h"
78

89
namespace geometry {
910
class Circle;
@@ -27,6 +28,8 @@ namespace geometry {
2728
bool boundsHavePoint(double x, double y);
2829

2930
Nullable<Point> getIntersection(Line line);
31+
32+
Nullable<std::vector<Point>> getIntersection(Circle circle);
3033
};
3134

3235
class EMLine : public Line {
@@ -38,5 +41,7 @@ namespace geometry {
3841
emscripten::val getMatchingY(double x);
3942

4043
emscripten::val getIntersection(EMLine line);
44+
45+
emscripten::val getIntersection(EMCircle circle);
4146
};
4247
}

resources/scripts/engine/geometry/line.js

-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ Engine.Geometry.Line = class Line extends Utils.proxy(CPP.Geometry.Line) {
1414
return this.getPolygonIntersection(shape);
1515
}
1616

17-
// line - circle intersection method
18-
getCircleIntersection(circle) {
19-
return circle.getLineIntersection(this);
20-
}
21-
2217
// line - polygon intersection method
2318
getPolygonIntersection(polygon) {
2419
return polygon.getLineIntersection(this);

0 commit comments

Comments
 (0)