File: geometry.rst

package info (click to toggle)
libgnatcoll 1.7gpl2015-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 17,280 kB
  • ctags: 1,124
  • sloc: ada: 134,072; python: 4,017; cpp: 1,397; ansic: 1,234; makefile: 368; sh: 152; xml: 31; sql: 6
file content (36 lines) | stat: -rw-r--r-- 1,170 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
********************************************
**Geometry**: primitive geometric operations
********************************************

.. highlight:: ada

GNATColl provides the package `GNATCOLL.Geometry`. This
package includes a number of primitive operations on geometric figures
like points, segments, lines, circles, rectangles and polygons.
In particular, you can compute their intersections, the distances,...

This package is generic, so that you can specify the type of coordinates
you wish to handle::

   declare
      package Float_Geometry is new GNATCOLL.Geometry (Float);
      use Float_Geometry;

      P1 : constant Point := (1.0, 1.0);
      P2 : constant Point := (2.0, 3.0);
   begin
      Put_Line ("Distance P1-P2 is" & Distance (P1, P2)'Img);
      --  Will print 2.23607
   end;
  

Or some operations involving a polygon::

     declare
        P3 : constant Point := (3.7, 2.0);
        P  : constant Polygon :=
           ((2.0, 1.3), (4.1, 3.0), (5.3, 2.6), (2.9, 0.7), (2.0, 1.3));
     begin
        Put_Line ("Area of polygon:" & Area (P));   --   3.015
        Put_Line ("P3 inside polygon ? " & Inside (P3, P)'Img);  --  True
     end;