@@ -22,10 +22,11 @@ void cross_sections_at_s(
2222void build_polygon_for_profile (float_type * const , const uint32_t , const Profile );
2323uint32_t find_aperture_info_for_s (const ApertureBounds , const float_type s , const uint32_t lower_bound );
2424
25- static inline float_type survey_s_for_aperture (const TypePosition , const ProfilePosition , const SurveyData , uint32_t * );
25+ static inline float_type survey_s_for_aperture (const TypePosition , const ProfilePosition , const float_type curvature , const SurveyData , uint32_t * );
2626static inline void bounds_on_s_for_aperture (
2727 const TypePosition ,
2828 const ProfilePosition ,
29+ const float_type curvature ,
2930 const SurveyData ,
3031 const Point2D * const ,
3132 const uint32_t num_poly_points ,
@@ -97,6 +98,7 @@ void build_profile_polygons(
9798 const TypePosition type_pos = ApertureModel_getp1_type_positions (model , type_pos_idx );
9899 const uint32_t type_idx = TypePosition_get_type_index (type_pos );
99100 const ApertureType aper_type = ApertureModel_getp1_types (model , type_idx );
101+ const float_type curvature = ApertureType_get_curvature (aper_type );
100102
101103 /* Get the profile position, and the polygon */
102104 const ProfilePosition profile_pos = ApertureType_getp1_positions (aper_type , profile_pos_idx );
@@ -107,13 +109,13 @@ void build_profile_polygons(
107109
108110 /* Get the survey s where the aperture actually sits */
109111 uint32_t installed_survey_index ;
110- const float_type found_s = survey_s_for_aperture (type_pos , profile_pos , survey , & installed_survey_index );
112+ const float_type found_s = survey_s_for_aperture (type_pos , profile_pos , curvature , survey , & installed_survey_index );
111113 ApertureBounds_set_s_positions (aperture_bounds , idx , found_s );
112114
113115 /* Get the bounds in s that the aperture spans */
114116 float_type min_s , max_s ;
115117 const Point2D * const profile_points = (Point2D * )poly ;
116- bounds_on_s_for_aperture (type_pos , profile_pos , survey , profile_points , num_points , installed_survey_index , & min_s , & max_s );
118+ bounds_on_s_for_aperture (type_pos , profile_pos , curvature , survey , profile_points , num_points , installed_survey_index , & min_s , & max_s );
117119 ApertureBounds_set_s_start (aperture_bounds , idx , min_s );
118120 ApertureBounds_set_s_end (aperture_bounds , idx , max_s );
119121 }
@@ -399,13 +401,13 @@ void cross_sections_at_s(
399401 We want to move to the type frame, so calculate the transformations
400402 */
401403 const Pose plane_in_world = pose_matrix_from_survey (survey_at_s , i );
402- // const Pose type_in_world = aperture_type_pose_in_world(type_pos, survey);
403- Pose type_in_world ;
404- for (int i = 0 ; i < 4 ; i ++ ) {
405- for (int j = 0 ; j < 4 ; j ++ ) {
406- type_in_world .mat [i ][j ] = TypePosition_get_transformation (type_pos , i , j );
407- }
408- }
404+ const Pose type_in_world = aperture_type_pose_in_world (type_pos , survey );
405+ // Pose type_in_world;
406+ // for (int i = 0; i < 4; i++) {
407+ // for (int j = 0; j < 4; j++) {
408+ // type_in_world.mat[i][j] = TypePosition_get_transformation(type_pos, i, j);
409+ // }
410+ // }
409411 const Pose world_in_type = pose_inverse_rigid (type_in_world );
410412 const Pose plane_in_type = matrix_multiply (world_in_type , plane_in_world );
411413 const Pose type_in_plane = pose_inverse_rigid (plane_in_type );
@@ -571,6 +573,7 @@ uint32_t find_aperture_info_for_s(
571573static inline float_type survey_s_for_aperture (
572574 const TypePosition type_pos ,
573575 const ProfilePosition profile_pos ,
576+ const float_type curvature ,
574577 const SurveyData survey ,
575578 uint32_t * found_survey_index
576579)
@@ -588,9 +591,7 @@ static inline float_type survey_s_for_aperture(
588591
589592 // Transformation from plane (s = 0) -> world
590593 Pose plane_in_world ;
591- // TODO: Include curvature and correct frame calculation
592- const Pose world_in_world = identity ();
593- aperture_profile_pose_frame (type_pos , profile_pos , 0 , survey , world_in_world , & plane_in_world );
594+ aperture_profile_pose_frame (type_pos , profile_pos , curvature , survey , identity (), & plane_in_world );
594595
595596 /*
596597 For data from MAD-X etc. it's likely that it's the type's reference survey point where the profile
@@ -601,16 +602,16 @@ static inline float_type survey_s_for_aperture(
601602 ZigZagIterator it = zigzag_iterator_new (survey_idx , 0 , num_survey_entries - 1 );
602603 do
603604 {
604- LineSegment3D segment = survey_segment (survey , it .index );
605+ Segment3D segment = survey_segment (survey , it .index );
605606 const Point3D plane_point = plane_initial_point (plane_in_world );
606607 const Point3D normal = plane_normal_vector (plane_in_world );
607- const float_type t = line_segment_plane_intersect (segment , plane_point , normal );
608+ const float_type t = segment3d_plane_intersect (segment , plane_point , normal );
608609 const float_type type_s = SurveyData_get_s (survey , it .index );
609610
610611 if (- eps <= t && t <= 1 + eps )
611612 {
612613 /* Current survey segment is intersected by the installed profile plane: compute the position. */
613- const float_type dist = t * segment_get_length (segment );
614+ const float_type dist = t * segment3d_get_length (segment );
614615 found_s = type_s + dist ;
615616 * found_survey_index = it .index ;
616617 break ;
@@ -624,6 +625,7 @@ static inline float_type survey_s_for_aperture(
624625static inline void bounds_on_s_for_aperture (
625626 const TypePosition type_pos ,
626627 const ProfilePosition profile_pos ,
628+ const float_type curvature ,
627629 const SurveyData survey ,
628630 const Point2D * const profile_points ,
629631 const uint32_t num_poly_points ,
@@ -642,18 +644,14 @@ static inline void bounds_on_s_for_aperture(
642644 segment (as opposed to being clamped to the edge points) we have found the right segment.
643645 This is a fair assumption as the diameter of a profile << radius of curvature of the survey,
644646 but if that is not the case, the bounds will not be correct.
645-
646- TODO: Handling of arcs, for now the algorithm deals with straight segments only.
647647*/
648648{
649649 const float_type eps = APER_PRECISION ;
650650 const uint32_t num_survey_entries = SurveyData_len_s (survey );
651651
652652 // Transformation profile local -> world frame
653653 Pose profile_in_world ;
654- // TODO: Include curvature and correct frame calculation
655- const Pose world_in_world = identity ();
656- aperture_profile_pose_frame (type_pos , profile_pos , 0 , survey , world_in_world , & profile_in_world );
654+ aperture_profile_pose_frame (type_pos , profile_pos , curvature , survey , identity (), & profile_in_world );
657655
658656 float_type out_min = INFINITY ;
659657 float_type out_max = - INFINITY ;
@@ -675,17 +673,13 @@ static inline void bounds_on_s_for_aperture(
675673 ZigZagIterator it = zigzag_iterator_new (installed_survey_index , 0 , num_survey_entries - 1 );
676674 do
677675 {
678- const LineSegment3D seg = survey_segment (survey , it .index );
679-
680- const Point3D a = seg .start ;
681- const Point3D b = seg .end ;
682-
683- const float_type t = closest_t_on_segment (pt_in_world , a , b );
676+ const Segment3D seg = survey_segment (survey , it .index );
677+ const float_type t = closest_t_on_segment (pt_in_world , seg );
684678
685679 if (- eps < t && t < 1 + eps ) {
686680 /* Candidate s on this segment */
687681 const float_type seg_s_start = SurveyData_get_s (survey , it .index );
688- const float_type seg_len = segment_get_length (seg );
682+ const float_type seg_len = segment3d_get_length (seg );
689683 closest_s = seg_s_start + t * seg_len ;
690684 break ;
691685 }
0 commit comments