Index: /cpp/common/2d.h
===================================================================
--- /cpp/common/2d.h	(revision 908)
+++ /cpp/common/2d.h	(revision 909)
@@ -1,4 +1,4 @@
 // This file is a part of Framsticks SDK.  http://www.framsticks.com/
-// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
+// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
 // See LICENSE.txt for details.
 
@@ -16,11 +16,11 @@
 	XY() {}
 	XY(T _x, T _y) :x(_x), y(_y) {}
-	template <typename Q> XY(const Q& other) : x(other.x), y(other.y) {}
-	template <typename Q> const XY& operator=(const Q& other) { x = other.x; y = other.y; return *this; }
-	template <typename Q> const XY operator()(const Q& other) { return XY(other.x, other.y); }
-	XY operator+(const XY&p) const { return XY(x + p.x, y + p.y); }
-	XY operator-(const XY&p) const { return XY(x - p.x, y - p.y); }
-	XY operator+=(const XY&p) { x += p.x; y += p.y; return *this; }
-	XY operator-=(const XY&p) { x -= p.x; y -= p.y; return *this; }
+	template <typename Q> XY(const Q &other) : x(other.x), y(other.y) {}
+	template <typename Q> const XY &operator=(const Q &other) { x = other.x; y = other.y; return *this; }
+	template <typename Q> const XY operator()(const Q &other) { return XY(other.x, other.y); }
+	XY operator+(const XY &p) const { return XY(x + p.x, y + p.y); }
+	XY operator-(const XY &p) const { return XY(x - p.x, y - p.y); }
+	XY operator+=(const XY &p) { x += p.x; y += p.y; return *this; }
+	XY operator-=(const XY &p) { x -= p.x; y -= p.y; return *this; }
 	XY operator-() const { return XY(-x, -y); }
 	// allows float operations on ints
@@ -28,35 +28,35 @@
 	template <typename Q> XY operator/=(Q q) { x /= q; y /= q; return *this; }
 	template <typename Q> XY operator/(Q q) const { return XY(x / q, y / q); }
-	template <typename Q> XY operator*(Q q) const { return XY(q*x, q*y); }
-	XY operator*=(const XY& q) { x *= q.x; y *= q.y; return *this; }
-	XY operator/=(const XY& q) { x /= q.x; y /= q.y; return *this; }
-	XY operator*(const XY& q) const { return XY(x*q.x, y*q.y); }
-	XY operator/(const XY& q) const { return XY(x/q.x, y/q.y); }
+	template <typename Q> XY operator*(Q q) const { return XY(q * x, q * y); }
+	XY operator*=(const XY &q) { x *= q.x; y *= q.y; return *this; }
+	XY operator/=(const XY &q) { x /= q.x; y /= q.y; return *this; }
+	XY operator*(const XY &q) const { return XY(x * q.x, y * q.y); }
+	XY operator/(const XY &q) const { return XY(x / q.x, y / q.y); }
 	void set(T _x, T _y) { x = _x; y = _y; }
 	void add(T _x, T _y) { x += _x; y += _y; }
 	void sub(T _x, T _y) { x -= _x; y -= _y; }
-	bool operator==(const XY& p) const { return (fabs(double(x - p.x)) < 1e-20) && (fabs(double(y - p.y)) < 1e-20); }
-	bool operator!=(const XY& p) const { return !operator==(p); }
-	T distanceTo(const XY& p) const { return sqrt(double((p.x - x)*(p.x - x) + (p.y - y)*(p.y - y))); }
-	T magnitude() const { return sqrt(x*x + y * y); }
-	T length() const { return sqrt(x*x + y * y); }
+	bool operator==(const XY &p) const { return (fabs(double(x - p.x)) < 1e-20) && (fabs(double(y - p.y)) < 1e-20); }
+	bool operator!=(const XY &p) const { return !operator==(p); }
+	T distanceTo(const XY &p) const { return sqrt(double((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y))); }
+	T magnitude() const { return sqrt(x * x + y * y); }
+	T length() const { return sqrt(x * x + y * y); }
 	T lengthSq() const { return x * x + y * y; }
-	T dotProduct(const XY& v) const { return x * v.x + y * v.y; }
-	T crossProduct(const XY& v) const { return x * v.y - y * v.x; }
+	T dotProduct(const XY &v) const { return x * v.x + y * v.y; }
+	T crossProduct(const XY &v) const { return x * v.y - y * v.x; }
 	void normalize() { operator/=(length()); } // length becomes 1
-	static XY average(const XY& v1, const XY& v2) { return XY((v1.x + v2.x)*0.5, (v1.y + v2.y)*0.5); }
+	static XY average(const XY &v1, const XY &v2) { return XY((v1.x + v2.x) * 0.5, (v1.y + v2.y) * 0.5); }
 	double getDirection() const { return atan2(y, x); }
-	static XY interpolate(const XY& v1, const XY& v2, double t) { return universal_lerp(v1,v2,t); }
+	static XY interpolate(const XY &v1, const XY &v2, double t) { return universal_lerp(v1, v2, t); }
 	XY toInt() const { return XY(int(x), int(y)); }
 	XY transpose() const { return XY(y, x); }
-	static const XY& zero() { static XY t(0, 0); return t; }
-	static const XY& one() { static XY t(1, 1); return t; }
+	static const XY &zero() { static XY t(0, 0); return t; }
+	static const XY &one() { static XY t(1, 1); return t; }
 };
 
 //specialized: int equality not using fabs()
-template<> inline bool XY<int>::operator==(const XY<int>& p) const { return (x == p.x) && (y == p.y); }
-
-template <typename T> XY<T> xymin(const XY<T>& a, const XY<T>& b) { return XY<T>(min(a.x, b.x), min(a.y, b.y)); }
-template <typename T> XY<T> xymax(const XY<T>& a, const XY<T>& b) { return XY<T>(max(a.x, b.x), max(a.y, b.y)); }
+template<> inline bool XY<int>::operator==(const XY<int> &p) const { return (x == p.x) && (y == p.y); }
+
+template <typename T> XY<T> xymin(const XY<T> &a, const XY<T> &b) { return XY<T>(min(a.x, b.x), min(a.y, b.y)); }
+template <typename T> XY<T> xymax(const XY<T> &a, const XY<T> &b) { return XY<T>(max(a.x, b.x), max(a.y, b.y)); }
 
 template <typename T>
@@ -82,13 +82,13 @@
 	XY<T> p, size;
 	XYRect() {}
-	XYRect(const XY<T>& p1, const XY<T>& s) :p(p1), size(s) {}
-	template <typename Q> XYRect(const Q& other) : p(other.p), size(other.size) {}
+	XYRect(const XY<T> &p1, const XY<T> &s) :p(p1), size(s) {}
+	template <typename Q> XYRect(const Q &other) : p(other.p), size(other.size) {}
 	XYRect(T _x, T _y, T _w, T _h) :p(_x, _y), size(_w, _h) {}
-	static XYRect<T> centeredAt(const XY<T>& p, XY<T> s) { return XYRect<T>(p - s * 0.5, s); }
+	static XYRect<T> centeredAt(const XY<T> &p, XY<T> s) { return XYRect<T>(p - s * 0.5, s); }
 
 	bool isEmpty() const { return (size.x < 0) || (size.y < 0); }
 	XYRect toInt() const { return XYRect(int(p.x), int(p.y), int(p.x + size.x) - int(p.x), int(p.y + size.y) - int(p.y)); }
-	bool operator==(const XYRect& r) const { return (p == r.p) && (size == r.size); }
-	template <typename Q> const XYRect& operator=(const Q& other) { p = other.p; size = other.size; return *this; }
+	bool operator==(const XYRect &r) const { return (p == r.p) && (size == r.size); }
+	template <typename Q> const XYRect &operator=(const Q &other) { p = other.p; size = other.size; return *this; }
 
 	T right() const { return p.x + size.x; }
@@ -97,12 +97,12 @@
 	T left() const { return p.x; }
 	XY<T> center() const { return p + size / 2; }
-	const XY<T>& topLeft() const { return p; }
+	const XY<T> &topLeft() const { return p; }
 	XY<T> bottomRight() const { return p + size; }
 	XY<T> topRight() const { return XY<T>(p.x + size.x, p.y); }
 	XY<T> bottomLeft() const { return XY<T>(p.x, p.y + size.y); }
 
-	T area() const { return size.x*size.y; }
-
-	bool intersects(const XYRect& r) const
+	T area() const { return size.x * size.y; }
+
+	bool intersects(const XYRect &r) const
 	{
 		if (r.p.x >= (p.x + size.x)) return false;
@@ -113,5 +113,5 @@
 	}
 
-	bool contains(const XY<T>& n) const
+	bool contains(const XY<T> &n) const
 	{
 		if (n.x < p.x) return false;
@@ -122,10 +122,10 @@
 	}
 
-	bool contains(const XYRect& r) const
+	bool contains(const XYRect &r) const
 	{
 		return contains(r.p) && contains(r.p + r.size);
 	}
 
-	void add(const XY<T>& n)
+	void add(const XY<T> &n)
 	{
 		if (n.x < p.x) { size.x += p.x - n.x; p.x = n.x; }
@@ -135,20 +135,20 @@
 	}
 
-	XYRect extendBy(const XY<T>& border_size) const
+	XYRect extendBy(const XY<T> &border_size) const
 	{
 		return XYRect(p - border_size, size + border_size * 2);
 	}
 
-	XYRect shrinkBy(const XY<T>& border_size) const
+	XYRect shrinkBy(const XY<T> &border_size) const
 	{
 		return XYRect(p + border_size, size - border_size * 2);
 	}
 
-	XYRect extendBy(const XYMargin<T>& m) const
+	XYRect extendBy(const XYMargin<T> &m) const
 	{
 		return XYRect(p.x - m.left, p.y - m.top, size.x + m.horizontal(), size.y + m.vertical());
 	}
 
-	XYRect shrinkBy(const XYMargin<T>& m) const
+	XYRect shrinkBy(const XYMargin<T> &m) const
 	{
 		return XYRect(p.x + m.left, p.y + m.top, size.x - m.horizontal(), size.y - m.vertical());
@@ -164,14 +164,14 @@
 	{
 		XYRect r;
-		r.size=size;
-		if (size.x < size.y*aspect)
-			r.size.y = r.size.x/aspect;
+		r.size = size;
+		if (size.x < size.y * aspect)
+			r.size.y = r.size.x / aspect;
 		else
-			r.size.x = r.size.y*aspect;
-		r.p=p+(size-r.size)*0.5;
-		return r;		
-	}
-	
-	XYRect intersection(const XYRect& r) const
+			r.size.x = r.size.y * aspect;
+		r.p = p + (size - r.size) * 0.5;
+		return r;
+	}
+
+	XYRect intersection(const XYRect &r) const
 	{
 		XYRect i;
@@ -185,5 +185,12 @@
 	}
 
-	XYRect extensionContaining(const XYRect& r) const
+	XYRect extensionContaining(const XY<T> &p) const
+	{
+		XY<T> p1 = xymin(topLeft(), p);
+		XY<T> p2 = xymax(bottomRight(), p);
+		return XYRect(p1, p2 - p1);
+	}
+
+	XYRect extensionContaining(const XYRect &r) const
 	{
 		XY<T> p1 = xymin(topLeft(), r.topLeft());
@@ -192,10 +199,10 @@
 	}
 
-	XYRect translation(const XY<T>& t) const
+	XYRect translation(const XY<T> &t) const
 	{
 		return XYRect(p + t, size);
 	}
 
-	T distanceTo(const XY<T>& n) const
+	T distanceTo(const XY<T> &n) const
 	{
 		XY<T> tp = n;
@@ -205,5 +212,5 @@
 	}
 
-	T distanceTo(const XYRect<T>& r) const
+	T distanceTo(const XYRect<T> &r) const
 	{
 		bool r_above = (r.bottom() <= top());
@@ -236,6 +243,6 @@
 	}
 
-	static const XYRect& zero() { static XYRect t(0, 0, 0, 0); return t; }
-	static const XYRect& one() { static XYRect t(0, 0, 1, 1); return t; }
+	static const XYRect &zero() { static XYRect t(0, 0, 0, 0); return t; }
+	static const XYRect &one() { static XYRect t(0, 0, 1, 1); return t; }
 };
 
