Esempio n. 1
0
  private Action<?> walk(AmObject cobj) {

    Action<?> action = visitor.preorderVisit(cobj, context);
    if (action == null) action = Action.next();

    final AmObject walkObj = extractWalkObject(cobj, action);
    if (walkObj != null) {
      // walk children
      UpdatingIterator it = getChildrenOf(walkObj);
      context.getAmParents().addLast(walkObj);
      while (it.hasNext()) {
        AmObject child = it.next();
        Action<?> childAction = walk(child);
        processAction(childAction, it);
      }
      context.getAmParents().removeLast();
    }

    Action<?> postAction =
        visitor.postorderVisit(walkObj != null ? walkObj : cobj, context, action);
    if (postAction == null) postAction = Action.next;

    action = action.mergeWith(postAction);
    return action;
  }
Esempio n. 2
0
 /**
  * Adds the value to the collection given by map.get(key). A new collection is created using the
  * supplied CollectionFactory.
  */
 public static <K, V, C extends Collection<V>> void putIntoValueCollection(
     Map<K, C> map, K key, V value, CollectionFactory<V> cf) {
   C c = map.get(key);
   if (c == null) {
     c = ErasureUtils.<C>uncheckedCast(cf.newCollection());
     map.put(key, c);
   }
   c.add(value);
 }
 /**
  * Gets an object from the cache. Performs a cleanup first If accessOrder is true, refreshed the
  * timestamp
  *
  * @param key the key of the object
  * @return the object or null
  */
 @Override
 public C get(Object key) {
   cleanup();
   C value = super.get(key);
   if (accessOrder && value != null) {
     value.refreshCacheTime();
   }
   return value;
 }
Esempio n. 4
0
 public static void testConfigurableForNonPrimitives() {
   Map<String, String> p = new HashMap<String, String>();
   C config = Configurable.createConfigurable(C.class, p);
   assertNull(config.port());
   p.put("port", "10");
   config = Configurable.createConfigurable(C.class, p);
   assertEquals(Integer.valueOf(10), config.port()); // property port is
   // not set
 }
  @SuppressWarnings("unchecked")
  private void executeAndRestoreDefaultProjectSettings(
      @NotNull Project project, @NotNull Runnable task) {
    if (!project.isDefault()) {
      task.run();
      return;
    }

    AbstractExternalSystemSettings systemSettings =
        ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
    Object systemStateToRestore = null;
    if (systemSettings instanceof PersistentStateComponent) {
      systemStateToRestore = ((PersistentStateComponent) systemSettings).getState();
    }
    systemSettings.copyFrom(myControl.getSystemSettings());
    Collection projectSettingsToRestore = systemSettings.getLinkedProjectsSettings();
    systemSettings.setLinkedProjectsSettings(
        Collections.singleton(getCurrentExternalProjectSettings()));
    try {
      task.run();
    } finally {
      if (systemStateToRestore != null) {
        ((PersistentStateComponent) systemSettings).loadState(systemStateToRestore);
      } else {
        systemSettings.setLinkedProjectsSettings(projectSettingsToRestore);
      }
    }
  }
Esempio n. 6
0
 public static <R, I, C extends Collection<R>> C collect(
     Iterable<? extends I> source, C destination, Transformer<R, I> transformer) {
   for (I item : source) {
     destination.add(transformer.transform(item));
   }
   return destination;
 }
 @NotNull
 private static <T, C extends Collection<T>> C copy(
     @NotNull C collection, @NotNull Iterable<? extends T> elements) {
   for (T element : elements) {
     collection.add(element);
   }
   return collection;
 }
 public static <T, C extends Collection<T>> C filter(
     Iterable<? extends T> source, C destination, Spec<? super T> filter) {
   for (T item : source) {
     if (filter.isSatisfiedBy(item)) {
       destination.add(item);
     }
   }
   return destination;
 }
 @NotNull
 private ExternalProjectSettings getCurrentExternalProjectSettings() {
   ExternalProjectSettings result = myControl.getProjectSettings().clone();
   File externalProjectConfigFile =
       getExternalProjectConfigToUse(new File(result.getExternalProjectPath()));
   final String linkedProjectPath = FileUtil.toCanonicalPath(externalProjectConfigFile.getPath());
   assert linkedProjectPath != null;
   result.setExternalProjectPath(linkedProjectPath);
   return result;
 }
    /**
     * Checks if the cache has been cleaned recently. If not, starts with the oldest elements, and
     * checks which are to old. If one is found to be not to old, all the others are assumed to be
     * not to old, and the cleanup is over.
     */
    private void cleanup() {
      if (!isTooOld(lastClean, timeBetweenGC)) {
        return;
      }
      lastClean = System.currentTimeMillis();

      // With very low timeout this check could lead to infinite recursion
      /*            if (super.isEmpty()) {
                    return;
                }
      */

      Iterator<C> iterator = values().iterator();

      while (iterator.hasNext()) {
        C element = iterator.next();
        if (isTooOld(element.getCacheTime(), timeToLive)) {
          iterator.remove();
        } else {
          break;
        }
      }
    }
Esempio n. 11
0
  public void runAlgorithm() {
    //  traceHull = null;
    COper3.dbClear();

    traceHullPt = null;
    traceValley = null;
    simple = null;
    focusPt = null;
    possHull = null;
    valleyTri = null;
    PtEntry.resetIds();

    EdPolygon[] rgn = UHullMain.getPolygons();

    if (rgn.length < 2) return;

    if (C.vb(OLDALG)) {
      T.disable();
      simple = PossHullOper.buildPossibleHull(rgn);
      T.enable();
    }

    possHull = calcPHullRange(rgn, 0, rgn.length - 1);
  }
 @Override
 protected void syncVars(Sync sync) {
   preloadIn = (Graph) C.sync("preloadIn", preloadIn, sync);
 }
Esempio n. 13
0
  private static void insertValleys(
      PtEntry hullPt, Object aSrc, Object bSrc) { // pa, MyPolygon pb) {
    boolean db = C.vb(DB_INSERTVALLEY);
    PtEntry ent = hullPt;

    if (db && T.update()) T.msg("insertValleys");
    do {
      PtEntry next = ent.next(true);

      if (ent.source() == next.source()) {
        PtEntry orig = ent.orig();

        if (orig.next(true) != next.orig()) {

          PtEntry vPeak0 = ent;
          PtEntry vPeak1 = next;

          EdPolygon opp = (EdPolygon) (vPeak0.source() == aSrc ? bSrc : aSrc);

          FPoint2 kernelPt = opp.getPointMod(C.vi(KERNELVERT));

          // construct a chain from the vertices of the valley
          PtEntry handle = new PtEntry(vPeak0);
          PtEntry hNext = handle;
          PtEntry e = vPeak0.orig();
          while (e != vPeak1.orig()) {
            inf.update();
            e = e.next(true);
            hNext = hNext.insert(new PtEntry(e), true);
          }

          if (C.vb(SKIPCONTOUR)) {
            PtEntry h0 = handle.next(true);
            PtEntry h1 = hNext.prev(true);
            PtEntry.join(vPeak0, h0);
            PtEntry.join(h1, vPeak1);
            if (db && T.update())
              T.msg("inserted unmodified valley" + T.show(vPeak0) + T.show(vPeak1));

          } else {
            if (!C.vb(DB_CONTOUR)) T.disable();
            PtEntry hull = COper3.buildHullForChain(handle, kernelPt);
            if (!C.vb(DB_CONTOUR)) T.enable();
            // find entries corresponding to start, end of hull
            PtEntry peak0 = null, peak1 = null;
            {
              PtEntry hEnt = hull;
              while (peak0 == null || peak1 == null) {
                inf.update();
                if (hEnt.orig() == vPeak0.orig()) peak0 = hEnt;
                if (hEnt.orig() == vPeak1.orig()) peak1 = hEnt;
                hEnt = hEnt.next(true);
              }
            }
            PtEntry.join(vPeak0, peak0.next(true));
            PtEntry.join(peak1.prev(true), vPeak1);
            if (db && T.update())
              T.msg("inserted monotonic valley" + T.show(vPeak0) + T.show(vPeak1));
          }
        }
      }
      ent = next;
    } while (ent != hullPt);
  }
Esempio n. 14
0
  public void addControls() {
    C.sOpenTab("Valley");
    {
      C.sStaticText( //
          "Generate possible hull in O(n log k) time, using 'valley' algorithm");
      C.sCheckBox(
          DB_INITIALHULL,
          "db initial hull",
          "trace construction of initial convex hull of the two polygons",
          false);
      C.sCheckBox(DB_CONTOUR, "db pt/poly", "trace point / polygon hull construction", false);
      C.sCheckBox(
          DB_INSERTVALLEY, "db insert valley", "trace insertion of monotonic valley edges", false);
      C.sCheckBox(DB_HULLEXPAND, "db expand", "trace hull expansion procedure", false);
      C.sCheckBox(
          SKIPCONTOUR,
          "skip contour",
          "use original polygons and not their contours\n"
              + "(required to ensure monotonicity of tangent searches)",
          false);
      C.sCheckBox(OLDALG, "simple", "plot possible hull using old algorithm", false);
      C.sCheckBox(OLDMETHOD, "old", "use old code", false);
      C.sIntSpinner(
          KERNELVERT,
          "kernel vertex",
          "specifies which vertex of the other polygon to use as point in pt/poly step",
          0,
          50,
          0,
          1);
    }

    C.sCloseTab();
  }
Esempio n. 15
0
 public Tester(C container, List<Test<C>> tests) {
   this.container = container;
   this.tests = tests;
   if (container != null) headline = container.getClass().getSimpleName();
 }
Esempio n. 16
0
  /**
   * Apply hull expansion procedure
   *
   * @param convHullEntry an entry of the hull (should be on the convex hull, so it is not deleted
   *     or replaced and is still valid for subsequent calls)
   * @param aHull entry on convex hull of polygon A
   * @param bHull entry on convex hull of polygon B
   * @param ccw true to move in ccw direction, else cw
   */
  private static void expandHull(PtEntry convHullEntry, PtEntry aHull, PtEntry bHull, boolean ccw) {
    if (C.vb(OLDMETHOD)) {
      OLDexpandHull(convHullEntry, aHull, bHull, ccw);
      return;
    }
    boolean db = C.vb(DB_HULLEXPAND);

    if (db && T.update()) T.msg("expandHull" + T.show(convHullEntry) + " ccw=" + ccw);

    // tangent points for A, B
    PtEntry[] tangentPoints = new PtEntry[2];
    tangentPoints[0] = aHull;
    tangentPoints[1] = bHull;

    PtEntry hEnt = convHullEntry;
    do {
      inf.update();

      // calculate tangent ray R
      PtEntry tangentPt = null;
      while (true) {
        int tanIndex = (hEnt.source() == tangentPoints[0].source()) ? 1 : 0;
        tangentPt = tangentPoints[tanIndex];

        if (!COper3.right(hEnt, tangentPt, tangentPt.next(true), ccw)
            && !COper3.right(hEnt, tangentPt, tangentPt.prev(true), ccw)) break;

        tangentPt = tangentPt.next(ccw);

        if (db && T.update())
          T.msg(
              "expandHull, advance tangent line"
                  + T.show(tangentPt.toPolygon(), MyColor.cDARKGRAY, -1, MARK_DISC)
                  + T.show(hEnt)
                  + tl(hEnt, tangentPt));
        tangentPoints[tanIndex] = tangentPt;
      }

      if (COper3.left(hEnt, tangentPt, hEnt.next(ccw), ccw)) {
        DArray dispPts = new DArray();

        // delete points until cross tangent line
        PtEntry next = hEnt.next(ccw);
        while (true) {
          PtEntry prev = next;
          dispPts.add(prev);
          next = prev.delete(ccw);
          if (COper3.right(hEnt, tangentPt, next, ccw)) {
            FPoint2 cross = MyMath.linesIntersection(hEnt, tangentPt, prev, next, null);
            hEnt = hEnt.insert(new PtEntry(cross), ccw);
            if (db && T.update())
              T.msg(
                  "expandHull, clipped to shadow region"
                      + tl(hEnt, tangentPt)
                      + T.show(hEnt)
                      + T.show(dispPts));
            break;
          }
        }
      } else {
        if (db && T.update())
          T.msg(
              "expandHull, not dipping into shadow region"
                  + T.show(hEnt.next(ccw))
                  + tl(hEnt, tangentPt));
      }
      while (true) {
        hEnt = hEnt.next(ccw);
        if (COper3.left(hEnt.prev(ccw), hEnt, hEnt.next(ccw), ccw)) break;
        if (db && T.update()) T.msg("skipping reflex vertex" + T.show(hEnt));
      }
    } while (hEnt != convHullEntry);
  }
 @Nullable
 private File getProjectFile() {
   String path = myControl.getProjectSettings().getExternalProjectPath();
   return path == null ? null : new File(path);
 }
Esempio n. 18
0
  /**
   * Determine convex hull of two polygons, using rotating calipers method
   *
   * @param pa first polygon
   * @param pb second polygon
   * @return convex hull structure
   */
  private static PtEntry hullOfPolygons(PtEntry pa, PtEntry pb, PtEntry aHull, PtEntry bHull) {

    boolean db = C.vb(DB_INITIALHULL);

    if (db && T.update())
      T.msg(
          "construct convex hull of polygons"
              + T.show(pa, MyColor.cBLUE, STRK_THICK, -1)
              + T.show(pb, MyColor.cDARKGREEN, STRK_THICK, -1));

    PtEntry hullVertex = null;

    // A hull vertex and index
    PtEntry av = rightMostVertex(aHull);

    // B hull vertex and index
    PtEntry bv = rightMostVertex(bHull);

    double theta = Math.PI / 2;

    LineEqn aLine = new LineEqn(av, theta);

    int bSide = aLine.sideOfLine(bv);
    boolean bActive = (bSide == 0) ? (bv.y > av.y) : bSide < 0;

    if (db && T.update()) T.msg("rightmost vertices" + T.show(av) + T.show(bv));

    // construct initial vertex of hull
    hullVertex = new PtEntry(!bActive ? av : bv);

    //    if (db && T.update())
    //      T.msg("constructed initial hull vertex: " + hullVertex);

    PtEntry.join(hullVertex, hullVertex);
    PtEntry firstEnt = hullVertex;

    while (true) {
      Inf.update(inf);

      PtEntry av2 = av.next(true);
      PtEntry bv2 = bv.next(true);

      // next vertex is either A advance, B advance, or bridge
      double anga = MyMath.polarAngle(av, av2);
      double angb = MyMath.polarAngle(bv, bv2);

      double angBridge = bActive ? MyMath.polarAngle(bv, av) : MyMath.polarAngle(av, bv);

      double ta = MyMath.normalizeAnglePositive(anga - theta);
      double tb = MyMath.normalizeAnglePositive(angb - theta);
      double tc = MyMath.normalizeAnglePositive(angBridge - theta);

      // precision problem: if A and B tangent lines are parallel, both can
      // reach near zero simultaneously

      final double MAX = Math.PI * 2 - 1e-3;
      if (ta >= MAX) ta = 0;
      if (tb >= MAX) tb = 0;
      if (tc >= MAX) tc = 0;

      theta += Math.min(ta, Math.min(tb, tc));

      if (db && T.update())
        T.msg("caliper" + T.show(hullVertex) + tr(hullVertex, theta) + tp(av) + tp(bv));

      PtEntry newPoint = null;

      if (ta <= tb && ta <= tc) {
        if (db && T.update()) T.msg("A vertex is nearest" + tl(av, av2));
        // ai++;
        av = av2;
        if (!bActive) newPoint = av;
      } else if (tb <= ta && tb <= tc) {
        if (db && T.update()) T.msg("B vertex is nearest" + tl(bv, bv2));
        // bi++;
        bv = bv2;
        if (bActive) newPoint = bv;
      } else {
        if (db && T.update())
          T.msg("Bridge vertex is nearest" + tl(bActive ? bv : av, bActive ? av : bv));
        bActive ^= true;
        newPoint = bActive ? bv : av;
      }

      if (newPoint != null) {
        if (PtEntry.samePoint(newPoint, firstEnt)) {
          break;
        }

        // construct new vertex for hull of the two;
        // remember, use original vertex, not the convex hull
        hullVertex = hullVertex.insert(new PtEntry(newPoint), true);
        if (db && T.update()) T.msg("adding new caliper vertex " + T.show(hullVertex));
      }
    }
    return hullVertex;
  }
 @Override
 protected void syncVars(Sync sync) {
   filter = (Boolean) C.sync("filter", filter, sync);
   continuation = (Finder) C.sync("continuation", continuation, sync);
   pattern = (TriplePattern) C.sync("pattern", pattern, sync);
 }
 public void prepare(@NotNull WizardContext context) {
   myControl.reset();
   String pathToUse = context.getProjectFileDirectory();
   myControl.setLinkedProjectPath(pathToUse);
   doPrepare(context);
 }
 @Override
 protected void syncVars(Sync sync) {
   t = (Triple) C.sync("t", t, sync);
 }
Esempio n. 22
0
  private static void OLDexpandHull(
      PtEntry convHullEntry, PtEntry aHull, PtEntry bHull, boolean ccw) {
    boolean db__OLD = C.vb(DB_HULLEXPAND);
    if (db__OLD && T.update()) T.msg("expandHull" + T.show(convHullEntry) + " ccw=" + ccw);

    PtEntry[] opp = new PtEntry[2];
    opp[0] = aHull;
    opp[1] = bHull;

    PtEntry old____hEnt = convHullEntry;
    boolean advanced = false;
    do {
      if (old____hEnt != convHullEntry) advanced = true;
      inf.update();
      if (old____hEnt.source() == null) {
        if (db__OLD && T.update())
          T.msg("expandHull, source unknown, guaranteed not convex" + T.show(old____hEnt));
        old____hEnt = old____hEnt.next(ccw);
        continue;
      }

      int w = (old____hEnt.source() == opp[0].source()) ? 1 : 0;
      PtEntry oppEnt = opp[w];

      boolean isTangent =
          !COper3.right(old____hEnt, oppEnt, oppEnt.next(true), ccw)
              && !COper3.right(old____hEnt, oppEnt, oppEnt.prev(true), ccw);

      if (!isTangent) {
        if (db__OLD && T.update())
          T.msg(
              "expandHull, advance tangent line"
                  + T.show(oppEnt.toPolygon(), MyColor.cDARKGRAY, -1, MARK_X)
                  + T.show(old____hEnt)
                  + tl(old____hEnt, oppEnt));
        opp[w] = oppEnt.next(ccw);
        continue;
      }

      if (COper3.left(old____hEnt, oppEnt, old____hEnt.next(ccw), ccw)
          && COper3.left(old____hEnt, oppEnt, old____hEnt.prev(ccw), ccw)) {
        DArray dispPts = new DArray();

        // delete points until cross tangent line
        PtEntry next = old____hEnt.next(ccw);
        while (true) {
          PtEntry prev = next;
          dispPts.add(prev);
          next = prev.delete(ccw);

          inf.update();
          if (COper3.right(old____hEnt, oppEnt, next, ccw)) {
            FPoint2 cross = MyMath.linesIntersection(old____hEnt, oppEnt, prev, next, null);
            old____hEnt = old____hEnt.insert(new PtEntry(cross), ccw);
            if (db__OLD && T.update())
              T.msg(
                  "expandHull, clipped to shadow region"
                      + tl(old____hEnt, oppEnt)
                      + T.show(old____hEnt)
                      + T.show(dispPts));
            break;
          }
        }
      } else {
        if (db__OLD && T.update())
          T.msg(
              "expandHull, not dipping into shadow region"
                  + T.show(old____hEnt.next(ccw))
                  + tl(old____hEnt, oppEnt));
      }
      old____hEnt = old____hEnt.next(ccw);
    } while (!advanced || old____hEnt != convHullEntry);
  }
Esempio n. 23
0
File: C.java Progetto: jmankhan/ACM
 public static void main(String[] args) throws Exception {
   C solver = new C();
   solver.solve();
   solver.end();
 }
 @NotNull
 public C getControl(@Nullable Project currentProject) {
   myControl.setCurrentProject(currentProject);
   return myControl;
 }