Skip to content
Snippets Groups Projects
Commit 9bec54c1 authored by Thomas Oster's avatar Thomas Oster
Browse files

Merge pull request #5 from mgmax/develop

private class Interval: improve, add documentation
parents d6263f21 a868c0ea
No related branches found
No related tags found
No related merge requests found
......@@ -29,25 +29,40 @@ package com.t_oster.liblasercut.platform;
public class Rectangle {
private int x1, x2, y1, y2;
/**
* integer interval helper class
* represents the set { min, min+1, ..., max }
*
* min must be < max
*/
private class Interval
{
private int x1,x2;
private int min,max;
private Interval(int x1, int x2)
private Interval(int min, int max)
{
this.x1 = x1;
this.x2 = x2;
this.min = min;
this.max = max;
if (min>max) {
throw new RuntimeException("Interval: min must be < max");
}
}
/**
* @return true if the other interval is equal or is a subset
*/
private boolean isSubsetOf(Interval o)
{
return o.x1 <= x1 && o.x2 >= x2;
return o.min <= min && o.max >= max;
}
/**
* @return true if the other interval has at least one element in common with this
*/
private boolean intersects(Interval o)
{
return (o.x1 >= x1 && o.x1 <= x2) || (o.x2 >= x1 && o.x2 <= x2);
return (o.min >= min && o.min <= max) || (o.max >= min && o.max <= max);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment