Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Projet GORDYJAN_BAGNOLY_GARCIA_POIGNONNEC
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
POIGNONNEC
Projet GORDYJAN_BAGNOLY_GARCIA_POIGNONNEC
Commits
3084998b
Commit
3084998b
authored
Apr 29, 2019
by
Arthur POIGNONNEC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DEV] Création de l'objet view (Visibilité)
parent
50df6dba
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
170 additions
and
6 deletions
+170
-6
Block.java
src/main/Block.java
+42
-0
Point.java
src/main/Point.java
+8
-0
Segment.java
src/main/Segment.java
+10
-6
View.java
src/main/View.java
+110
-0
No files found.
src/main/Block.java
0 → 100644
View file @
3084998b
package
main
;
public
class
Block
{
// VARIABLES
private
Double
x
;
private
Double
y
;
private
Double
r
;
// CONSTRUCTOR
public
Block
(
Double
x
,
Double
y
,
Double
r
)
{
this
.
x
=
x
;
this
.
y
=
y
;
this
.
r
=
r
;
}
// GETTERS / SETTERS
public
Double
getX
()
{
return
x
;
}
public
void
setX
(
Double
x
)
{
this
.
x
=
x
;
}
public
Double
getY
()
{
return
y
;
}
public
void
setY
(
Double
y
)
{
this
.
y
=
y
;
}
public
Double
getR
()
{
return
r
;
}
public
void
setR
(
Double
r
)
{
this
.
r
=
r
;
}
}
src/main/Point.java
View file @
3084998b
...
@@ -24,6 +24,14 @@ public class Point {
...
@@ -24,6 +24,14 @@ public class Point {
return
y
;
return
y
;
}
}
public
void
setX
(
double
x
)
{
this
.
x
=
x
;
}
public
void
setY
(
double
y
)
{
this
.
y
=
y
;
}
public
String
toString
(){
public
String
toString
(){
return
"("
+
x
+
","
+
y
+
")"
;
return
"("
+
x
+
","
+
y
+
")"
;
}
}
...
...
src/main/Segment.java
View file @
3084998b
...
@@ -5,11 +5,15 @@ public class Segment {
...
@@ -5,11 +5,15 @@ public class Segment {
// VARIABLES
// VARIABLES
private
Edge
p1
;
private
Edge
p1
;
private
Edge
p2
;
private
Edge
p2
;
private
Double
d
istance
;
private
Double
d
;
//CONSTRUCTOR
//CONSTRUCTOR
public
Segment
(){
public
Segment
(
Edge
_p1
,
Edge
_p2
){
this
.
p1
=
_p1
;
this
.
p2
=
_p2
;
p1
.
setSegment
(
this
);
p2
.
setSegment
(
this
);
}
}
// GETTERS / SETTERS
// GETTERS / SETTERS
...
@@ -29,11 +33,11 @@ public class Segment {
...
@@ -29,11 +33,11 @@ public class Segment {
this
.
p2
=
p2
;
this
.
p2
=
p2
;
}
}
public
Double
getD
istance
()
{
public
Double
getD
()
{
return
d
istance
;
return
d
;
}
}
public
void
setD
istance
(
Double
distance
)
{
public
void
setD
(
Double
d
)
{
this
.
d
istance
=
distance
;
this
.
d
=
d
;
}
}
}
}
src/main/View.java
0 → 100644
View file @
3084998b
package
main
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
View
{
// VARIABLES
private
List
<
Segment
>
segments
;
private
List
<
Edge
>
edges
;
private
Point
viewer
;
// CONSTRUCTOR
public
View
()
{
this
.
segments
=
new
ArrayList
<>();
this
.
edges
=
new
ArrayList
<>();
this
.
viewer
=
new
Point
(
0
d
,
0
d
);
}
// METHODES
/**
* Creation of the map borders
* @param size
*/
public
void
loadEdgeOfMap
(
Double
size
){
addSegment
(
0
d
,
0
d
,
0
d
,
size
);
addSegment
(
0
d
,
0
d
,
size
,
0
d
);
addSegment
(
size
,
0
d
,
size
,
size
);
addSegment
(
0
d
,
size
,
size
,
size
);
}
/**
* Add a segment to the view
* @param x1
* @param y1
* @param x2
* @param y2
*/
public
void
addSegment
(
Double
x1
,
Double
y1
,
Double
x2
,
Double
y2
){
Edge
p1
=
new
Edge
(
x1
,
y1
);
Edge
p2
=
new
Edge
(
x2
,
y2
);
Segment
segment
=
new
Segment
(
p1
,
p2
);
segments
.
add
(
segment
);
edges
.
add
(
p1
);
edges
.
add
(
p2
);
}
/**
* Loading elements composing the map
* @param size
* @param blocks
* @param walls
*/
public
void
loadMap
(
Double
size
,
List
<
Block
>
blocks
,
List
<
Segment
>
walls
){
segments
.
clear
();
edges
.
clear
();
// Loading the edge of the map
loadEdgeOfMap
(
size
);
// Streaming the list of blocks to create their segments
blocks
.
stream
().
forEach
(
b
->
{
// Recovering properties of the current block
Double
x
=
b
.
getX
();
Double
y
=
b
.
getY
();
Double
r
=
b
.
getR
();
// Building the segments composing the block
addSegment
(
x
-
r
,
y
-
r
,
x
-
r
,
y
+
r
);
addSegment
(
x
-
r
,
y
+
r
,
x
+
r
,
y
+
r
);
addSegment
(
x
+
r
,
y
+
r
,
x
+
r
,
y
-
r
);
addSegment
(
x
+
r
,
y
-
r
,
x
-
r
,
y
-
r
);
});
// Streaming the list of walls to create corresponding segments
walls
.
stream
().
forEach
(
w
->
{
addSegment
(
w
.
getP1
().
getX
(),
w
.
getP1
().
getY
(),
w
.
getP2
().
getX
(),
w
.
getP2
().
getY
());
});
}
/**
* Set the position of the viewer
* @param x
* @param y
*/
public
void
setViewerLocation
(
Double
x
,
Double
y
){
viewer
.
setX
(
x
);
viewer
.
setY
(
y
);
segments
.
stream
().
forEach
(
seg
->
{
Double
dx
=
0.5
*
(
seg
.
getP1
().
getX
()
+
seg
.
getP2
().
getX
())
-
x
;
Double
dy
=
0.5
*
(
seg
.
getP1
().
getY
()
+
seg
.
getP2
().
getY
())
-
y
;
seg
.
setD
(
dx
*
dx
+
dy
*
dy
);
seg
.
getP1
().
setAngle
(
Math
.
atan2
(
seg
.
getP1
().
getY
()
-
y
,
seg
.
getP1
().
getX
()
-
x
));
seg
.
getP2
().
setAngle
(
Math
.
atan2
(
seg
.
getP2
().
getY
()
-
y
,
seg
.
getP2
().
getX
()
-
x
));
Double
dAngle
=
seg
.
getP2
().
getAngle
()
-
seg
.
getP1
().
getAngle
();
if
(
dAngle
<=
-
Math
.
PI
)
dAngle
+=
2
*
Math
.
PI
;
if
(
dAngle
>
Math
.
PI
)
dAngle
-=
2
*
Math
.
PI
;
seg
.
getP1
().
setBegin
(
dAngle
>
0
d
);
seg
.
getP2
().
setBegin
(!
seg
.
getP1
().
getBegin
());
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment