# HG changeset patch # User David Bryant # Date 1247205348 -34200 # Node ID 7d57cae108057b95e98de0a1eb1e356d914269ca # Parent d6f44347373dc48cdfb6389791012e63f1e4b69b Renamed geometry2 to geometry diff -r d6f44347373d -r 7d57cae10805 build.sh --- a/build.sh Fri Jul 10 15:15:27 2009 +0930 +++ b/build.sh Fri Jul 10 15:25:48 2009 +0930 @@ -4,7 +4,7 @@ -ofgui \ gui.d tool_stack.d tool.d icanvas.d canvas.d \ tk/geometry.d tk/gtk_support.d tk/misc.d tk/types.d tk/events.d \ - tk/geometry2.d cairo_support.d \ + cairo_support.d \ -od.obj \ -I"${DMD_BASE}/include/d" \ -L-lgtkd -L-ldl diff -r d6f44347373d -r 7d57cae10805 cairo_support.d --- a/cairo_support.d Fri Jul 10 15:15:27 2009 +0930 +++ b/cairo_support.d Fri Jul 10 15:25:48 2009 +0930 @@ -1,10 +1,10 @@ module cairo_support; -import tk.geometry2; +import tk.geometry; import cairo.Context; -void rectangle(Context cr, Point2 corner1, Point2 corner2) { +void rectangle(Context cr, Point corner1, Point corner2) { double x = corner1.x; double y = corner1.y; double w = corner2.x - corner1.x; diff -r d6f44347373d -r 7d57cae10805 canvas.d --- a/canvas.d Fri Jul 10 15:15:27 2009 +0930 +++ b/canvas.d Fri Jul 10 15:25:48 2009 +0930 @@ -20,7 +20,7 @@ import gtk.Adjustment; import tk.misc; -import tk.geometry2; +import tk.geometry; import tk.types; import tk.events; import tk.gtk_support; @@ -34,8 +34,8 @@ class Canvas : Table, ICanvas { static this() { - ORIGIN = Point2(0.0, 0.0); - INITIAL_PAGE_SIZE = Vector2(210.0, 297.0); // A4 + ORIGIN = Point(0.0, 0.0); + INITIAL_PAGE_SIZE = Vector(210.0, 297.0); // A4 } this(ICanvasEventHandler event_handler) { @@ -108,17 +108,17 @@ 0, 0); } - override void rel_zoom(Point2 screen_datum, double factor) { + override void rel_zoom(Point screen_datum, double factor) { // Work out pixel distance from current centre to datum, // Do the zoom, then work out the new centre that keeps the // pixel distance the same - Point2 old_model_datum = screen_to_model(screen_datum); - Vector2 pixel_distance = model_to_screen(old_model_datum - mViewCentre); + Point old_model_datum = screen_to_model(screen_datum); + Vector pixel_distance = model_to_screen(old_model_datum - mViewCentre); mZoom = clamp_zoom(factor * mZoom); mViewCentre = old_model_datum - screen_to_model(pixel_distance); - Point2 new_model_datum = screen_to_model(screen_datum); + Point new_model_datum = screen_to_model(screen_datum); update_adjustments(); //update_rulers(new_model_datum); @@ -126,7 +126,7 @@ queueDraw(); } - override void rel_pan(Vector2 screen_displacement) { + override void rel_pan(Vector screen_displacement) { mViewCentre = mViewCentre + screen_to_model(screen_displacement); update_adjustments(); @@ -144,7 +144,7 @@ bool onConfigure(GdkEventConfigure * event, Widget widget) { assert(widget is mDrawingArea); - mViewSize = Vector2(cast(double)event.width, cast(double)event.height); + mViewSize = Vector(cast(double)event.width, cast(double)event.height); update_adjustments(); update_rulers(); @@ -181,8 +181,8 @@ { // Make the paper white, with a border - Point2 screen_page_left_bottom = model_to_screen(mPageLeftBottom); - Point2 screen_page_right_top = model_to_screen(mPageRightTop); + Point screen_page_left_bottom = model_to_screen(mPageLeftBottom); + Point screen_page_right_top = model_to_screen(mPageRightTop); cr.setSourceRgba(1.0, 1.0, 1.0, 1.0); rectangle(cr, screen_page_left_bottom, screen_page_right_top); @@ -200,8 +200,8 @@ assert(widget is mDrawingArea); //writefln("Got button event\n"); - Point2 screen_point = Point2(event.x + 0.5, event.y + 0.5); - Point2 model_point = screen_to_model(screen_point); + Point screen_point = Point(event.x + 0.5, event.y + 0.5); + Point model_point = screen_to_model(screen_point); auto button_event = new ButtonEvent(gtk2tk_click(event.type), gtk2tk_button(event.button), @@ -230,8 +230,8 @@ gtk_widget_event(mHRuler.getWidgetStruct(), cast(GdkEvent *)event); gtk_widget_event(mVRuler.getWidgetStruct(), cast(GdkEvent *)event); - Point2 screen_point = Point2(event.x + 0.5, event.y + 0.5); - Point2 model_point = screen_to_model(screen_point); + Point screen_point = Point(event.x + 0.5, event.y + 0.5); + Point model_point = screen_to_model(screen_point); auto motion_event = new MotionEvent(screen_point, model_point, @@ -246,8 +246,8 @@ assert(widget is mDrawingArea); //writefln("Got scroll\n"); - Point2 screen_point = Point2(event.x + 0.5, event.y + 0.5); - Point2 model_point = screen_to_model(screen_point); + Point screen_point = Point(event.x + 0.5, event.y + 0.5); + Point model_point = screen_to_model(screen_point); auto scroll_event = new ScrollEvent(gtk2tk_direction(event.direction), screen_point, @@ -263,10 +263,10 @@ GtkAdjustment * h_gtkAdjustment = mHAdjustment.getAdjustmentStruct(); GtkAdjustment * v_gtkAdjustment = mVAdjustment.getAdjustmentStruct(); - Point2 view_left_bottom = Point2(gtk_adjustment_get_value(h_gtkAdjustment), + Point view_left_bottom = Point(gtk_adjustment_get_value(h_gtkAdjustment), gtk_adjustment_get_value(v_gtkAdjustment)); writefln("%s", view_left_bottom); - Vector2 model_size = screen_to_model(mViewSize); + Vector model_size = screen_to_model(mViewSize); mViewCentre = view_left_bottom + model_size / 2.0; update_rulers(); @@ -275,10 +275,10 @@ } void update_rulers() { - Vector2 model_size = screen_to_model(mViewSize); + Vector model_size = screen_to_model(mViewSize); - Point2 view_left_bottom = mViewCentre - model_size / 2.0; - Point2 view_right_top = mViewCentre + model_size / 2.0; + Point view_left_bottom = mViewCentre - model_size / 2.0; + Point view_right_top = mViewCentre + model_size / 2.0; mHRuler.setRange(view_left_bottom.x, view_right_top.x, @@ -291,17 +291,17 @@ } void update_adjustments() { - Vector2 model_size = screen_to_model(mViewSize); + Vector model_size = screen_to_model(mViewSize); - Point2 view_left_bottom = mViewCentre - model_size / 2.0; - Point2 view_right_top = mViewCentre + model_size / 2.0; + Point view_left_bottom = mViewCentre - model_size / 2.0; + Point view_right_top = mViewCentre + model_size / 2.0; // Adjust the canvas size if necessary mCanvasLeftBottom = min_extents(mCanvasLeftBottom, view_left_bottom); mCanvasRightTop = max_extents(mCanvasRightTop, view_right_top); - Vector2 canvas_size = mCanvasRightTop - mCanvasLeftBottom; - Vector2 page_size = mPageRightTop - mPageLeftBottom; + Vector canvas_size = mCanvasRightTop - mCanvasLeftBottom; + Vector page_size = mPageRightTop - mPageLeftBottom; // Update the adjustments @@ -328,17 +328,17 @@ mVAdjustment.valueChanged(); } - Point2 model_to_screen(Point2 model) { return ORIGIN + mViewSize / 2.0 + mZoom * (model - mViewCentre); } - Point2 screen_to_model(Point2 screen) { return mViewCentre + (screen - mViewSize / 2.0 - ORIGIN) / mZoom; } - Vector2 model_to_screen(Vector2 model) { return mZoom * model; } - Vector2 screen_to_model(Vector2 screen) { return screen / mZoom; } + Point model_to_screen(Point model) { return ORIGIN + mViewSize / 2.0 + mZoom * (model - mViewCentre); } + Point screen_to_model(Point screen) { return mViewCentre + (screen - mViewSize / 2.0 - ORIGIN) / mZoom; } + Vector model_to_screen(Vector model) { return mZoom * model; } + Vector screen_to_model(Vector screen) { return screen / mZoom; } double model_to_screen(double model) { return mZoom * model; } double screen_to_model(double screen) { return screen / mZoom; } double clamp_zoom(double zoom) { return clamp(zoom, 0.1, 10.0); } - static const Point2 ORIGIN; - static const Vector2 INITIAL_PAGE_SIZE; + static const Point ORIGIN; + static const Vector INITIAL_PAGE_SIZE; ICanvasEventHandler mEventHandler; @@ -346,14 +346,14 @@ // Screen units are in pixels double mZoom; // pixels-per-mm - Point2 mViewCentre; // model: where in the model is the centre of our view + Point mViewCentre; // model: where in the model is the centre of our view - Point2 mCanvasLeftBottom; // model: bottom left corner of canvas - Point2 mCanvasRightTop; // model: top right corner of canvas - Point2 mPageLeftBottom; // model: bottom left corner of page - Point2 mPageRightTop; // model: top right corner of page + Point mCanvasLeftBottom; // model: bottom left corner of canvas + Point mCanvasRightTop; // model: top right corner of canvas + Point mPageLeftBottom; // model: bottom left corner of page + Point mPageRightTop; // model: top right corner of page - Vector2 mViewSize; // screen: size of view window in pixels + Vector mViewSize; // screen: size of view window in pixels HRuler mHRuler; VRuler mVRuler; diff -r d6f44347373d -r 7d57cae10805 gui.d --- a/gui.d Fri Jul 10 15:15:27 2009 +0930 +++ b/gui.d Fri Jul 10 15:25:48 2009 +0930 @@ -11,7 +11,7 @@ import tk.events; import std.stdio; -import tk.geometry2; +import tk.geometry; void main(string[] args) { Main.init(args); @@ -23,17 +23,17 @@ Main.run(); /* - Point2 p3 = Point2.DEFAULT; + Point p3 = Point.DEFAULT; - Point2 p1 = Point2(3.0, 5.0); + Point p1 = Point(3.0, 5.0); writefln("%s", p1); - Point2 p2 = Point2(1.0, 2.0); + Point p2 = Point(1.0, 2.0); writefln("%s", p2); writefln("%s", p1 - p2); - Rectangle2 r = Rectangle2(p1, p2); + Rectangle r = Rectangle(p1, p2); writefln("%s", r); */ } diff -r d6f44347373d -r 7d57cae10805 icanvas.d --- a/icanvas.d Fri Jul 10 15:15:27 2009 +0930 +++ b/icanvas.d Fri Jul 10 15:25:48 2009 +0930 @@ -1,10 +1,10 @@ module icanvas; -import tk.geometry2; +import tk.geometry; interface ICanvas { - void rel_zoom(Point2 screen_datum, double factor); - void rel_pan(Vector2 screen_displacement); + void rel_zoom(Point screen_datum, double factor); + void rel_pan(Vector screen_displacement); //void damage(); } diff -r d6f44347373d -r 7d57cae10805 standard_tools.d --- a/standard_tools.d Fri Jul 10 15:15:27 2009 +0930 +++ b/standard_tools.d Fri Jul 10 15:25:48 2009 +0930 @@ -3,15 +3,15 @@ final class PanTool : Tool { override bool handle_scroll(ICanvas canvas, ScrollEvent event) { const double AMOUNT = 30.0; - Vector2 v; + Vector v; if (event.mask.query(Modifier.SHIFT)) { // left to right - v = new Vector2(AMOUNT, 0.0); + v = new Vector(AMOUNT, 0.0); } else { // down to up - v = new Vector2(0.0, AMOUNT); + v = new Vector(0.0, AMOUNT); } if (event.scroll_direction == ScrollDirection.UP) { diff -r d6f44347373d -r 7d57cae10805 tk/events.d --- a/tk/events.d Fri Jul 10 15:15:27 2009 +0930 +++ b/tk/events.d Fri Jul 10 15:25:48 2009 +0930 @@ -1,7 +1,7 @@ module tk.events; import tk.types; -import tk.geometry2; +import tk.geometry; // // Should we pass the screen and model points into @@ -66,26 +66,26 @@ } abstract class PointerEvent : InputEvent { - this(Point2 screen_point, Point2 model_point, Mask mask) { + this(Point screen_point, Point model_point, Mask mask) { super(mask); - mScreenPoint2 = screen_point; - mModelPoint2 = model_point; + mScreenPoint = screen_point; + mModelPoint = model_point; } - Point2 screen_point() { return mScreenPoint2; } - Point2 model_point() { return mModelPoint2; } + Point screen_point() { return mScreenPoint; } + Point model_point() { return mModelPoint; } private { - Point2 mScreenPoint2; - Point2 mModelPoint2; + Point mScreenPoint; + Point mModelPoint; } } final class ButtonEvent : PointerEvent { this(ButtonPress button_press, ButtonNumber button_number, - Point2 screen_point, - Point2 model_point, + Point screen_point, + Point model_point, Mask mask) { super(screen_point, model_point, mask); mButtonPress = button_press; @@ -93,7 +93,7 @@ } override string toString() { - return std.string.format("Button event: %s, %s, %s, %s, %s", mButtonPress, mButtonNumber, mScreenPoint2, mModelPoint2, mMask); + return std.string.format("Button event: %s, %s, %s, %s, %s", mButtonPress, mButtonNumber, mScreenPoint, mModelPoint, mMask); } ButtonPress button_press() { return mButtonPress; } @@ -106,28 +106,28 @@ } final class MotionEvent : PointerEvent { - this(Point2 screen_point, - Point2 model_point, + this(Point screen_point, + Point model_point, Mask mask) { super(screen_point, model_point, mask); } override string toString() { - return std.string.format("Motion event: %s, %s, %s", mScreenPoint2, mModelPoint2, mMask); + return std.string.format("Motion event: %s, %s, %s", mScreenPoint, mModelPoint, mMask); } } final class ScrollEvent : PointerEvent { this(ScrollDirection scroll_direction, - Point2 screen_point, - Point2 model_point, + Point screen_point, + Point model_point, Mask mask) { super(screen_point, model_point, mask); mScrollDirection = scroll_direction; } override string toString() { - return std.string.format("Scroll event: %s, %s, %s, %s", mScrollDirection, mScreenPoint2, mModelPoint2, mMask); + return std.string.format("Scroll event: %s, %s, %s, %s", mScrollDirection, mScreenPoint, mModelPoint, mMask); } ScrollDirection scroll_direction() { return mScrollDirection; } diff -r d6f44347373d -r 7d57cae10805 tk/geometry.d --- a/tk/geometry.d Fri Jul 10 15:15:27 2009 +0930 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -module tk.geometry; - -private import std.math; -private import tk.misc; - -final class Point { - this() { - this(0.0, 0.0); - } - - this(double x, double y) { - _x = x; - _y = y; - } - - Point clone() const { - return new Point(_x, _y); - } - - override string toString() const { - return std.string.format("(%f, %f)", _x, _y); - } - - Point opAdd(in Vector v) const { - return new Point(_x + v._x, _y + v._y); - } - - Vector opSub(in Point p) const { - return new Vector(_x - p._x, _y - p._y); - } - - Point opSub(in Vector v) const { - return new Point(_x - v._x, _y - v._y); - } - - double x() const { return _x; } - double y() const { return _y; } - - private immutable double _x, _y; -} - -Point min_extents(in Point a, in Point b) { - return new Point(min(a.x, b.x), min(a.y, b.y)); -} - -Point max_extents(in Point a, in Point b) { - return new Point(max(a.x, b.x), max(a.y, b.y)); -} - -// - -final class Vector { - this() { - this(0.0, 0.0); - } - - this(double x, double y) { - _x = x; - _y = y; - } - - override string toString() const { - return std.string.format("[%f, %f]", _x, _y); - } - - Vector opAdd(in Vector v) const { - return new Vector(_x + v._x, _y + v._y); - } - - Vector opSub(in Vector v) const { - return new Vector(_x - v._x, _y - v._y); - } - - Vector opNeg() const { - return new Vector(-_x, -_y); - } - - Vector opMul_r(double d) const { - return new Vector(d * _x, d * _y); - } - - Vector opDiv(double d) const { - return new Vector(_x / d, _y / d); - } - - double length() const { - return sqrt(_x * _x + _y * _y); - } - - double x() const { return _x; } - double y() const { return _y; } - - private immutable double _x, _y; -} - -// - -final class Rectangle { - this() { - mPosition = new Point(); - mSize = new Vector(); - } - - this(Point position, Vector size) { - this(position.x, position.y, size.x, size.y); - } - - this(Point corner1, Point corner2) { - this(corner1.x, corner1.y, corner2.x - corner1.x, corner2.y - corner1.y); - } - - const(Point) position() const { return mPosition; } - const(Vector) size() const { return mSize; } - - private { - this(double x, double y, double w, double h) { - if (w < 0.0) { x += w; w = -w; } - if (h < 0.0) { y += h; h = -h; } - mPosition = new Point(x, y); - mSize = new Vector(w, h); - } - - const(Point) mPosition; - const(Vector) mSize; - } -} diff -r d6f44347373d -r 7d57cae10805 tk/geometry2.d --- a/tk/geometry2.d Fri Jul 10 15:15:27 2009 +0930 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -module tk.geometry2; - -private import std.stdio; -private import std.math; -private import tk.misc; - -struct Point2 { - static immutable Point2 DEFAULT; - - static this() { - DEFAULT = Point2(0.0, 0.0); - } - - this(in double x, in double y) { - _x = x; - _y = y; - } - - Point2 opAdd(in Vector2 v) const { - return Point2(_x + v._x, _y + v._y); - } - - Point2 opSub(in Vector2 v) const { - return Point2(_x - v._x, _y - v._y); - } - - Vector2 opSub(in Point2 p) const { - return Vector2(_x - p._x, _y - p._y); - } - - string toString() /* const */ { - return std.string.format("(%f, %f)", _x, _y); - } - - double x() const { return _x; } - double y() const { return _y; } - - private { - double _x, _y; - } -} - -Point2 min_extents(in Point2 a, in Point2 b) { - return Point2(min(a.x, b.x), min(a.y, b.y)); -} - -Point2 max_extents(in Point2 a, in Point2 b) { - return Point2(max(a.x, b.x), max(a.y, b.y)); -} - -struct Vector2 { - static Vector2 DEFAULT; - - static this() { - DEFAULT = Vector2(0.0, 0.0); - } - - this(in double x, in double y) { - _x = x; - _y = y; - } - - Vector2 opAdd(in Vector2 v) const { - return Vector2(_x + v._x, _y + v._y); - } - - Vector2 opSub(in Vector2 v) const { - return Vector2(_x - v._x, _y - v._y); - } - - Vector2 opNeg() const { - return Vector2(-_x, -_y); - } - - Vector2 opMul_r(in double d) const { - return Vector2(d * _x, d * _y); - } - - Vector2 opDiv(in double d) const { - return Vector2(_x / d, _y / d); - } - - double length() const { - return sqrt(_x * _x + _y * _y); - } - - string toString() /* const */ { - return std.string.format("[%f, %f]", _x, _y); - } - - double x() const { return _x; } - double y() const { return _y; } - - private { - double _x, _y; - } -} - -struct Rectangle2 { - static Rectangle2 DEFAULT; - - static this() { - DEFAULT = Rectangle2(Point2.DEFAULT, Vector2.DEFAULT); - } - - /* - static Rectangle2 from_arbitrary_corners(in Point2 corner1, in Point2 corner2) { - } - */ - - this(in Point2 position, in Vector2 size) { - this(position.x, position.y, size.x, size.y); - } - - this(in Point2 corner1, in Point2 corner2) { - this(corner1.x, corner1.y, corner2.x - corner1.x, corner2.y - corner1.y); - } - - Point2 position() const { - return _position; - } - - alias position min_corner; - - Point2 max_corner() const { - return _position + _size; - } - - bool valid() const { - return _size.x > 0.0 & _size.y > 0.0; - } - - bool invalid() const { - return !valid(); - } - - double area() const { - return _size.x * _size.y; - } - - // Intersection - Rectangle2 opAnd(in Rectangle2 r) const { - if (invalid() || r.invalid()) { - return DEFAULT; - } - else { - Point2 max = min_extents(max_corner(), r.max_corner()); - Point2 min = max_extents(min_corner(), r.min_corner()); - - if (max.x < min.x || max.y < min.y) { - return DEFAULT; - } - else { - return Rectangle2(min, max); - } - } - } - - // Union - Rectangle2 opOr(in Rectangle2 r) const { - if (invalid()) { - return r; - } - else if (r.invalid()) { - return this; - } - else { - return Rectangle2(min_extents(min_corner(), r.min_corner()), - max_extents(max_corner(), r.max_corner())); - } - } - - /* - Rectangle2 moved(in Vector2 displacement) { - return Rectangle2( - } - Rectangle2 resized(in Vector2 new_size) { - } - Rectangle2 repositioned(in Point2 new_position) { - } - */ - - string toString() /* const */ { - return std.string.format("{%s, %s}", _position, _size); - } - - private { - this(double x, double y, double w, double h) { - if (w < 0.0) { x += w; w = -w; } - if (h < 0.0) { y += h; h = -h; } - _position = Point2(x, y); - _size = Vector2(w, h); - } - - Point2 _position; - Vector2 _size; - } -} diff -r d6f44347373d -r 7d57cae10805 tool_stack.d --- a/tool_stack.d Fri Jul 10 15:15:27 2009 +0930 +++ b/tool_stack.d Fri Jul 10 15:25:48 2009 +0930 @@ -2,9 +2,10 @@ import std.stdio; +import tool; private import icanvas; private import tk.types; -private import tk.geometry2; +private import tk.geometry; private import tk.events; //IToolStack @@ -52,15 +53,15 @@ // Scroll const double AMOUNT = 30.0; - Vector2 v; + Vector v; if (event.mask.query(Modifier.SHIFT)) { // left to right - v = Vector2(AMOUNT, 0.0); + v = Vector(AMOUNT, 0.0); } else { // down to up - v = Vector2(0.0, AMOUNT); + v = Vector(0.0, AMOUNT); } if (event.scroll_direction == ScrollDirection.UP) {