1pub mod rules;
32
33#[cxx::bridge(namespace = "maliput::api")]
34#[allow(clippy::missing_safety_doc)]
35pub mod ffi {
36 struct ConstLanePtr {
39 pub lane: *const Lane,
40 }
41 struct MutIntersectionPtr {
44 pub intersection: *mut Intersection,
45 }
46 struct ConstLaneSRangeRef<'a> {
49 pub lane_s_range: &'a LaneSRange,
50 }
51
52 unsafe extern "C++" {
53 include!("api/api.h");
54 include!("cxx_utils/error_handling.h");
55
56 #[namespace = "maliput::math"]
57 type Vector3 = crate::math::ffi::Vector3;
58 #[namespace = "maliput::math"]
59 type Quaternion = crate::math::ffi::Quaternion;
60 #[namespace = "maliput::math"]
61 type Matrix3 = crate::math::ffi::Matrix3;
62 #[namespace = "maliput::math"]
63 type RollPitchYaw = crate::math::ffi::RollPitchYaw;
64 #[namespace = "maliput::api::rules"]
65 type RoadRulebook = crate::api::rules::ffi::RoadRulebook;
66 #[namespace = "maliput::api::rules"]
67 type TrafficLightBook = crate::api::rules::ffi::TrafficLightBook;
68 #[namespace = "maliput::api::rules"]
69 type PhaseRingBook = crate::api::rules::ffi::PhaseRingBook;
70 #[namespace = "maliput::api::rules"]
71 type RuleRegistry = crate::api::rules::ffi::RuleRegistry;
72 #[namespace = "maliput::api::rules"]
73 type PhaseProvider = crate::api::rules::ffi::PhaseProvider;
74 #[namespace = "maliput::api::rules"]
75 type DiscreteValueRuleStateProvider = crate::api::rules::ffi::DiscreteValueRuleStateProvider;
76 #[namespace = "maliput::api::rules"]
77 type RangeValueRuleStateProvider = crate::api::rules::ffi::RangeValueRuleStateProvider;
78 #[namespace = "maliput::api::rules"]
79 type PhaseStateProviderQuery = crate::api::rules::ffi::PhaseStateProviderQuery;
80 #[namespace = "maliput::api::rules"]
81 type DiscreteValueRuleDiscreteValue = crate::api::rules::ffi::DiscreteValueRuleDiscreteValue;
82 #[namespace = "maliput::api::rules"]
83 type DiscreteValueRuleState = crate::api::rules::ffi::DiscreteValueRuleState;
84 #[namespace = "maliput::api::rules"]
85 type Phase = crate::api::rules::ffi::Phase;
86 #[namespace = "maliput::api::rules"]
87 type NextPhase = crate::api::rules::ffi::NextPhase;
88 #[namespace = "maliput::api::rules"]
89 type BulbState = crate::api::rules::ffi::BulbState;
90 #[namespace = "maliput::api::rules"]
91 type UniqueBulbId = crate::api::rules::ffi::UniqueBulbId;
92
93 #[namespace = "maliput::api"]
94 type RoadNetwork;
96 fn road_geometry(self: &RoadNetwork) -> *const RoadGeometry;
97 fn RoadNetwork_intersection_book(road_network: &RoadNetwork) -> *const IntersectionBook;
98 fn traffic_light_book(self: &RoadNetwork) -> *const TrafficLightBook;
99 fn rulebook(self: &RoadNetwork) -> *const RoadRulebook;
100 fn phase_ring_book(self: &RoadNetwork) -> *const PhaseRingBook;
101 fn rule_registry(self: &RoadNetwork) -> *const RuleRegistry;
102 fn RoadNetwork_phase_provider(road_network: &RoadNetwork) -> *const PhaseProvider;
103 fn RoadNetwork_discrete_value_rule_state_provider(
104 road_network: &RoadNetwork,
105 ) -> *const DiscreteValueRuleStateProvider;
106 fn RoadNetwork_range_value_rule_state_provider(
107 road_network: &RoadNetwork,
108 ) -> *const RangeValueRuleStateProvider;
109
110 type RoadGeometry;
112 fn RoadGeometry_id(road_geometry: &RoadGeometry) -> String;
113 fn num_junctions(self: &RoadGeometry) -> i32;
114 fn linear_tolerance(self: &RoadGeometry) -> f64;
115 fn angular_tolerance(self: &RoadGeometry) -> f64;
116 fn num_branch_points(self: &RoadGeometry) -> i32;
117 fn RoadGeometry_ToRoadPosition(
118 rg: &RoadGeometry,
119 inertial_position: &InertialPosition,
120 ) -> Result<UniquePtr<RoadPositionResult>>;
121 fn RoadGeometry_FindRoadPositions(
122 rg: &RoadGeometry,
123 inertial_position: &InertialPosition,
124 radius: f64,
125 ) -> Result<UniquePtr<CxxVector<RoadPositionResult>>>;
126 fn RoadGeometry_GetLane(rg: &RoadGeometry, lane_id: &String) -> ConstLanePtr;
127 fn RoadGeometry_GetLanes(rg: &RoadGeometry) -> UniquePtr<CxxVector<ConstLanePtr>>;
128 fn RoadGeometry_GetSegment(rg: &RoadGeometry, segment_id: &String) -> *const Segment;
129 fn RoadGeometry_GetJunction(rg: &RoadGeometry, junction_id: &String) -> *const Junction;
130 fn RoadGeometry_GetBranchPoint(rg: &RoadGeometry, branch_point_id: &String) -> *const BranchPoint;
131 fn RoadGeometry_BackendCustomCommand(rg: &RoadGeometry, command: &String) -> Result<String>;
132 fn RoadGeometry_GeoReferenceInfo(rg: &RoadGeometry) -> String;
133 type LanePosition;
135 fn LanePosition_new(s: f64, r: f64, h: f64) -> UniquePtr<LanePosition>;
136 fn s(self: &LanePosition) -> f64;
137 fn r(self: &LanePosition) -> f64;
138 fn h(self: &LanePosition) -> f64;
139 fn set_s(self: Pin<&mut LanePosition>, s: f64);
140 fn set_r(self: Pin<&mut LanePosition>, r: f64);
141 fn set_h(self: Pin<&mut LanePosition>, h: f64);
142 fn srh(self: &LanePosition) -> &Vector3;
143 fn set_srh(self: Pin<&mut LanePosition>, srh: &Vector3);
144 fn LanePosition_to_str(lane_pos: &LanePosition) -> String;
145
146 type InertialPosition;
148 fn InertialPosition_new(x: f64, y: f64, z: f64) -> UniquePtr<InertialPosition>;
149 fn x(self: &InertialPosition) -> f64;
150 fn y(self: &InertialPosition) -> f64;
151 fn z(self: &InertialPosition) -> f64;
152 fn set_x(self: Pin<&mut InertialPosition>, x: f64);
153 fn set_y(self: Pin<&mut InertialPosition>, y: f64);
154 fn set_z(self: Pin<&mut InertialPosition>, z: f64);
155 fn xyz(self: &InertialPosition) -> &Vector3;
156 fn set_xyz(self: Pin<&mut InertialPosition>, xyz: &Vector3);
157 fn length(self: &InertialPosition) -> f64;
158 fn Distance(self: &InertialPosition, other: &InertialPosition) -> f64;
159 fn InertialPosition_to_str(inertial_pos: &InertialPosition) -> String;
160 fn InertialPosition_operator_eq(lhs: &InertialPosition, rhs: &InertialPosition) -> bool;
161 fn InertialPosition_operator_sum(lhs: &InertialPosition, rhs: &InertialPosition)
162 -> UniquePtr<InertialPosition>;
163 fn InertialPosition_operator_sub(lhs: &InertialPosition, rhs: &InertialPosition)
164 -> UniquePtr<InertialPosition>;
165 fn InertialPosition_operator_mul_scalar(lhs: &InertialPosition, scalar: f64) -> UniquePtr<InertialPosition>;
166
167 type Lane;
169 fn to_left(self: &Lane) -> *const Lane;
170 fn to_right(self: &Lane) -> *const Lane;
171 fn index(self: &Lane) -> i32;
172 fn length(self: &Lane) -> f64;
173 fn Contains(self: &Lane, lane_position: &LanePosition) -> bool;
174 fn segment(self: &Lane) -> *const Segment;
175 fn Lane_id(lane: &Lane) -> String;
176 fn Lane_lane_bounds(lane: &Lane, s: f64) -> Result<UniquePtr<RBounds>>;
177 fn Lane_segment_bounds(lane: &Lane, s: f64) -> Result<UniquePtr<RBounds>>;
178 fn Lane_elevation_bounds(lane: &Lane, s: f64, r: f64) -> Result<UniquePtr<HBounds>>;
179 fn Lane_GetOrientation(lane: &Lane, lane_position: &LanePosition) -> Result<UniquePtr<Rotation>>;
180 fn Lane_ToInertialPosition(lane: &Lane, lane_position: &LanePosition) -> Result<UniquePtr<InertialPosition>>;
181 fn Lane_ToLanePosition(
182 lane: &Lane,
183 inertial_position: &InertialPosition,
184 ) -> Result<UniquePtr<LanePositionResult>>;
185 fn Lane_ToSegmentPosition(
186 lane: &Lane,
187 inertial_position: &InertialPosition,
188 ) -> Result<UniquePtr<LanePositionResult>>;
189 fn Lane_GetBranchPoint(lane: &Lane, start: bool) -> *const BranchPoint;
190 fn Lane_GetConfluentBranches(lane: &Lane, start: bool) -> Result<*const LaneEndSet>;
191 fn Lane_GetOngoingBranches(lane: &Lane, start: bool) -> Result<*const LaneEndSet>;
192 fn Lane_GetDefaultBranch(lane: &Lane, start: bool) -> UniquePtr<LaneEnd>;
193 fn Lane_EvalMotionDerivatives(
194 lane: &Lane,
195 lane_position: &LanePosition,
196 sigma_v: f64,
197 rho_v: f64,
198 eta_v: f64,
199 ) -> UniquePtr<LanePosition>;
200
201 type Segment;
203 fn num_lanes(self: &Segment) -> i32;
204 fn junction(self: &Segment) -> Result<*const Junction>;
205 fn lane(self: &Segment, index: i32) -> Result<*const Lane>;
206 fn Segment_id(segment: &Segment) -> String;
207
208 type Junction;
210 fn road_geometry(self: &Junction) -> *const RoadGeometry;
211 fn num_segments(self: &Junction) -> i32;
212 fn segment(self: &Junction, index: i32) -> Result<*const Segment>;
213 fn Junction_id(junction: &Junction) -> String;
214
215 type RoadPosition;
217 unsafe fn RoadPosition_new(lane: *const Lane, lane_pos: &LanePosition) -> UniquePtr<RoadPosition>;
221 fn RoadPosition_ToInertialPosition(road_position: &RoadPosition) -> Result<UniquePtr<InertialPosition>>;
222 fn RoadPosition_lane(road_position: &RoadPosition) -> *const Lane;
223 fn RoadPosition_pos(road_position: &RoadPosition) -> UniquePtr<LanePosition>;
224
225 type RoadPositionResult;
227 fn RoadPositionResult_road_position(result: &RoadPositionResult) -> UniquePtr<RoadPosition>;
228 fn RoadPositionResult_nearest_position(result: &RoadPositionResult) -> UniquePtr<InertialPosition>;
229 fn RoadPositionResult_distance(result: &RoadPositionResult) -> f64;
230
231 type LanePositionResult;
233 fn LanePositionResult_road_position(result: &LanePositionResult) -> UniquePtr<LanePosition>;
234 fn LanePositionResult_nearest_position(result: &LanePositionResult) -> UniquePtr<InertialPosition>;
235 fn LanePositionResult_distance(result: &LanePositionResult) -> f64;
236
237 type Rotation;
239 fn Rotation_new() -> UniquePtr<Rotation>;
240 fn Rotation_from_quat(q: &Quaternion) -> UniquePtr<Rotation>;
241 fn Rotation_from_rpy(rpy: &RollPitchYaw) -> UniquePtr<Rotation>;
242 fn roll(self: &Rotation) -> f64;
243 fn pitch(self: &Rotation) -> f64;
244 fn yaw(self: &Rotation) -> f64;
245 fn quat(self: &Rotation) -> &Quaternion;
246 fn Distance(self: &Rotation, other: &Rotation) -> f64;
247 fn Rotation_set_quat(r: Pin<&mut Rotation>, q: &Quaternion);
248 fn Rotation_rpy(r: &Rotation) -> UniquePtr<RollPitchYaw>;
249 fn Rotation_matrix(r: &Rotation) -> UniquePtr<Matrix3>;
250 fn Rotation_Apply(r: &Rotation, ip: &InertialPosition) -> UniquePtr<InertialPosition>;
251 fn Rotation_Reverse(r: &Rotation) -> UniquePtr<Rotation>;
252
253 type RBounds;
255 fn min(self: &RBounds) -> f64;
256 fn max(self: &RBounds) -> f64;
257
258 type HBounds;
260 fn min(self: &HBounds) -> f64;
261 fn max(self: &HBounds) -> f64;
262
263 type SRange;
265 fn SRange_new(s0: f64, s1: f64) -> UniquePtr<SRange>;
266 fn s0(self: &SRange) -> f64;
267 fn s1(self: &SRange) -> f64;
268 fn set_s0(self: Pin<&mut SRange>, s0: f64);
269 fn set_s1(self: Pin<&mut SRange>, s1: f64);
270 fn size(self: &SRange) -> f64;
271 fn WithS(self: &SRange) -> bool;
272 fn Intersects(self: &SRange, other: &SRange, tolerance: f64) -> bool;
273 fn Contains(self: &SRange, s_range: &SRange, tolerance: f64) -> bool;
274 fn SRange_GetIntersection(s_range: &SRange, other: &SRange, tolerance: f64) -> UniquePtr<SRange>;
275
276 type LaneSRange;
278 fn LaneSRange_new(lane_id: &String, s_range: &SRange) -> UniquePtr<LaneSRange>;
279 fn length(self: &LaneSRange) -> f64;
280 fn Intersects(self: &LaneSRange, other: &LaneSRange, tolerance: f64) -> bool;
281 fn Contains(self: &LaneSRange, lane_s_range: &LaneSRange, tolerance: f64) -> bool;
282 fn LaneSRange_lane_id(lane_s_range: &LaneSRange) -> String;
283 fn LaneSRange_s_range(lane_s_range: &LaneSRange) -> UniquePtr<SRange>;
284 fn LaneSRange_GetIntersection(
285 lane_s_range: &LaneSRange,
286 other: &LaneSRange,
287 tolerance: f64,
288 ) -> UniquePtr<LaneSRange>;
289
290 type LaneSRoute;
292 fn LaneSRoute_new(ranges: &CxxVector<ConstLaneSRangeRef>) -> UniquePtr<LaneSRoute>;
293 fn length(self: &LaneSRoute) -> f64;
294 fn Intersects(self: &LaneSRoute, other: &LaneSRoute, tolerance: f64) -> bool;
295 fn ranges(self: &LaneSRoute) -> &CxxVector<LaneSRange>;
296
297 type LaneEnd;
299 unsafe fn LaneEnd_new(lane: *const Lane, start: bool) -> UniquePtr<LaneEnd>;
305 fn LaneEnd_lane(lane_end: &LaneEnd) -> *const Lane;
306 fn LaneEnd_is_start(lane_end: &LaneEnd) -> bool;
307
308 type LaneEndSet;
310 fn size(self: &LaneEndSet) -> i32;
311 fn get(self: &LaneEndSet, index: i32) -> Result<&LaneEnd>;
312
313 type BranchPoint;
315 fn BranchPoint_id(branch_point: &BranchPoint) -> String;
316 fn road_geometry(self: &BranchPoint) -> *const RoadGeometry;
317 fn GetConfluentBranches(self: &BranchPoint, end: &LaneEnd) -> Result<*const LaneEndSet>;
318 fn GetOngoingBranches(self: &BranchPoint, end: &LaneEnd) -> Result<*const LaneEndSet>;
319 fn GetASide(self: &BranchPoint) -> *const LaneEndSet;
320 fn GetBSide(self: &BranchPoint) -> *const LaneEndSet;
321 fn BranchPoint_GetDefaultBranch(branch_point: &BranchPoint, end: &LaneEnd) -> UniquePtr<LaneEnd>;
322
323 type Intersection;
325 fn Intersection_id(intersection: &Intersection) -> String;
326 fn Intersection_Phase(intersection: &Intersection) -> UniquePtr<PhaseStateProviderQuery>;
327 fn region(self: &Intersection) -> &CxxVector<LaneSRange>;
328 fn Intersection_ring_id(intersection: &Intersection) -> String;
329 fn Intersection_unique_bulb_ids(intersection: &Intersection) -> UniquePtr<CxxVector<UniqueBulbId>>;
330 fn Intersection_bulb_state(intersection: &Intersection, bulb_id: &UniqueBulbId) -> UniquePtr<BulbState>;
331 fn Intersection_DiscreteValueRuleStates(
332 intersection: &Intersection,
333 ) -> UniquePtr<CxxVector<DiscreteValueRuleState>>;
334 fn Intersection_IncludesTrafficLight(intersection: &Intersection, traffic_light_id: &String) -> bool;
335 fn Intersection_IncludesDiscreteValueRule(intersection: &Intersection, rule_id: &String) -> bool;
336 fn Intersection_IncludesInertialPosition(
337 intersection: &Intersection,
338 inertial_position: &InertialPosition,
339 road_geometry: &RoadGeometry,
340 ) -> bool;
341
342 type IntersectionBook;
344 fn IntersectionBook_GetIntersection(book: &IntersectionBook, id: &String) -> MutIntersectionPtr;
345 fn IntersectionBook_GetIntersections(book: &IntersectionBook) -> UniquePtr<CxxVector<MutIntersectionPtr>>;
346 fn IntersectionBook_FindIntersectionTrafficLight(
347 book: &IntersectionBook,
348 traffic_light_id: &String,
349 ) -> MutIntersectionPtr;
350 fn IntersectionBook_FindIntersectionDiscreteValueRule(
351 book: &IntersectionBook,
352 rule_id: &String,
353 ) -> MutIntersectionPtr;
354 fn IntersectionBook_FindIntersectionInertialPosition(
355 book: &IntersectionBook,
356 inertial_position: &InertialPosition,
357 ) -> MutIntersectionPtr;
358
359 }
360 impl UniquePtr<RoadNetwork> {}
361 impl UniquePtr<LanePosition> {}
362}