summaryrefslogtreecommitdiff
path: root/src/dged/location.h
blob: 440459555307916f79eb65925fc62ba467297708 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef _LOCATION_H
#define _LOCATION_H

#include <stdbool.h>
#include <stdint.h>

/**
 * A location inside text.
 */
struct location {
  /** The line in the text (0..) */
  uint32_t line;

  /** The column in the text (0..) */
  uint32_t col;
};

/**
 * Is the location between two other locations.
 *
 * @param [in] location The location to test.
 * @param [in] l1 The first location.
 * @param [in] l2 The other location.
 * @returns True if @p location is between @p l1 and @p l2.
 */
bool location_is_between(struct location location, struct location l1,
                         struct location l2);

/**
 * Compare two locations.
 *
 * @param [in] l1 The first location.
 * @param [in] l2 The second location.
 *
 * @returns -1 if @p l1 is before @p l2, 0 if @p l1 is equal to @p l2
 *          and +1 if @p l1 is after @p l2.
 */
int location_compare(struct location l1, struct location l2);

/**
 * A region (area) in text.
 */
struct region {
  /** The top left corner of the region. */
  struct location begin;

  /** The bottom right corner of the region. */
  struct location end;
};

/**
 * Create a new region.
 *
 * Note that if begin is after end, their order will be reversed.
 *
 * @param [in] begin The point in the text where this region begins.
 * @param [in] end The point in the text where this region ends.
 * @returns a new region.
 */
struct region region_new(struct location begin, struct location end);

/**
 * Is this region covering anything?
 *
 * @param [in] region The region to check.
 * @returns True if the region has a size > 0.
 */
bool region_has_size(struct region region);

/**
 * Is the location inside the region?
 *
 * @param [in] region The region to test.
 * @param [in] location The location to test.
 * @returns True if @p location is inside @p region.
 */
bool region_is_inside(struct region region, struct location location);

bool region_is_inside_rect(struct region region, struct location location);

#endif