PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/graphics/region.d

http://github.com/wilkie/djehuty
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. module graphics.region;
  10. import core.definitions;
  11. import platform.vars.region;
  12. import scaffold.graphics;
  13. class Region {
  14. this() {
  15. }
  16. this(Region rgn) {
  17. _points = rgn.points;
  18. }
  19. this(Coord[] points) {
  20. _points = points.dup;
  21. }
  22. // Description: This function will test to see whether or not a point exists within this region.
  23. // x: The x coordinate of the point to test.
  24. // y: The y coordinate of the point to test.
  25. // Returns: Will return true when the point given is inside the region.
  26. bool containsPoint(int x, int y) {
  27. return false;
  28. }
  29. // Description: This function will test to see whether or not a point exists within this region.
  30. // pt: The point to test.
  31. // Returns: Will return true when the point given is inside the region.
  32. bool containsPoint(Coord pt) {
  33. return false;
  34. }
  35. // Description: This function will return a copy of the array of points in the region.
  36. // Returns: A duplicate of the array of points.
  37. Coord[] points() {
  38. if (_points is null) { return null; }
  39. return _points.dup;
  40. }
  41. uint length() {
  42. if (_points is null) { return 0; }
  43. return _points.length;
  44. }
  45. int opApply(int delegate(inout Coord) loopFunc) {
  46. int ret;
  47. for(int i = 0; i < _points.length; i++) {
  48. ret = loopFunc(_points[i]);
  49. if (ret) { break; }
  50. }
  51. return ret;
  52. }
  53. int opApply(int delegate(inout int, inout Coord) loopFunc) {
  54. int ret;
  55. for(int i = 0; i < _points.length; i++) {
  56. ret = loopFunc(i, _points[i]);
  57. if (ret) { break; }
  58. }
  59. return ret;
  60. }
  61. Coord[] opSlice() {
  62. return points;
  63. }
  64. protected:
  65. // Whether or not the platform's realization of the state of this region
  66. // is valid
  67. package bool platformDirty = true;
  68. // Platform specific denotation of the region
  69. package RegionPlatformVars _pfvars;
  70. // The collection of points
  71. Coord[] _points;
  72. }