mirror of
https://github.com/Ed94/metadesk.git
synced 2026-07-25 00:47:52 +00:00
draft of base.c
This commit is contained in:
+71
-15
@@ -9,15 +9,15 @@
|
||||
typedef struct TxtPt TxtPt;
|
||||
struct TxtPt
|
||||
{
|
||||
S64 line;
|
||||
S64 column;
|
||||
S64 line;
|
||||
S64 column;
|
||||
};
|
||||
|
||||
typedef struct TxtRng TxtRng;
|
||||
struct TxtRng
|
||||
{
|
||||
TxtPt min;
|
||||
TxtPt max;
|
||||
TxtPt min;
|
||||
TxtPt max;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -26,8 +26,8 @@ struct TxtRng
|
||||
typedef struct String8TxtPtPair String8TxtPtPair;
|
||||
struct String8TxtPtPair
|
||||
{
|
||||
String8 string;
|
||||
TxtPt pt;
|
||||
String8 string;
|
||||
TxtPt pt;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
@@ -38,13 +38,69 @@ MD_API String8TxtPtPair str8_txt_pt_pair_from_string(String8 string);
|
||||
////////////////////////////////
|
||||
//~ rjf: Text 2D Coordinate/Range Functions
|
||||
|
||||
TxtPt txt_pt(S64 line, S64 column);
|
||||
B32 txt_pt_match(TxtPt a, TxtPt b);
|
||||
B32 txt_pt_less_than(TxtPt a, TxtPt b);
|
||||
TxtPt txt_pt_min(TxtPt a, TxtPt b);
|
||||
TxtPt txt_pt_max(TxtPt a, TxtPt b);
|
||||
TxtRng txt_rng(TxtPt min, TxtPt max);
|
||||
TxtRng txt_rng_intersect(TxtRng a, TxtRng b);
|
||||
TxtRng txt_rng_union(TxtRng a, TxtRng b);
|
||||
B32 txt_rng_contains(TxtRng r, TxtPt pt);
|
||||
inline TxtPt txt_pt(S64 line, S64 column) { TxtPt p = { line, column }; return p; }
|
||||
|
||||
inline B32 txt_pt_match(TxtPt a, TxtPt b) { return a.line == b.line && a.column == b.column; }
|
||||
inline TxtPt txt_pt_min (TxtPt a, TxtPt b) { TxtPt result = b; if (txt_pt_less_than(a, b)) { result = a; } return result; }
|
||||
inline TxtPt txt_pt_max (TxtPt a, TxtPt b) { TxtPt result = a; if (txt_pt_less_than(a, b)) { result = b; } return result; }
|
||||
|
||||
B32 txt_pt_less_than (TxtPt a, TxtPt b);
|
||||
TxtRng txt_rng (TxtPt min, TxtPt max);
|
||||
TxtRng txt_rng_intersect(TxtRng a, TxtRng b);
|
||||
TxtRng txt_rng_union (TxtRng a, TxtRng b);
|
||||
B32 txt_rng_contains (TxtRng r, TxtPt pt);
|
||||
|
||||
inline B32
|
||||
txt_pt_less_than(TxtPt a, TxtPt b)
|
||||
{
|
||||
B32 result = 0;
|
||||
if (a.line < b.line) {
|
||||
result = 1;
|
||||
}
|
||||
else if (a.line == b.line) {
|
||||
result = a.column < b.column;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline TxtRng
|
||||
txt_rng(TxtPt min, TxtPt max)
|
||||
{
|
||||
TxtRng range = {0};
|
||||
if(txt_pt_less_than(min, max)) {
|
||||
range.min = min;
|
||||
range.max = max;
|
||||
}
|
||||
else {
|
||||
range.min = max;
|
||||
range.max = min;
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
inline TxtRng
|
||||
txt_rng_intersect(TxtRng a, TxtRng b)
|
||||
{
|
||||
TxtRng result = {0};
|
||||
result.min = txt_pt_max(a.min, b.min);
|
||||
result.max = txt_pt_min(a.max, b.max);
|
||||
if (txt_pt_less_than(result.max, result.min)) {
|
||||
MemoryZeroStruct(&result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline TxtRng
|
||||
txt_rng_union(TxtRng a, TxtRng b)
|
||||
{
|
||||
TxtRng result = {0};
|
||||
result.min = txt_pt_min(a.min, b.min);
|
||||
result.max = txt_pt_max(a.max, b.max);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline B32
|
||||
txt_rng_contains(TxtRng r, TxtPt pt) {
|
||||
B32 result = ((txt_pt_less_than(r.min, pt) || txt_pt_match(r.min, pt)) && txt_pt_less_than(pt, r.max));
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user