omg_line
Overview & Purpose
omg_line manages survey planning lines (OMG_Line and OMG_Line_List), providing binary file persistence (.lines format), dual geographic/projected coordinate synchronization, and interactive 2D computational geometry operations. Designed primarily for interactive line planning in JView (JV) and exporting survey plans via line_export, the library supports adding, deleting, reversing, reordering, parallel-offsetting, splitting, extending, vertex-moving, joining, and clipping survey lines against a bounding clip segment.
Key Data Structures, Constants & Macros
Constants & Macros
OMG_LINE_VERSION_1_SIZE(32bytes): On-disk size of a single Version 1 line record (4 * sizeof(double)forlon1,lat1,lon2,lat2).OMG_LINE_LIST_VERSION_1(1): File format version identifier.OMG_LINE_INCREMENT(1) /OMG_LINE_DECREMENT(-1): Direction step constants forreorder_OMG_Lines.LEFT_OF_LINE(1) /RIGHT_OF_LINE(2): Offset side specifiers foradd_OMG_Line_Parallel.
Core Structs
OMG_Line: Represents a single directed two-point survey line segment:- Persistent geographic endpoints (stored on disk in little-endian IEEE 754 doubles):
lon1,lat1,lon2,lat2. - In-memory projected map/pixel coordinates (computed via
Project/inv_projusing aJHC_header):x1,y1,x2,y2.
- Persistent geographic endpoints (stored on disk in little-endian IEEE 754 doubles):
OMG_Line_List: Container for an ordered collection ofOMG_Linesegments:- On-disk header fields:
int version,int num_lines. - In-memory housekeeping: allocated capacity
size_lines,char *line_filename, dynamic arrayOMG_Line *lines, reference map projectionJHC_header map_header, andint selected_lineindex.
- On-disk header fields:
Public Functions & Signatures
Initialization, I/O & Projection
int init_OMG_Line(OMG_Line *line)/int reverse_OMG_Line(OMG_Line *line)/int print_OMG_Line(OMG_Line *line)- Zero-initializes a line, swaps its start and end vertices (
lat1/lon1/x1/y1$\leftrightarrow$lat2/lon2/x2/y2), or prints formatted degrees/decimal-minutes endpoints usingposition2string.
- Zero-initializes a line, swaps its start and end vertices (
int init_OMG_Line_List(OMG_Line_List *list)/int free_OMG_Line_List(OMG_Line_List *list)/int print_OMG_Line_List(OMG_Line_List *list)- Lifecycle and diagnostic output for
OMG_Line_List.
- Lifecycle and diagnostic output for
int set_OMG_Line_List_Projection(OMG_Line_List *list, JHC_header map_header)- Assigns the
JHC_headermap projection structure used to project geographic coordinates into pixel/grid space.
- Assigns the
OMG_Line_List read_OMG_Line_List(char *line_filename, JHC_header map_header)- Reads a binary
.linesfile (8-byte little-endian header ofversionandnum_lines, followed bynum_lines32-byte records oflon1, lat1, lon2, lat2), projecting each line upon insertion viaadd_OMG_Line.
- Reads a binary
int write_OMG_Line_List(OMG_Line_List *list)- Writes the
OMG_Line_Listtolist->line_filename(defaulting to"lines.lines"if unset) in little-endian binary format.
- Writes the
char *position2string(double lat, double lon)- Formats decimal-degree latitude and longitude into a newly allocated
"DD MM.MMMM' N/S, DDD MM.MMMM' E/W"string.
- Formats decimal-degree latitude and longitude into a newly allocated
Interactive Editing & Computational Geometry
int add_OMG_Line(OMG_Line_List *list, OMG_Line *line, int position)- Automatically forward-projects (
Project) ifx1..y2are zero, or inverse-projects (inv_proj) iflat1..lon2are zero. Dynamically doubleslist->linescapacity (starting at 10) when full, shifts existing elements to insert atposition(or appends at the end ifposition == -1), and updatesselected_line.
- Automatically forward-projects (
int remove_OMG_Line(OMG_Line_List *list, int line_number)- Removes
line_numberand shifts subsequent lines down.
- Removes
int add_OMG_Line_Parallel(OMG_Line_List *list, int side, int number, float spacing)- Computes the azimuth of
selected_linein pixel coordinates (where $+x$ is right and $+y$ is down), rotates $\pm 90^\circ$ forLEFT_OF_LINEorRIGHT_OF_LINE, scalesspacingbylist->map_header.xstep, and insertsnumberparallel lines.
- Computes the azimuth of
int get_point_cpa(OMG_Line *line, double x, double y, double *x_cpa, double *y_cpa, double *distance, int *on_segment)- Computes the Closest Point of Approach (CPA) from $(x, y)$ to the infinite line through
lineby intersecting perpendicular slopes ($m_2 = -1/m_1$), calculates Euclidean*distance, and sets*on_segment = 1if(*y_cpa - y1) * (*y_cpa - y2) < 0.
- Computes the Closest Point of Approach (CPA) from $(x, y)$ to the infinite line through
int get_closest_OMG_Line(OMG_Line_List *list, double lat, double lon, double x, double y)- Returns the index of the line segment with the minimum perpendicular CPA distance where
on_segment == 1, or-1if none.
- Returns the index of the line segment with the minimum perpendicular CPA distance where
int split_OMG_Line(OMG_Line_List *list, int line_number, double lat, double lon, double x, double y)- Projects $(x, y)$ onto
line_numberviaget_point_cpaand replaces the original segment with two collinear sub-segments meeting at(x_split, y_split).
- Projects $(x, y)$ onto
int extend_OMG_Line(OMG_Line_List *list, int line_number, double lat, double lon, double x, double y)- Finds the CPA of $(x, y)$ along the lineβs trajectory and replaces the nearer endpoint of
line_numberwith(x_split, y_split).
- Finds the CPA of $(x, y)$ along the lineβs trajectory and replaces the nearer endpoint of
int move_OMG_Line_point(OMG_Line_List *list, int line_number, double lat, double lon, double x, double y)- Identifies the endpoint of
line_numberclosest to $(x, y)$ and updates every line inlistsharing that exact vertex to the new coordinates $(x, y)$, preserving connected polyline vertices.
- Identifies the endpoint of
int join_OMG_Lines(OMG_Line_List *list, int line_number, double lat, double lon, double x, double y)- Snaps the nearest endpoint of the closest other line in
listto the selected endpoint ofline_number.
- Snaps the nearest endpoint of the closest other line in
int reorder_OMG_Lines(OMG_Line_List *list, int direction)- Swaps
selected_linewith its neighbor atselected_line + direction(wrapping around list boundaries).
- Swaps
int get_line_intersection(OMG_Line *l1, OMG_Line *l2, double *x, double *y)&int clip_OMG_Lines(OMG_Line_List *list, OMG_Line *clip_line)- Computes the intersection of two line segments and verifies it lies on both segments;
clip_OMG_Linestruncates the nearer endpoint of every line inlistthat intersectsclip_line.
- Computes the intersection of two line segments and verifies it lies on both segments;
How It Fits Into the OMG Architecture
omg_line is included directly in JV_global.h to provide interactive survey line planning and editing inside JView (code/JV/), and in line_export (code/line/line_export.c) to export binary .lines plans into ASCII waypoints and shipboard navigation formats.