#ifndef PLOT_RANGE_H
#define PLOT_RANGE_H

struct Range {

	float min;
	float max;

	Range() : min(0), max(0) {;}

	Range(const float min, const float max) : min(min), max(max) {
		;
	}

	float getSize() const {
		return max-min;
	}

	float getCenter() const {
		return (max+min)/2;
	}

	bool isValid() const {
		return getSize() > 0;
	}

	/** resize the region. 1.0 = keep-as-is */
	void scale(const float val) {
		const float center = getCenter();
		const float size = getSize();
		min = center - size / 2 * val;
		max = center + size / 2 * val;
	}

	/** adjust (grow) the range */
	void adjust(const float val) {
		if (val < min) {min = val;}
		if (val > max) {max = val;}
	}

	void adjust(const Range& o) {
		if (o.min < min) {min = o.min;}
		if (o.max > max) {max = o.max;}
	}

};

#endif // PLOT_RANGE_H
