Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • akooobon1u
  • doan5u
  • lucas
  • main
  • mandler4u
  • mingot2u
  • paulin38u
  • pierron9
  • pozzodib1u
  • wissle1u
10 results

Target

Select target project
  • pierron9/sphere
1 result
Select Git revision
  • akooobon1u
  • doan5u
  • lucas
  • main
  • mandler4u
  • mingot2u
  • paulin38u
  • pierron9
  • pozzodib1u
  • wissle1u
10 results
Show changes
Commits on Source (3)
target
.DS_Store
.vscode
.idea
......@@ -10,53 +10,53 @@ public class Sphere {
// Constructors
// ***********************************************************************
public Sphere() {
radius_ = 0.0;
pos_ = new Point3d();
radiusProtected = 0.0;
posProtected = new Point3d();
}
public Sphere(double radius) {
radius_ = radius;
pos_ = new Point3d();
radiusProtected = radius;
posProtected = new Point3d();
}
public Sphere(double radius, Point3d pos) {
radius_ = radius;
pos_ = pos;
radiusProtected = radius;
posProtected = pos;
}
// ***********************************************************************
// Methods
// ***********************************************************************
public double computeVolume() {
return 4 * Math.PI * Math.pow(radius_, 2) / 3;
return 4 * Math.PI * Math.pow(radiusProtected, 3) / 3;
}
public double distanceTo(Sphere other) {
return pos_.distance(other.pos_);
return posProtected.distance(other.posProtected);
}
public double distanceSquaredTo(Sphere other) {
return pos_.distanceSquared(other.pos_);
return posProtected.distanceSquared(other.posProtected);
}
public boolean inContactWith(Sphere other) {
return distanceSquaredTo(other) <= Math.pow(radius_ + other.radius_, 2);
return distanceSquaredTo(other) <= Math.pow(radiusProtected + other.radiusProtected, 2);
}
// ***********************************************************************
// Accessors
// ***********************************************************************
public Point3d getPos() {
return pos_;
return posProtected;
}
public double getRadius() {
return radius_;
return radiusProtected;
}
// ***********************************************************************
// Attributes
// ***********************************************************************
protected double radius_ = 0.0;
protected Point3d pos_;
protected double radiusProtected = 0.0;
protected Point3d posProtected;
}
package fr.nancy.iut;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import javax.vecmath.Point3d;
/**
* Created by dparsons on 12/08/15.
*/
public class SphereTest {
class SphereTest {
private Sphere sphere1;
private Sphere sphere2;
private Sphere sphere3;
@Test
public void testComputeVolume() throws Exception {
void testComputeVolume() throws Exception {
Sphere mySphere = new Sphere(1.5);
assertEquals(14.137166941154069, mySphere.computeVolume(), 0.0);
}
@BeforeEach
void setUp() {
sphere1 = new Sphere();
sphere2 = new Sphere(3.0);
sphere3 = new Sphere( 5.0, new Point3d(1, 2, 3));
}
@Test
void distanceTo() {
assertEquals(0.0, sphere1.distanceTo(sphere2));
assertEquals(3.7416573867739413, sphere1.distanceTo(sphere3), 0.0001);
assertEquals(3.7416573867739413, sphere2.distanceTo(sphere3), 0.0001);
}
@Test
void distanceSquaredTo() {
assertEquals(0.0, sphere1.distanceSquaredTo(sphere2));
assertEquals(14.0, sphere1.distanceSquaredTo(sphere3), 0.0001);
assertEquals(14.0, sphere2.distanceSquaredTo(sphere3), 0.0001);
}
@Test
void inContactWith() {
assertTrue(sphere1.inContactWith(sphere2));
assertFalse(!sphere1.inContactWith(sphere3));
assertFalse(!sphere2.inContactWith(sphere3));
}
@Test
void getPos() {
Point3d point0 = new Point3d();
Point3d point123 = new Point3d(1, 2, 3);
assertEquals(point0, sphere1.getPos());
assertEquals(point0, sphere2.getPos());
assertEquals(point123, sphere3.getPos());
}
@Test
void getRadius() {
assertEquals(0.0, sphere1.getRadius());
assertEquals(3.0, sphere2.getRadius());
assertEquals(5.0, sphere3.getRadius());
}
}
\ No newline at end of file