< prev index next >

openjfx9/modules/javafx.graphics/src/main/java/com/sun/marlin/CollinearSimplifier.java

Print this page


   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.java2d.marlin;
  27 
  28 import sun.awt.geom.PathConsumer2D;
  29 
  30 final class CollinearSimplifier implements PathConsumer2D {
  31 
  32     enum SimplifierState {
  33 
  34         Empty, PreviousPoint, PreviousLine
  35     };
  36     // slope precision threshold
  37     static final float EPS = 1e-4f; // aaime proposed 1e-3f
  38 
  39     PathConsumer2D delegate;
  40     SimplifierState state;
  41     float px1, py1, px2, py2;
  42     float pslope;
  43 
  44     CollinearSimplifier() {
  45     }
  46 
  47     public CollinearSimplifier init(PathConsumer2D delegate) {
  48         this.delegate = delegate;
  49         this.state = SimplifierState.Empty;
  50 
  51         return this; // fluent API
  52     }
  53 
  54     @Override
  55     public void pathDone() {
  56         emitStashedLine();
  57         state = SimplifierState.Empty;
  58         delegate.pathDone();
  59     }
  60 
  61     @Override
  62     public void closePath() {
  63         emitStashedLine();
  64         state = SimplifierState.Empty;
  65         delegate.closePath();
  66     }
  67 
  68     @Override
  69     public long getNativeConsumer() {
  70         return 0;
  71     }
  72 
  73     @Override
  74     public void quadTo(float x1, float y1, float x2, float y2) {
  75         emitStashedLine();
  76         delegate.quadTo(x1, y1, x2, y2);
  77         // final end point:
  78         state = SimplifierState.PreviousPoint;
  79         px1 = x2;
  80         py1 = y2;
  81     }
  82 
  83     @Override
  84     public void curveTo(float x1, float y1, float x2, float y2,
  85                         float x3, float y3) {
  86         emitStashedLine();
  87         delegate.curveTo(x1, y1, x2, y2, x3, y3);
  88         // final end point:
  89         state = SimplifierState.PreviousPoint;
  90         px1 = x3;


   1 /*
   2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.marlin;
  27 
  28 import com.sun.javafx.geom.PathConsumer2D;
  29 
  30 public final class CollinearSimplifier implements PathConsumer2D {
  31 
  32     enum SimplifierState {
  33 
  34         Empty, PreviousPoint, PreviousLine
  35     };
  36     // slope precision threshold
  37     static final float EPS = 1e-4f; // aaime proposed 1e-3f
  38 
  39     PathConsumer2D delegate;
  40     SimplifierState state;
  41     float px1, py1, px2, py2;
  42     float pslope;
  43 
  44     CollinearSimplifier() {
  45     }
  46 
  47     public CollinearSimplifier init(PathConsumer2D delegate) {
  48         this.delegate = delegate;
  49         this.state = SimplifierState.Empty;
  50 
  51         return this; // fluent API
  52     }
  53 
  54     @Override
  55     public void pathDone() {
  56         emitStashedLine();
  57         state = SimplifierState.Empty;
  58         delegate.pathDone();
  59     }
  60 
  61     @Override
  62     public void closePath() {
  63         emitStashedLine();
  64         state = SimplifierState.Empty;
  65         delegate.closePath();





  66     }
  67 
  68     @Override
  69     public void quadTo(float x1, float y1, float x2, float y2) {
  70         emitStashedLine();
  71         delegate.quadTo(x1, y1, x2, y2);
  72         // final end point:
  73         state = SimplifierState.PreviousPoint;
  74         px1 = x2;
  75         py1 = y2;
  76     }
  77 
  78     @Override
  79     public void curveTo(float x1, float y1, float x2, float y2,
  80                         float x3, float y3) {
  81         emitStashedLine();
  82         delegate.curveTo(x1, y1, x2, y2, x3, y3);
  83         // final end point:
  84         state = SimplifierState.PreviousPoint;
  85         px1 = x3;


< prev index next >