Mercurial > projects > doodle
diff doodle/tk/geometry.d @ 79:535bae7a7305
Checkpoint
author | "David Bryant <bagnose@gmail.com>" |
---|---|
date | Sun, 15 Aug 2010 23:18:05 +0930 |
parents | 024a5608087f |
children | a274d16ab6ce |
line wrap: on
line diff
--- a/doodle/tk/geometry.d Sun Aug 15 15:19:14 2010 +0930 +++ b/doodle/tk/geometry.d Sun Aug 15 23:18:05 2010 +0930 @@ -113,7 +113,8 @@ } } -Vector normalise(in Vector v) { +/* +Vector normal(in Vector v) { double l = v.length; if (l < 1e-9) { // TODO consolidate numerical stability constants @@ -124,6 +125,7 @@ return v / l; } } +*/ // // A rectangle in 2D space. @@ -152,12 +154,12 @@ this(corner1.x, corner1.y, corner.x - corner1.x, corner.y - corner1.y); } - double x0() { return _position.x; } - double y0() { return _position.y; } - double w() { return _size.x; } - double h() { return _size.y; } - double x1() { return x0 + w; } - double y1() { return y0 + h; } + double x0() const { return _position.x; } + double y0() const { return _position.y; } + double w() const { return _size.x; } + double h() const { return _size.y; } + double x1() const { return x0 + w; } + double y1() const { return y0 + h; } alias position corner0; Point position() const { return _position; } @@ -236,9 +238,18 @@ } } +Rectangle growCentre(in Rectangle r, in Vector amount) { + return Rectangle(r.x0 - amount.x / 2, r.y0 - amount.y / 2, r.w + amount.x, r.h + amount.y); +} + +Rectangle growCentre(in Rectangle r, in double amount) { + return Rectangle(r.x0 - amount / 2, r.y0 - amount / 2, r.w + amount, r.h + amount); +} + // TODO review these functions. // Want a clear and simple set. +/+ Rectangle move(in Rectangle r, in Vector displacement) { return Rectangle(r.position + displacement, r.size); } @@ -260,15 +271,18 @@ Rectangle shrink(in Rectangle r, in Vector shrink_amount) { return Rectangle(r.position, r.size - shrink_amount); } ++/ // Operations about the centre +/+ Rectangle feather(in Rectangle r, double amount) { // feather isn't the right name assert(amount >= 0.0); assert(!isnan(amount)); return Rectangle(Point(r.position.x - amount, r.position.y - amount), Vector(r.size.x + 2.0 * amount, r.size.y + 2.0 * amount)); } ++/ private { // This function computes the intersection of two lines. @@ -388,9 +402,11 @@ } } +/* Segment reverse(in Segment s) { return Segment(s.end, s.begin); } +*/ bool intersection(in Segment a, in Segment b, out Point p) { Point pa1 = a.begin;