/android/LGame-Android-0.2.8/LGame-Android-0.2.8-update2/org/loon/framework/android/game/core/graphics/geom/CurveLink.java

http://loon-simple.googlecode.com/ · Java · 115 lines · 73 code · 18 blank · 24 comment · 15 complexity · 117dd762702fe93e02d3daa6cfac78cf MD5 · raw file

  1. /*
  2. * Copyright 1998 Sun Microsystems, Inc. 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. Sun designates this
  8. * particular file as subject to the "Classpath" exception as provided
  9. * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22. * CA 95054 USA or visit www.sun.com if you need additional information or
  23. * have any questions.
  24. */
  25. package org.loon.framework.android.game.core.graphics.geom;
  26. final class CurveLink {
  27. Curve curve;
  28. double ytop;
  29. double ybot;
  30. int etag;
  31. CurveLink next;
  32. public CurveLink(Curve curve, double ystart, double yend, int etag) {
  33. this.curve = curve;
  34. this.ytop = ystart;
  35. this.ybot = yend;
  36. this.etag = etag;
  37. if (ytop < curve.getYTop() || ybot > curve.getYBot()) {
  38. throw new InternalError("bad curvelink [" + ytop + "=>" + ybot
  39. + "] for " + curve);
  40. }
  41. }
  42. public boolean absorb(CurveLink link) {
  43. return absorb(link.curve, link.ytop, link.ybot, link.etag);
  44. }
  45. public boolean absorb(Curve curve, double ystart, double yend, int etag) {
  46. if (this.curve != curve || this.etag != etag || ybot < ystart
  47. || ytop > yend) {
  48. return false;
  49. }
  50. if (ystart < curve.getYTop() || yend > curve.getYBot()) {
  51. throw new InternalError("bad curvelink [" + ystart + "=>" + yend
  52. + "] for " + curve);
  53. }
  54. this.ytop = Math.min(ytop, ystart);
  55. this.ybot = Math.max(ybot, yend);
  56. return true;
  57. }
  58. public boolean isEmpty() {
  59. return (ytop == ybot);
  60. }
  61. public Curve getCurve() {
  62. return curve;
  63. }
  64. public Curve getSubCurve() {
  65. if (ytop == curve.getYTop() && ybot == curve.getYBot()) {
  66. return curve.getWithDirection(etag);
  67. }
  68. return curve.getSubCurve(ytop, ybot, etag);
  69. }
  70. public Curve getMoveto() {
  71. return new Order0(getXTop(), getYTop());
  72. }
  73. public double getXTop() {
  74. return curve.XforY(ytop);
  75. }
  76. public double getYTop() {
  77. return ytop;
  78. }
  79. public double getXBot() {
  80. return curve.XforY(ybot);
  81. }
  82. public double getYBot() {
  83. return ybot;
  84. }
  85. public double getX() {
  86. return curve.XforY(ytop);
  87. }
  88. public int getEdgeTag() {
  89. return etag;
  90. }
  91. public void setNext(CurveLink link) {
  92. this.next = link;
  93. }
  94. public CurveLink getNext() {
  95. return next;
  96. }
  97. }