Skip to content
LibItsSecurity_Functions.ttcn3 64.2 KiB
Newer Older
            * @param p_latlon  The latitude/longitude: (N|S|E|W)
            * @return The decimal coordinate on success, 0.0, otherwise
            * @verdict Unchanged
            */
            external function fx_dms2dd(in Int p_degrees, in Int p_minutes, in float p_seconds, in Oct1 p_latlon) return float;
        } // End of group geodesic
        
    } // End of group externalFunctions
    
filatov's avatar
filatov committed
    group geometryFunctions {
        
        /**
        * @desc    Check that given location is valid
        * @param   p_location    location to be checked
        * @return  true on success, false otherwise
        */
        function f_isValidTwoDLocation(
garciay's avatar
garciay committed
                                       in template (value) TwoDLocation p_location
filatov's avatar
filatov committed
        ) return boolean {
garciay's avatar
garciay committed
                (valueof(p_location).longitude != c_maxLongitude + 1) and
                (valueof(p_location).latitude != c_maxLatitude + 1);
        } // End of function f_isValidTwoDLocation
filatov's avatar
filatov committed
        /**
        * @desc    Check that two given rectanlular regions are intersected
        *          Note: Regions must be normalized(northwest.latitude >= southeast.latitude)
        *          TODO: Add case when
        * @param   p_r1    Region 1
        * @param   p_r2    Region 2
        *
        * @return  true on success, false otherwise
        */
        function f_isRectangularRegionsIntersected(
garciay's avatar
garciay committed
                                                   in template (value) RectangularRegion p_r1,
                                                   in template (value) RectangularRegion p_r2
        ) return boolean {
garciay's avatar
garciay committed
            return not (
                valueof(p_r2).northwest.longitude > valueof(p_r1).southeast.longitude or 
                valueof(p_r2).southeast.longitude < valueof(p_r1).northwest.longitude or 
                valueof(p_r2).southeast.latitude  > valueof(p_r1).northwest.latitude or 
                valueof(p_r2).northwest.latitude  < valueof(p_r1).southeast.latitude
            );
        } // End of function f_isRectangularRegionsIntersected
filatov's avatar
filatov committed
        
garciay's avatar
garciay committed
        function f_isContinuousRectangularRegions(
                                                  in template (value) RectangularRegions regions
filatov's avatar
filatov committed
        ) return boolean {
filatov's avatar
filatov committed
            // TODO: call external function
filatov's avatar
filatov committed
            return true;
        } // End of function f_isRectangularRegionsIntersected
        
        /**
        * @desc Check if a polygonal regin is inside another one
        * @param p_parent  The main polygonal region
        * @param p_region  The polygonal region to be included
        * @return true on success, false otherwise
        * @verdict Unchanged
        */
        function f_isRectangularRegionsInside(
garciay's avatar
garciay committed
                                              in template (value) RectangularRegions p_parent,
                                              in template (value) RectangularRegions p_region
        ) return boolean {
            // TODO: convert rectangular regions to polygons and check polygons
filatov's avatar
filatov committed
            return true;
        } // End of function f_isRectangularRegionsInside
        * @desc    Check that given polygon doesn't have neither self-intersections nor holes.
        * @param   p_region   Polygonal Region
        * @return  true on success, false otherwise
        * @verdict Unchanged
        */
        function f_isValidPolygonalRegion(
            in template (value) PolygonalRegion p_region
filatov's avatar
filatov committed
        ) return boolean {
            // Sanity check
            if (not isbound(p_region) or (lengthof(p_region) == 0)) {
                return false;
            }
            
garciay's avatar
garciay committed
            return fx_isValidPolygonalRegion(valueof(p_region));
        } // End of function f_isValidPolygonalRegion
        * @desc Check if a polygonal regin is inside another one
        * @param p_parent  The main polygonal region
        * @param p_region  The polygonal region to be included
        * @return true on success, false otherwise
        * @verdict Unchanged
        */
        function f_isPolygonalRegionInside(
garciay's avatar
garciay committed
                                           in template (value) PolygonalRegion p_parent,
                                           in template (value) PolygonalRegion p_region
filatov's avatar
filatov committed
        ) return boolean {
            // Sanity check
            if (not isbound(p_parent) or not isbound(p_region) or (lengthof(p_parent) == 0) or (lengthof(p_region) == 0)) {
                return false;
            }
            
            return fx_isPolygonalRegionInside(valueof(p_parent), valueof(p_region));
        } // End of function f_isPolygonalRegionInside
garciay's avatar
garciay committed
        
        * @desc
        */
        function f_isIdentifiedRegionInside(
garciay's avatar
garciay committed
                                            in template (value) UInt16 p_parent,
                                            in template (value) UInt16 p_region
        ) return boolean {
garciay's avatar
garciay committed
            return valueof(p_parent) == valueof(p_region);
        } // End of function f_isIdentifiedRegionInside
garciay's avatar
garciay committed
        
        * @desc Check that the location is inside a region
        * @param p_region      The region to consider
        * @param p_location    The device location
        * @return true on success, false otherwise
        * @verdict Unchanged
        */
        function f_isLocationInsideRegion(
garciay's avatar
garciay committed
                                          in template (value) GeographicRegion p_region,
                                          in template (value) ThreeDLocation p_location
        ) return boolean {
            var boolean v_ret := false;
            select (p_region.region_type) {
                case (e_none) {
                    v_ret := true;
                }
                case (e_circle) {
                    v_ret := f_isLocationInsideCircularRegion(p_region.region.circular_region, p_location);
                case (e_rectangle) {
                    v_ret := f_isLocationInsideRectangularRegion(p_region.region.rectangular_region, p_location);
                case (e_polygon) {
                    v_ret := f_isLocationInsidePolygonalRegion(p_region.region.polygonal_region, p_location);
                case (e_id) {
                    v_ret := f_isLocationInsideIdentifiedRegion(p_region.region.id_region, p_location);
                case else {
                    v_ret := f_isLocationInsideOtherRegion(p_region.region.other_region, p_location);
        } // End of function f_isLocationInsideRegion
        
        /**
        * @desc Check that the location is inside a circular region
        * @param p_region      The circular region to consider
        * @param p_location    The device location
        * @return true on success, false otherwise
        * @verdict Unchanged
        */
garciay's avatar
garciay committed
        function f_isLocationInsideCircularRegion(
                                                  in template (value) CircularRegion p_region,
                                                  in template (value) ThreeDLocation p_location
        ) return boolean {
            // Sanity check
            if (not isbound(p_region) or not isbound(p_location)) {
                return false;
            }
            
garciay's avatar
garciay committed
            return fx_isLocationInsideCircularRegion(valueof(p_region), valueof(p_location));
        } // End of function f_isLocationInsideCircularRegion
        
        /**
        * @desc Check that the location is inside a rectangular region
        * @param p_region      The rectangular region to consider
        * @param p_location    The device location
        * @return true on success, false otherwise
        * @verdict Unchanged
        */
        function f_isLocationInsideRectangularRegion(
garciay's avatar
garciay committed
                                                     in template (value) RectangularRegions p_region,
                                                     in template (value) ThreeDLocation p_location
        ) return boolean {
            // Sanity check
            if (not isbound(p_region) or not isbound(p_location) or (lengthof(p_region) == 0)) {
                return false;
            }
garciay's avatar
garciay committed
//            log("f_isLocationInsideRectangularRegion: p_polygonalArea: ", p_region);
//            log("f_isLocationInsideRectangularRegion: p_location: ", p_location);
garciay's avatar
garciay committed
            return fx_isLocationInsideRectangularRegion(valueof(p_region), valueof(p_location));
        } // End of function f_isLocationInsideRectangularRegion
        
        /**
        * @desc Check that the location is inside a polygonal region
        * @param p_region      The polygonal region to consider
        * @param p_location    The device location
        * @return true on success, false otherwise
        * @verdict Unchanged
        */
        function f_isLocationInsidePolygonalRegion(
garciay's avatar
garciay committed
                                                   in template (value) PolygonalRegion  p_region,
                                                   in template (value) ThreeDLocation p_location
        ) return boolean {
            // Sanity check
            if (not isbound(p_region) or not isbound(p_location) or (lengthof(p_region) == 0)) {
                return false;
            }
//            log("f_isLocationInsidePolygonalRegion: p_polygonalArea: ", p_region, " - ", valueof(p_region));
//            log("f_isLocationInsidePolygonalRegion: p_location: ", p_location, " - ", valueof(p_location));
garciay's avatar
garciay committed
            return fx_isLocationInsidePolygonalRegion(valueof(p_region), valueof(p_location));
        } // End of function f_isLocationInsidePolygonalRegion
        
        /**
        * @desc Check if the location is inside an identified region
        * @param p_region      The identified region to consider
        * @param p_location    The device location
        * @return true on success, false otherwise
        * @verdict Unchanged
        */
        function f_isLocationInsideIdentifiedRegion(
garciay's avatar
garciay committed
                                                    in template (value) IdentifiedRegion p_region,
                                                    in template (value) ThreeDLocation p_location
        ) return boolean {
            // Sanity check
            if (not isbound(p_region) or not isbound(p_location)) {
                return false;
            }
            
garciay's avatar
garciay committed
            return fx_isLocationInsideIdentifiedRegion(valueof(p_region), valueof(p_location));
        } // End of function f_isLocationInsideIdentifiedRegion
        
        /**
        * @desc Check if the location is inside an undefined region
        * @param p_region      The identified region to consider
        * @param p_location    The device location
        * @return true on success, false otherwise
        * @verdict Unchanged
        */
        function f_isLocationInsideOtherRegion(
garciay's avatar
garciay committed
                                               in template (value) octetstring p_region,
                                               in template (value) ThreeDLocation p_location
        ) return boolean {
            // FIXME To be removed
        } // End of function f_isLocationInsideOtherRegion
        
        * @desc Convert a spacial coordinate from DMS to Dms
        * @param p_degrees The degrees (D)
        * @param p_minutes The minutes (M)
        * @param p_seconds The seconds (S)
        * @param p_latlon  The latitude/longitude: (N|S|E|W)
        * @return The decimal coordinate on success, 0.0, otherwise
        * @verdict Unchanged
        */
        function f_dms2dd(
garciay's avatar
garciay committed
                          in integer p_degrees,
                          in integer p_minutes,
                          in float p_seconds,
                          in charstring p_latlon
        ) return float {
            var Oct1 v_latlon;
            
            // Sanity checks
            if (lengthof(p_latlon) != 1) {
                return 0.0;
            } else if ((p_latlon != "N") and (p_latlon != "S") and (p_latlon != "E") and (p_latlon != "W")) {
                return 0.0;
            }
            v_latlon := char2oct(p_latlon);
            return fx_dms2dd(p_degrees, p_minutes, p_seconds, v_latlon);
        } // End of function f_dms2dd
        
        /**
        * @desc Convert the latitude from float to int
        * @param p_latitude The latitude to be converted. Significand length shall be 7 digits length
        * @return The converted latitude
        * @verdict Unchanged
        */
garciay's avatar
garciay committed
        function f_ddlat2int(
                             in float p_latitude
        ) return WGSLatitude {
            return float2int(p_latitude * 10000000.0); // Significand length shall be 7 digits length
        }
        
        /**
        * @desc Convert the longitude from float to int
        * @param p_longitude The longitude to be converted. Significand length shall be 6 digits length
        * @return The converted longitude
        * @verdict Unchanged
        */
garciay's avatar
garciay committed
        function f_ddlon2int(
                             in float p_longitude
        ) return WGSLongitude {
            return float2int(p_longitude * 1000000.0); // Significand length shall be 6 digits length
        }
        
    } // End of group geometryFunctions
filatov's avatar
filatov committed
    
} // End of module LibItsSecurity_Functions