Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. package lighting;
  2.  
  3. import java.awt.Polygon;
  4. import java.awt.geom.Area;
  5. import java.awt.geom.Line2D;
  6. import java.awt.geom.PathIterator;
  7. import java.awt.geom.Point2D;
  8.  
  9. public class Obscurer {
  10. private Polygon profile;
  11. private Area area;
  12. private Line2D.Double[] lines = new Line2D.Double[0];
  13.  
  14. public Obscurer(Polygon prof) {
  15. this.profile = prof;
  16. this.area = new Area(this.profile);
  17. }
  18.  
  19. public Polygon getProfile() {
  20. return profile;
  21. }
  22.  
  23. public void doSegments() {
  24. /*
  25. for(int i = 0; i < Main.obscList.size(); i++) {
  26. Obscurer o = Main.obscList.get(i);
  27. if(o.equals(this)) continue;
  28. Area test = (Area) area.clone();
  29. test.intersect(o.area);
  30. if((test.getBounds().width+test.getBounds().height) > 0) {
  31. area.add(o.area);
  32. Polygon temp = new Polygon();
  33. PathIterator path = area.getPathIterator(null);
  34. while (!path.isDone()) {
  35. toPolygon(path,temp);
  36. path.next();
  37. }
  38. Main.obscList.remove(o);
  39. i = 0;
  40. profile = temp;
  41. }
  42.  
  43. }*/
  44. Point2D.Double[] points = new Point2D.Double[profile.npoints];
  45. for(int i = 0; i < profile.npoints; i++) {
  46. points[i] = new Point2D.Double(profile.xpoints[i], profile.ypoints[i]);
  47. }
  48. Line2D.Double[] segments = new Line2D.Double[profile.npoints];
  49. for(int i = 0; i < profile.npoints;i++) {
  50. segments[i] = new Line2D.Double(points[i].getX(), points[i].getY(), points[(i+1)%profile.npoints].getX(), points[(i+1)%profile.npoints].getY());
  51. }
  52. this.lines = segments;
  53. }
  54.  
  55. private static void toPolygon(PathIterator p_path,Polygon p) {
  56. double[] point = new double[2];
  57. if(p_path.currentSegment(point) != PathIterator.SEG_CLOSE) {
  58. p.addPoint((int) point[0], (int) point[1]);
  59. }
  60. }
  61.  
  62.  
  63. public Line2D.Double[] lineSegments() {
  64. return lines.clone();
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement