From a9b0d578890cf33ec170f8c437bfa1b2c8695f65 Mon Sep 17 00:00:00 2001 From: James Holman Date: Fri, 30 Aug 2024 20:06:40 +1000 Subject: [PATCH] docs: copy in some postgres docs --- sqlx-postgres/src/types/geometry/box.rs | 13 ++++++++++++- sqlx-postgres/src/types/geometry/line.rs | 6 ++++-- sqlx-postgres/src/types/geometry/line_segment.rs | 15 ++++++++++++++- sqlx-postgres/src/types/geometry/path.rs | 16 +++++++++++++++- sqlx-postgres/src/types/geometry/point.rs | 9 ++++++++- sqlx-postgres/src/types/geometry/polygon.rs | 16 +++++++++++++++- 6 files changed, 68 insertions(+), 7 deletions(-) diff --git a/sqlx-postgres/src/types/geometry/box.rs b/sqlx-postgres/src/types/geometry/box.rs index c99c1fdca4..af6767e598 100644 --- a/sqlx-postgres/src/types/geometry/box.rs +++ b/sqlx-postgres/src/types/geometry/box.rs @@ -13,7 +13,18 @@ const ERROR: &str = "error decoding BOX"; /// /// Storage size: 32 bytes /// Description: Rectangular box -/// Representation: ((x1,y1),(x2,y2)) +/// Representation: `((x1,y1),(x2,y2))` +/// +/// Boxes are represented by pairs of points that are opposite corners of the box. Values of type box are specified using any of the following syntaxes: +/// +/// ``` +/// ( ( x1 , y1 ) , ( x2 , y2 ) ) +/// ( x1 , y1 ) , ( x2 , y2 ) +/// x1 , y1 , x2 , y2 +/// ``` +/// where `(x1,y1) and (x2,y2)` are any two opposite corners of the box. +/// Boxes are output using the second syntax. +/// Any two opposite corners can be supplied on input, but the values will be reordered as needed to store the upper right and lower left corners, in that order. /// /// See https://www.postgresql.org/docs/16/datatype-geometric.html#DATATYPE-GEOMETRIC-BOXES #[derive(Debug, Clone, PartialEq)] diff --git a/sqlx-postgres/src/types/geometry/line.rs b/sqlx-postgres/src/types/geometry/line.rs index b1b1a81210..0e3ac23e76 100644 --- a/sqlx-postgres/src/types/geometry/line.rs +++ b/sqlx-postgres/src/types/geometry/line.rs @@ -9,11 +9,13 @@ use std::str::FromStr; const ERROR: &str = "error decoding LINE"; -/// Postgres Geometric Line type +/// ## Postgres Geometric Line type /// /// Storage size: 24 bytes /// Description: Infinite line -/// Representation: {A, B, C} +/// Representation: `{A, B, C}` +/// +/// Lines are represented by the linear equation Ax + By + C = 0, where A and B are not both zero. Values of type line are input and output in the following form: /// /// See https://www.postgresql.org/docs/16/datatype-geometric.html#DATATYPE-LINE #[derive(Debug, Clone, PartialEq)] diff --git a/sqlx-postgres/src/types/geometry/line_segment.rs b/sqlx-postgres/src/types/geometry/line_segment.rs index 0d499aff24..0318fe9d79 100644 --- a/sqlx-postgres/src/types/geometry/line_segment.rs +++ b/sqlx-postgres/src/types/geometry/line_segment.rs @@ -13,7 +13,20 @@ const ERROR: &str = "error decoding LSEG"; /// /// Storage size: 32 bytes /// Description: Finite line segment -/// Representation: ((x1,y1),(x2,y2)) +/// Representation: `((x1,y1),(x2,y2))` +/// +/// +/// Line segments are represented by pairs of points that are the endpoints of the segment. Values of type lseg are specified using any of the following syntaxes: +/// ``` +/// [ ( x1 , y1 ) , ( x2 , y2 ) ] +/// ( ( x1 , y1 ) , ( x2 , y2 ) ) +/// ( x1 , y1 ) , ( x2 , y2 ) +/// x1 , y1 , x2 , y2 +/// ``` +/// where `(x1,y1) and (x2,y2)` are the end points of the line segment. +/// +/// Line segments are output using the first syntax. +/// /// /// See https://www.postgresql.org/docs/16/datatype-geometric.html#DATATYPE-LSEG #[derive(Debug, Clone, PartialEq)] diff --git a/sqlx-postgres/src/types/geometry/path.rs b/sqlx-postgres/src/types/geometry/path.rs index d266c32b71..061eba9b00 100644 --- a/sqlx-postgres/src/types/geometry/path.rs +++ b/sqlx-postgres/src/types/geometry/path.rs @@ -13,7 +13,21 @@ const BYTE_WIDTH: usize = 8; /// /// Storage size: 16+16n bytes /// Description: Open path or Closed path (similar to polygon) -/// Representation: Open [(x1,y1),...], Closed ((x1,y1),...) +/// Representation: Open `[(x1,y1),...]`, Closed `((x1,y1),...)` +/// +/// Paths are represented by lists of connected points. Paths can be open, where the first and last points in the list are considered not connected, or closed, where the first and last points are considered connected. +/// Values of type path are specified using any of the following syntaxes: +/// ``` +/// [ ( x1 , y1 ) , ... , ( xn , yn ) ] +/// ( ( x1 , y1 ) , ... , ( xn , yn ) ) +/// ( x1 , y1 ) , ... , ( xn , yn ) +/// ( x1 , y1 , ... , xn , yn ) +/// x1 , y1 , ... , xn , yn +/// ``` +/// where the points are the end points of the line segments comprising the path. Square brackets `([])` indicate an open path, while parentheses `(())` indicate a closed path. +/// When the outermost parentheses are omitted, as in the third through fifth syntaxes, a closed path is assumed. +/// +/// Paths are output using the first or second syntax, as appropriate. /// /// See https://www.postgresql.org/docs/16/datatype-geometric.html#DATATYPE-GEOMETRIC-PATHS #[derive(Debug, Clone, PartialEq)] diff --git a/sqlx-postgres/src/types/geometry/point.rs b/sqlx-postgres/src/types/geometry/point.rs index a60bb39bd4..38d0820aaf 100644 --- a/sqlx-postgres/src/types/geometry/point.rs +++ b/sqlx-postgres/src/types/geometry/point.rs @@ -11,7 +11,14 @@ use std::str::FromStr; /// /// Storage size: 16 bytes /// Description: Point on a plane -/// Representation: (x, y) +/// Representation: `(x, y)` +/// +/// Points are the fundamental two-dimensional building block for geometric types. Values of type point are specified using either of the following syntaxes: +/// ``` +/// ( x , y ) +/// x , y +/// ```` +/// where x and y are the respective coordinates, as floating-point numbers. /// /// See https://www.postgresql.org/docs/16/datatype-geometric.html#DATATYPE-GEOMETRIC-POINTS #[derive(Debug, Clone, PartialEq)] diff --git a/sqlx-postgres/src/types/geometry/polygon.rs b/sqlx-postgres/src/types/geometry/polygon.rs index f0cbaa3670..0cff86d046 100644 --- a/sqlx-postgres/src/types/geometry/polygon.rs +++ b/sqlx-postgres/src/types/geometry/polygon.rs @@ -13,7 +13,21 @@ const BYTE_WIDTH: usize = 8; /// /// Storage size: 40+16n bytes /// Description: Polygon (similar to closed polygon) -/// Representation: ((x1,y1),...) +/// Representation: `((x1,y1),...)` +/// +/// Polygons are represented by lists of points (the vertexes of the polygon). Polygons are very similar to closed paths; the essential semantic difference is that a polygon is considered to include the area within it, while a path is not. +/// An important implementation difference between polygons and paths is that the stored representation of a polygon includes its smallest bounding box. This speeds up certain search operations, although computing the bounding box adds overhead while constructing new polygons. +/// Values of type polygon are specified using any of the following syntaxes: +/// +/// ``` +/// ( ( x1 , y1 ) , ... , ( xn , yn ) ) +/// ( x1 , y1 ) , ... , ( xn , yn ) +/// ( x1 , y1 , ... , xn , yn ) +/// x1 , y1 , ... , xn , yn +/// ``` +/// +/// where the points are the end points of the line segments comprising the boundary of the polygon. +/// Polygons are output using the first syntax. /// /// Seeh ttps://www.postgresql.org/docs/16/datatype-geometric.html#DATATYPE-POLYGON #[derive(Debug, Clone, PartialEq)]