-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAQTFunctions.h
49 lines (39 loc) · 1.49 KB
/
AQTFunctions.h
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
//
// AQTFunctions.h
// AquaTerm
//
// Created by Per Persson on Tue Nov 25 2003.
// Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//
#import <Foundation/NSGeometry.h>
#import "AQTGraphic.h"
#define COMP_EPS 0.001
// A macro to cast structs that have the same fields
// Handy, dangerous and untested...
#define CAST_STRUCT_TO(struct_t) *(struct_t *)&
// FIXME: test these...
#define GEQ(a,b) ((a) > (b)-COMP_EPS)
#define LEQ(a,b) ((a) < (b)+COMP_EPS)
#define EQ(a,b) (-COMP_EPS < (a)-(b) && (a)-(b) < COMP_EPS)
/* Color utilities */
static inline BOOL AQTEqualColors(AQTColor c1, AQTColor c2) {
// return (c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue);
return (EQ(c1.red, c2.red) && EQ(c1.green, c2.green) && EQ(c1.blue, c2.blue) && EQ(c1.alpha, c2.alpha));
}
/* Geometry extensions */
static inline BOOL AQTIntervalContainsFloat(float aMin, float aMax, float a) {
// return (a > aMin - COMP_EPS && a < aMax + COMP_EPS);
return (GEQ(a, aMin) && LEQ(a, aMax));
}
static inline BOOL AQTIsZeroRect(NSRect aRect){
return NSEqualRects(aRect, NSZeroRect);
}
BOOL AQTContainsRect(NSRect containerRect, NSRect testRect);
BOOL AQTIntersectsRect(NSRect aRect, NSRect bRect);
NSRect AQTUnionRect(NSRect aRect, NSRect bRect);
static inline NSRect AQTRectFromSize(NSSize aSize) {
return NSMakeRect(0.0, 0.0, aSize.width, aSize.height);
}
static inline BOOL AQTProportionalSizes(NSSize aSize, NSSize bSize) {
return EQ(aSize.height/aSize.width, bSize.height/bSize.width);
}