/graphics/region.d
D | 95 lines | 51 code | 23 blank | 21 comment | 6 complexity | 9d3aa0e44eb27d31c739f0adeb122a65 MD5 | raw file
1/* 2 * region.d 3 * 4 * This module implements a region primitive. 5 * 6 * Author: Dave Wilkinson 7 * 8 */ 9 10module graphics.region; 11 12import core.definitions; 13 14import platform.vars.region; 15 16import scaffold.graphics; 17 18class Region { 19 20 this() { 21 } 22 23 this(Region rgn) { 24 _points = rgn.points; 25 } 26 27 this(Coord[] points) { 28 _points = points.dup; 29 } 30 31 // Description: This function will test to see whether or not a point exists within this region. 32 // x: The x coordinate of the point to test. 33 // y: The y coordinate of the point to test. 34 // Returns: Will return true when the point given is inside the region. 35 bool containsPoint(int x, int y) { 36 return false; 37 } 38 39 // Description: This function will test to see whether or not a point exists within this region. 40 // pt: The point to test. 41 // Returns: Will return true when the point given is inside the region. 42 bool containsPoint(Coord pt) { 43 return false; 44 } 45 46 // Description: This function will return a copy of the array of points in the region. 47 // Returns: A duplicate of the array of points. 48 Coord[] points() { 49 if (_points is null) { return null; } 50 return _points.dup; 51 } 52 53 uint length() { 54 if (_points is null) { return 0; } 55 return _points.length; 56 } 57 58 int opApply(int delegate(inout Coord) loopFunc) { 59 int ret; 60 61 for(int i = 0; i < _points.length; i++) { 62 ret = loopFunc(_points[i]); 63 if (ret) { break; } 64 } 65 66 return ret; 67 } 68 69 int opApply(int delegate(inout int, inout Coord) loopFunc) { 70 int ret; 71 72 for(int i = 0; i < _points.length; i++) { 73 ret = loopFunc(i, _points[i]); 74 if (ret) { break; } 75 } 76 77 return ret; 78 } 79 80 Coord[] opSlice() { 81 return points; 82 } 83 84protected: 85 86 // Whether or not the platform's realization of the state of this region 87 // is valid 88 package bool platformDirty = true; 89 90 // Platform specific denotation of the region 91 package RegionPlatformVars _pfvars; 92 93 // The collection of points 94 Coord[] _points; 95}