Skip to content

Commit

Permalink
refactoring of get profile (fix, simplification, clarity, performance)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Oct 16, 2024
1 parent 16789ed commit 4174cef
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3507,6 +3507,7 @@ public void TC11() throws IOException {
.vEdgeDiff(true)
.setGs(0.5)
.build();
rayData.setReflexionOrder(0);

//Propagation process path data building
AttenuationCnossosParameters attData = new AttenuationCnossosParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void poly2D_3D(){
*/
public Building(Polygon poly, double height, List<Double> alphas, int key, boolean zBuildings) {
this.poly = poly;
// Fix clock wise orientation of the polygon and inner holes
this.poly.normalize();
this.height = height;
this.alphas = new ArrayList<>();
this.alphas.addAll(alphas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,105 +224,17 @@ public String toString() {
return str;
}


/**
*
* @param cutPoint
* @return
*/
public int compareTox01y01(CutPoint cutPoint) {
if(this.coordinate.x < cutPoint.coordinate.x ||
(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y < cutPoint.coordinate.y)) {
return -1;
}
if(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y == cutPoint.coordinate.y) {
return 0;
}
else {
return 1;
}
}


/**
*
* @param cutPoint
* @return
*/
public int compareTox10y01(CutPoint cutPoint) {
if(this.coordinate.x > cutPoint.coordinate.x ||
(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y < cutPoint.coordinate.y)) {
return -1;
}
if(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y == cutPoint.coordinate.y) {
return 0;
}
else {
return 1;
}
}

/**
*
* @param cutPoint
* @return
*/
public int compareTox01y10(CutPoint cutPoint) {
if(this.coordinate.x < cutPoint.coordinate.x ||
(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y > cutPoint.coordinate.y)) {
return -1;
}
if(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y == cutPoint.coordinate.y) {
return 0;
}
else {
return 1;
}
}


/**
*
* @param cutPoint
* @return
*/
public int compareTox10y10(CutPoint cutPoint) {
if(this.coordinate.x > cutPoint.coordinate.x ||
(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y > cutPoint.coordinate.y)) {
return -1;
}
if(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y == cutPoint.coordinate.y) {
return 0;
}
else {
return 1;
}
}


/**
*
* @param cutPoint the object to be compared.
* @return
*/
@Override
public int compareTo(CutPoint cutPoint) {
if(this.coordinate.x < cutPoint.coordinate.x ||
(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y < cutPoint.coordinate.y)) {
return -1;
}
if(this.coordinate.x == cutPoint.coordinate.x && this.coordinate.y == cutPoint.coordinate.y) {
return 0;
}
else {
return 1;
}
return this.coordinate.compareTo(cutPoint.coordinate);
}

public boolean isCorner(){
return corner;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.noise_planet.noisemodelling.pathfinder.profilebuilder;

import org.locationtech.jts.geom.Coordinate;

import java.util.Comparator;

public class CutPointDistanceComparator implements Comparator<CutPoint> {
private final Coordinate reference;

public CutPointDistanceComparator(Coordinate reference) {
this.reference = reference;
}

@Override
public int compare(CutPoint o1, CutPoint o2) {
return Double.compare(o1.coordinate.distance(reference), o2.coordinate.distance(reference));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,47 @@ public class CutProfile {
* Add the source point.
* @param coord Coordinate of the source point.
*/
public void addSource(Coordinate coord) {
public CutPoint addSource(Coordinate coord) {
source = new CutPoint(coord, SOURCE, -1);
pts.add(0, source);
pts.add(source);
return source;
}

/**
* Add the receiver point.
* @param coord Coordinate of the receiver point.
*/
public void addReceiver(Coordinate coord) {
public CutPoint addReceiver(Coordinate coord) {
receiver = new CutPoint(coord, RECEIVER, -1);
pts.add(receiver);
return receiver;
}

/**
* Add a building cutting point.
* @param coord Coordinate of the cutting point.
* @param buildingId Id of the cut building.
*/
public void addBuildingCutPt(Coordinate coord, int buildingId, int wallId, boolean corner) {
public CutPoint addBuildingCutPt(Coordinate coord, int buildingId, int wallId, boolean corner) {
CutPoint cut = new CutPoint(coord, ProfileBuilder.IntersectionType.BUILDING, buildingId, corner);
cut.buildingId = buildingId;
cut.wallId = wallId;
pts.add(cut);
pts.get(pts.size()-1).buildingId = buildingId;
hasBuildingInter = true;
return cut;
}

/**
* Add a building cutting point.
* @param coord Coordinate of the cutting point.
* @param id Id of the cut building.
*/
public void addWallCutPt(Coordinate coord, int id, boolean corner) {
pts.add(new CutPoint(coord, ProfileBuilder.IntersectionType.WALL, id, corner));
pts.get(pts.size()-1).wallId = id;
public CutPoint addWallCutPt(Coordinate coord, int id, boolean corner) {
CutPoint wallPoint = new CutPoint(coord, ProfileBuilder.IntersectionType.WALL, id, corner);
wallPoint.wallId = id;
pts.add(wallPoint);
hasBuildingInter = true;
return wallPoint;
}

/**
Expand Down Expand Up @@ -154,25 +159,10 @@ public CutPoint getReceiver() {
}

/**
* Sort the CutPoints by there coordinates
* Sort the CutPoints by distance with c0
*/
public void sort(Coordinate c0, Coordinate c1) {
if(c0.x<=c1.x){
if(c0.y<=c1.y){
pts.sort(CutPoint::compareTox01y01);
}
else {
pts.sort(CutPoint::compareTox01y10);
}
}
if(c0.x>c1.x){
if(c0.y<=c1.y){
pts.sort(CutPoint::compareTox10y01);
}
else {
pts.sort(CutPoint::compareTox10y10);
}
}
public void sort(Coordinate c0) {
pts.sort(new CutPointDistanceComparator(c0));
}

/**
Expand Down
Loading

0 comments on commit 4174cef

Please sign in to comment.