Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibLaserCut
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Elektronikföreningen Admittansen
LibLaserCut
Commits
713747b5
Commit
713747b5
authored
12 years ago
by
Thomas Oster
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Add missing Interval-Class
parent
2f1cf6c9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/com/t_oster/liblasercut/platform/Rectangle.java
+49
-26
49 additions, 26 deletions
src/com/t_oster/liblasercut/platform/Rectangle.java
with
49 additions
and
26 deletions
src/com/t_oster/liblasercut/platform/Rectangle.java
+
49
−
26
View file @
713747b5
/**
* This file is part of VisiCut.
* Copyright (C) 2012 Max Gaukler <development@maxgaukler.de>
*
*
* VisiCut is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* VisiCut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with VisiCut. If not, see <http://www.gnu.org/licenses/>.
**/
package
com.t_oster.liblasercut.platform
;
/**
* (not really compatible) replacement of java.awt.Rectangle,
* (not really compatible) replacement of java.awt.Rectangle,
* This Rectangle cannot be "empty" - at minimum it needs to have one point.
*
*
* @see Point
*/
public
class
Rectangle
{
private
int
x1
,
x2
,
y1
,
y2
;
private
class
Interval
{
private
int
x1
,
x2
;
private
Interval
(
int
x1
,
int
x2
)
{
this
.
x1
=
x1
;
this
.
x2
=
x2
;
}
private
boolean
isSubsetOf
(
Interval
o
)
{
return
o
.
x1
<=
x1
&&
o
.
x2
>=
x2
;
}
private
boolean
intersects
(
Interval
o
)
{
return
(
o
.
x1
>=
x1
&&
o
.
x1
<=
x2
)
||
(
o
.
x2
>=
x1
&&
o
.
x2
<=
x2
);
}
}
/**
* construct a rectangle with the corners (x1,y1) and (x2,y2)
*/
...
...
@@ -36,22 +59,22 @@ public class Rectangle {
this
.
y1
=
Math
.
min
(
y1
,
y2
);
this
.
y2
=
Math
.
max
(
y1
,
y2
);
}
/**
* Construct a rectangle with the corners p1 and p2
*/
public
Rectangle
(
Point
p1
,
Point
p2
)
{
this
(
p1
.
x
,
p1
.
y
,
p2
.
x
,
p2
.
y
);
}
/**
/**
* construct a rectangle with only one point p
*/
public
Rectangle
(
Point
p
)
{
this
(
p
,
p
);
}
/**
* add a point to the boundary of this rectangle
* use this iteratively to get the boundingBox
...
...
@@ -62,20 +85,20 @@ public class Rectangle {
}
else
if
(
x
>
x2
)
{
this
.
x2
=
x
;
}
if
(
y
<
y1
)
{
this
.
y1
=
y
;
}
else
if
(
y
>
y2
)
{
this
.
y2
=
y
;
}
}
public
void
add
(
Point
p
)
{
if
(
p
!=
null
)
{
add
(
p
.
x
,
p
.
y
);
}
}
/**
* smallest X coordinate
* @return int
...
...
@@ -83,42 +106,42 @@ public class Rectangle {
public
int
getXMin
()
{
return
x1
;
}
/**
* greatest X coordinate
*/
public
int
getXMax
()
{
return
x2
;
}
/**
* smallest Y coordinate
*/
public
int
getYMin
()
{
return
y1
;
}
/**
* greatest Y coordinate
*/
public
int
getYMax
()
{
return
y2
;
}
/**
/**
* X interval from left to right
*/
p
ublic
Interval
getXInterval
()
{
p
rivate
Interval
getXInterval
()
{
return
new
Interval
(
x1
,
x2
);
}
/**
/**
* Y interval from top to bottom
*/
p
ublic
Interval
getYInterval
()
{
p
rivate
Interval
getYInterval
()
{
return
new
Interval
(
y1
,
y2
);
}
@Override
public
String
toString
()
{
return
"Rectangle(x1="
+
x1
+
",y1="
+
y1
+
",x2="
+
x2
+
",y2="
+
y2
+
")"
;
...
...
@@ -129,17 +152,17 @@ public class Rectangle {
{
return
new
Rectangle
(
x1
,
y1
,
x2
,
y2
);
}
/**
* check if this is inside of (or equal) another rectangle
* @param other
* @return true if this rectangle is equal to or inside of the other one
*/
public
boolean
isInsideOf
(
Rectangle
other
)
{
return
this
.
getXInterval
().
isSubsetOf
(
other
.
getXInterval
())
return
this
.
getXInterval
().
isSubsetOf
(
other
.
getXInterval
())
&&
this
.
getYInterval
().
isSubsetOf
(
other
.
getYInterval
());
}
/**
* check if the intersection of this rectangle with another one is not empty
* @param other
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment