/** @see DATAREST-221 */ @Test public void returnsObjectAsIfNoProjectionTypeFound() { Projector projector = new PersistentEntityProjector(configuration, factory, "sample"); Object object = new Object(); assertThat(projector.project(object), is(object)); }
public void watchMovie(String movie) { System.out.println("Get ready to watch a movie..."); projector.on(); projector.wideScreenMode(); amp.on(); amp.setDvd(dvd); amp.setVolume(5); dvd.on(); dvd.play(movie); }
@Override public Projector getProjector() { if (projector == null) { projector = new Projector(); projector.setDistance(70); projector.set2DScaling(15); projector.setRotationAngle(125); projector.setElevationAngle(10); } return projector; }
private float x2(int x, int y) { Transcaler ts = _tile.getTranscaler(); PointsView.Orientation pvo = _points.getOrientation(); if (pvo == PointsView.Orientation.X1RIGHT_X2UP) { Projector p = _tile.getHorizontalProjector(); return (float) p.v(ts.y(y)); } else { Projector p = _tile.getVerticalProjector(); return (float) p.v(ts.x(x)); } }
private int y(float x1, float x2) { Transcaler ts = _tile.getTranscaler(); PointsView.Orientation pvo = _points.getOrientation(); if (pvo == PointsView.Orientation.X1RIGHT_X2UP) { Projector p = _tile.getHorizontalProjector(); return ts.y(p.u(x2)); } else { Projector p = _tile.getVerticalProjector(); return ts.y(p.u(x1)); } }
/** @see DATAREST-221 */ @Test public void invokesProjectionFactoryIfProjectionFound() { configuration.addProjection(Sample.class, Object.class); Projector projector = new PersistentEntityProjector(configuration, factory, "sample"); Object source = new Object(); projector.project(source); verify(factory, times(1)).createProjection(source, Sample.class); }
public void endMovie() { System.out.println("Shutting movie theater down..."); projector.off(); amp.off(); dvd.stop(); dvd.eject(); dvd.off(); }
@Override public void upstreamFinished() { if (remainingUpstreams.decrementAndGet() > 0) { return; } for (int i = 0; i < aggregationCollectors.length; i++) { row[i] = aggregationCollectors[i].finishCollect(); } if (downstream != null) { downstream.setNextRow(row); Throwable throwable = upstreamFailure.get(); if (throwable != null) { downstream.upstreamFailed(throwable); } else { downstream.upstreamFinished(); } } }
EllipseCartesianMatchEngine.Ellipse project(Projector projector) { double[] center = projector.project(alpha_, delta_); double x = center[0]; double y = center[1]; double a = 0; double b = 0; double theta = 0; return new EllipseCartesianMatchEngine.Ellipse(x, y, a, b, theta); }
@Override public void upstreamFailed(Throwable throwable) { upstreamFailure.set(throwable); if (remainingUpstreams.decrementAndGet() > 0) { return; } if (downstream != null) { downstream.upstreamFailed(throwable); } }
@Override EllipseCartesianMatchEngine.Ellipse project(Projector projector) { double[] center = projector.project(alpha_, delta_); double x = center[0]; double y = center[1]; double a = mu_; double b = nu_; double theta = 0.5 * Math.PI + zeta_; return new EllipseCartesianMatchEngine.Ellipse(x, y, a, b, theta); }
@Override public void downstream(Projector downstream) { this.downstream = downstream; downstream.registerUpstream(this); }
public void map(Object in, AvroCollector<Pair<Object, Object>> collector, Reporter reporter) throws IOException { Object key = projector.project(in); pair.set(key, in); collector.collect(pair); }
/** * Determines whether there is a match between two given ellipses, and returns an object * characterising it if there is. * * @param se1 ellipse 1 * @param se2 ellipse 2 * @param needPoints true if the caller wants the coordinate information filled in in the returned * Match object; this may be expensive to generate, so if it's not required, false can be * given * @return description of match, or null if no overlap */ static Match getMatch(SkyEllipse se1, SkyEllipse se2, boolean needPoints) { double alpha1 = se1.alpha_; double delta1 = se1.delta_; double alpha2 = se2.alpha_; double delta2 = se2.delta_; /* If the centres are more distant than the sum of the major radii, * there is no match. */ double maxSep = se1.getMaxRadius() + se2.getMaxRadius(); if (Math.abs(delta2 - delta1) > maxSep || calculateSeparation(alpha1, delta1, alpha2, delta2) > maxSep) { return null; } /* If they are both points, then it's a match (a perfect one) only * if both centres are identical. */ boolean isPoint1 = se1.isPoint(); boolean isPoint2 = se2.isPoint(); if (isPoint1 && isPoint2) { return (normalizeAlpha(alpha1) == normalizeAlpha(alpha2) && normalizeDelta(delta1) == normalizeDelta(delta2)) ? new Match(0, NaN, NaN, NaN, NaN) : null; } /* If just one is a point, then it's a match only if it falls * inside the other. */ else if (isPoint1) { double s = se2.getScaledDistance(alpha1, delta1); return s <= 1 ? new Match(s, NaN, NaN, alpha1, delta1) : null; } else if (isPoint2) { double s = se1.getScaledDistance(alpha2, delta2); return s <= 1 ? new Match(s, alpha2, delta2, NaN, NaN) : null; } /* If the centre of one of the ellipses is inside the other one, * use the scaled distance. */ double sc1 = se1.getScaledDistance(alpha2, delta2); double sc2 = se2.getScaledDistance(alpha1, delta1); boolean isCenterInside1 = sc1 <= 1.0; boolean isCenterInside2 = sc2 <= 1.0; if (isCenterInside1 && isCenterInside2) { return sc1 < sc2 ? new Match(sc1, alpha2, delta2, NaN, NaN) : new Match(sc2, NaN, NaN, alpha1, delta1); } else if (isCenterInside1) { return new Match(sc1, alpha2, delta2, NaN, NaN); } else if (isCenterInside2) { return new Match(sc2, NaN, NaN, alpha2, delta2); } /* Otherwise, it's complicated. I haven't managed to make much of * the spherical trigonometry required to do this properly, so * perform an approximate projection of both ellipses onto a plane * and treat them in Cartesian coordinates. * The projection is onto a plane tangent to the midpoint between * the two centres. This is somewhat arbitrary, but it is at least * symmetric between the two input ellipses. */ if (se1.isCircle() && se2.isCircle() && !needPoints) { double mu1 = se1.getMaxRadius(); double mu2 = se2.getMaxRadius(); double s = calculateSeparation(alpha1, delta1, alpha2, delta2); double score = 1 + 0.5 * ((s - mu2) / mu1 + (s - mu1) / mu2); return new Match(score, NaN, NaN, NaN, NaN); } else { double[] pt = bisect(alpha1, delta1, alpha2, delta2); Projector projector = new Projector(pt[0], pt[1]); EllipseCartesianMatchEngine.Match cmatch = EllipseCartesianMatchEngine.getMatch( se1.project(projector), se2.project(projector), false); if (cmatch == null) { return null; } else { double score = cmatch.score_; if (needPoints) { double[] ad1 = projector.unproject(cmatch.x1_, cmatch.y1_); double[] ad2 = projector.unproject(cmatch.x2_, cmatch.y2_); return new Match(score, ad1[0], ad1[1], ad2[0], ad2[1]); } else { return new Match(score, NaN, NaN, NaN, NaN); } } } }