From 2570c1bee6dd8b33ac2e92b533e32b69b02a2cfc Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Fri, 6 May 2011 14:50:56 +0200
Subject: GlyphShape: Use switch block for PathIterator - adding default
 (exception)

Implements more of John Pritchard <jdp@syntelos.org> proposal
      https://github.com/syntelos/jogl/commit/05a7ec92d30e1e688b1eb7cc317cad83a0e8fd60
---
 .../classes/jogamp/graph/math/plane/Crossing.java  | 102 +++++++++++----------
 1 file changed, 54 insertions(+), 48 deletions(-)

(limited to 'src/jogl/classes/jogamp/graph/math')

diff --git a/src/jogl/classes/jogamp/graph/math/plane/Crossing.java b/src/jogl/classes/jogamp/graph/math/plane/Crossing.java
index 2138b217d..9be5978cc 100644
--- a/src/jogl/classes/jogamp/graph/math/plane/Crossing.java
+++ b/src/jogl/classes/jogamp/graph/math/plane/Crossing.java
@@ -467,31 +467,34 @@ public class Crossing {
         int cross = 0;
         float mx, my, cx, cy;
         mx = my = cx = cy = 0.0f;
-        float coords[] = new float[6];
+        final float coords[] = new float[6];
 
         while (!p.isDone()) {
-            switch (p.currentSegment(coords)) {
-            case PathIterator.SEG_MOVETO:
-                if (cx != mx || cy != my) {
-                    cross += crossLine(cx, cy, mx, my, x, y);
-                }
-                mx = cx = coords[0];
-                my = cy = coords[1];
-                break;
-            case PathIterator.SEG_LINETO:
-                cross += crossLine(cx, cy, cx = coords[0], cy = coords[1], x, y);
-                break;
-            case PathIterator.SEG_QUADTO:
-                cross += crossQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], x, y);
-                break;
-            case PathIterator.SEG_CUBICTO:
-                cross += crossCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], x, y);
-                break;
-            case PathIterator.SEG_CLOSE:
-                if (cy != my || cx != mx) {
-                    cross += crossLine(cx, cy, cx = mx, cy = my, x, y);
-                }
-                break;
+            final int segmentType = p.currentSegment(coords);
+            switch (segmentType) {
+                case PathIterator.SEG_MOVETO:
+                    if (cx != mx || cy != my) {
+                        cross += crossLine(cx, cy, mx, my, x, y);
+                    }
+                    mx = cx = coords[0];
+                    my = cy = coords[1];
+                    break;
+                case PathIterator.SEG_LINETO:
+                    cross += crossLine(cx, cy, cx = coords[0], cy = coords[1], x, y);
+                    break;
+                case PathIterator.SEG_QUADTO:
+                    cross += crossQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], x, y);
+                    break;
+                case PathIterator.SEG_CUBICTO:
+                    cross += crossCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], x, y);
+                    break;
+                case PathIterator.SEG_CLOSE:
+                    if (cy != my || cx != mx) {
+                        cross += crossLine(cx, cy, cx = mx, cy = my, x, y);
+                    }
+                    break;
+                default:
+                    throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType);                
             }
             
             // checks if the point (x,y) is the vertex of shape with PathIterator p           
@@ -821,7 +824,7 @@ public class Crossing {
         int count;
         float mx, my, cx, cy;
         mx = my = cx = cy = 0.0f;
-        float coords[] = new float[6];
+        final float coords[] = new float[6];
 
         float rx1 = x;
         float ry1 = y;
@@ -830,30 +833,33 @@ public class Crossing {
 
         while (!p.isDone()) {
             count = 0;
-            switch (p.currentSegment(coords)) {
-            case PathIterator.SEG_MOVETO:
-                if (cx != mx || cy != my) {
-                    count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
-                }
-                mx = cx = coords[0];
-                my = cy = coords[1];
-                break;
-            case PathIterator.SEG_LINETO:
-                count = intersectLine(cx, cy, cx = coords[0], cy = coords[1], rx1, ry1, rx2, ry2);
-                break;
-            case PathIterator.SEG_QUADTO:
-                count = intersectQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], rx1, ry1, rx2, ry2);
-                break;
-            case PathIterator.SEG_CUBICTO:
-                count = intersectCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], rx1, ry1, rx2, ry2);
-                break;
-            case PathIterator.SEG_CLOSE:
-                if (cy != my || cx != mx) {
-                    count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
-                }
-                cx = mx;
-                cy = my;
-                break;
+            final int segmentType = p.currentSegment(coords);
+            switch (segmentType) {
+                case PathIterator.SEG_MOVETO:
+                    if (cx != mx || cy != my) {
+                        count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
+                    }
+                    mx = cx = coords[0];
+                    my = cy = coords[1];
+                    break;
+                case PathIterator.SEG_LINETO:
+                    count = intersectLine(cx, cy, cx = coords[0], cy = coords[1], rx1, ry1, rx2, ry2);
+                    break;
+                case PathIterator.SEG_QUADTO:
+                    count = intersectQuad(cx, cy, coords[0], coords[1], cx = coords[2], cy = coords[3], rx1, ry1, rx2, ry2);
+                    break;
+                case PathIterator.SEG_CUBICTO:
+                    count = intersectCubic(cx, cy, coords[0], coords[1], coords[2], coords[3], cx = coords[4], cy = coords[5], rx1, ry1, rx2, ry2);
+                    break;
+                case PathIterator.SEG_CLOSE:
+                    if (cy != my || cx != mx) {
+                        count = intersectLine(cx, cy, mx, my, rx1, ry1, rx2, ry2);
+                    }
+                    cx = mx;
+                    cy = my;
+                    break;
+                default:
+                    throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType);
             }
             if (count == CROSSING) {
                 return CROSSING;
-- 
cgit v1.2.3